Skip to content

Commit f39ff4d

Browse files
aduh95marco-ippolito
authored andcommitted
worker: handle --input-type more consistently
PR-URL: #54979 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Marco Ippolito <[email protected]>
1 parent ee5624b commit f39ff4d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/internal/main/worker_thread.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ let debug = require('internal/util/debuglog').debuglog('worker', (fn) => {
5353
});
5454

5555
const assert = require('internal/assert');
56+
const { getOptionValue } = require('internal/options');
5657
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
5758

5859
prepareWorkerThreadExecution();
@@ -153,7 +154,7 @@ port.on('message', (message) => {
153154
break;
154155
}
155156

156-
case 'classic': {
157+
case 'classic': if (getOptionValue('--input-type') !== 'module') {
157158
const { evalScript } = require('internal/process/execution');
158159
const name = '[worker eval]';
159160
// This is necessary for CJS module compilation.
@@ -169,6 +170,7 @@ port.on('message', (message) => {
169170
break;
170171
}
171172

173+
// eslint-disable-next-line no-fallthrough
172174
case 'module': {
173175
const { evalModuleEntryPoint } = require('internal/process/execution');
174176
PromisePrototypeThen(evalModuleEntryPoint(filename), undefined, (e) => {

test/parallel/test-worker-cli-options.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Flags: --expose-internals --expose-gc
22
'use strict';
3-
require('../common');
3+
const common = require('../common');
44
const { Worker } = require('worker_threads');
55
const assert = require('assert');
66

@@ -29,3 +29,11 @@ new Worker(CODE, { eval: true, env: process.env, execArgv: ['--expose-internals'
2929
assert.throws(() => {
3030
new Worker(CODE, { eval: true, execArgv: ['--expose-gc'] });
3131
}, /ERR_WORKER_INVALID_EXEC_ARGV/);
32+
33+
// Test ESM eval
34+
new Worker('export {}', { eval: true, execArgv: ['--input-type=module'] });
35+
new Worker('export {}', { eval: true, execArgv: ['--input-type=commonjs'] })
36+
.once('error', common.expectsError({ name: 'SyntaxError' }));
37+
new Worker('export {}', { eval: true, execArgv: ['--experimental-detect-module'] });
38+
new Worker('export {}', { eval: true, execArgv: ['--no-experimental-detect-module'] })
39+
.once('error', common.expectsError({ name: 'SyntaxError' }));

0 commit comments

Comments
 (0)