lib: fix checking syntax of esm module

Fixes: https://github.com/nodejs/node/issues/41189

PR-URL: https://github.com/nodejs/node/pull/41198
Refs: https://github.com/nodejs/node/pull/37468
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
Qingyu Deng 2021-12-20 07:33:34 +08:00 committed by GitHub
parent 0fcae7ba16
commit 3f7dabdfdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 1 deletions

View File

@ -54,7 +54,7 @@ function checkSyntax(source, filename) {
const { defaultResolve } = require('internal/modules/esm/resolve');
const { defaultGetFormat } = require('internal/modules/esm/get_format');
const { url } = defaultResolve(pathToFileURL(filename).toString());
const { format } = defaultGetFormat(url);
const format = defaultGetFormat(url);
isModule = format === 'module';
}
if (isModule) {

3
test/fixtures/syntax/good_syntax.mjs vendored Normal file
View File

@ -0,0 +1,3 @@
export function testFunction(req, res) {
return 'PASS';
}

View File

@ -17,6 +17,7 @@ const syntaxArgs = [
[
'syntax/good_syntax.js',
'syntax/good_syntax',
'syntax/good_syntax.mjs',
'syntax/good_syntax_shebang.js',
'syntax/good_syntax_shebang',
'syntax/illegal_if_not_wrapped.js',