Skip to content

Commit 0d7db35

Browse files
committed
esm: update containsModuleSyntax re removal of stripShebang
1 parent 3e7d55b commit 0d7db35

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,11 @@ Module.containsModuleSyntax = (source) => {
896896
// writing, Acorn doesn't support import() expressions as they are only Stage
897897
// 3; yet Node already supports them.
898898
const acorn = require('internal/deps/acorn/acorn/dist/acorn');
899-
source = stripShebang(source);
900899
source = stripBOM(source);
901900
try {
902901
let prevToken, prevPrevToken;
903-
for (const { type: token } of acorn.tokenizer(source)) {
902+
const acornOptions = { allowHashBang: true };
903+
for (const { type: token } of acorn.tokenizer(source, acornOptions)) {
904904
if (prevToken &&
905905
// By definition import or export must be followed by another token.
906906
(prevToken.keyword === 'import' || prevToken.keyword === 'export') &&

test/es-module/test-esm-contains-module-syntax.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ expect('esm-with-import-statement.js', 'module');
1010
expect('esm-with-export-statement.js', 'module');
1111
expect('esm-with-import-expression.js', 'module');
1212
expect('esm-with-indented-import-statement.js', 'module');
13+
expect('hashbang.js', 'module');
1314

1415
expect('cjs-with-require.js', 'commonjs');
1516
expect('cjs-with-import-expression.js', 'commonjs');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
import { version } from 'process';
3+
console.log(version);

0 commit comments

Comments
 (0)