From e457ec05d69e53416abe856644c5840218a832c9 Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Mon, 20 Dec 2021 07:33:34 +0800 Subject: [PATCH] lib: fix checking syntax of esm module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Michaël Zasso Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- lib/internal/main/check_syntax.js | 2 +- test/fixtures/syntax/good_syntax.mjs | 3 +++ test/sequential/test-cli-syntax-good.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/syntax/good_syntax.mjs diff --git a/lib/internal/main/check_syntax.js b/lib/internal/main/check_syntax.js index a3b9bf2923769e..25ae6bdb47a2df 100644 --- a/lib/internal/main/check_syntax.js +++ b/lib/internal/main/check_syntax.js @@ -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) { diff --git a/test/fixtures/syntax/good_syntax.mjs b/test/fixtures/syntax/good_syntax.mjs new file mode 100644 index 00000000000000..b07312f4f6c1bd --- /dev/null +++ b/test/fixtures/syntax/good_syntax.mjs @@ -0,0 +1,3 @@ +export function testFunction(req, res) { + return 'PASS'; +} diff --git a/test/sequential/test-cli-syntax-good.js b/test/sequential/test-cli-syntax-good.js index 262c30ccad6bce..44051c7a4a3617 100644 --- a/test/sequential/test-cli-syntax-good.js +++ b/test/sequential/test-cli-syntax-good.js @@ -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',