From 08166cb99a880cdb6a61d3c1ff4765144cd81451 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Thu, 29 Oct 2015 11:22:00 -0500 Subject: [PATCH] src: wrap source before doing syntax check This is to ensure that it is evaluated the same way it would be if it were to be run by node or required. Before, the following would pass if run by node, but fail if run via the syntax check flag: if (true) { return; } Now, this will pass the syntax check PR-URL: https://github.com/nodejs/node/pull/3587 Reviewed-By: Ben Noordhuis Reviewed-By: Sakthipriyan Vairamani --- src/node.js | 2 ++ test/fixtures/syntax/illegal_if_not_wrapped.js | 3 +++ test/parallel/test-cli-syntax.js | 1 + 3 files changed, 6 insertions(+) create mode 100644 test/fixtures/syntax/illegal_if_not_wrapped.js diff --git a/src/node.js b/src/node.js index d47a129635..ed74480289 100644 --- a/src/node.js +++ b/src/node.js @@ -106,6 +106,8 @@ var source = fs.readFileSync(filename, 'utf-8'); // remove shebang and BOM source = internalModule.stripBOM(source.replace(/^\#\!.*/, '')); + // wrap it + source = Module.wrap(source); // compile the script, this will throw if it fails new vm.Script(source, {filename: filename, displayErrors: true}); process.exit(0); diff --git a/test/fixtures/syntax/illegal_if_not_wrapped.js b/test/fixtures/syntax/illegal_if_not_wrapped.js new file mode 100644 index 0000000000..d76a836c88 --- /dev/null +++ b/test/fixtures/syntax/illegal_if_not_wrapped.js @@ -0,0 +1,3 @@ +if (true) { + return; +} diff --git a/test/parallel/test-cli-syntax.js b/test/parallel/test-cli-syntax.js index 20fdfdc995..1118a63934 100644 --- a/test/parallel/test-cli-syntax.js +++ b/test/parallel/test-cli-syntax.js @@ -20,6 +20,7 @@ var syntaxArgs = [ 'syntax/good_syntax', 'syntax/good_syntax_shebang.js', 'syntax/good_syntax_shebang', + 'syntax/illegal_if_not_wrapped.js' ].forEach(function(file) { file = path.join(common.fixturesDir, file);