Skip to content

Commit 65cd03c

Browse files
evanlucasrvagg
authored andcommitted
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: #3587 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 1e98d90 commit 65cd03c

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/node.js

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
var source = fs.readFileSync(filename, 'utf-8');
107107
// remove shebang and BOM
108108
source = internalModule.stripBOM(source.replace(/^\#\!.*/, ''));
109+
// wrap it
110+
source = Module.wrap(source);
109111
// compile the script, this will throw if it fails
110112
new vm.Script(source, {filename: filename, displayErrors: true});
111113
process.exit(0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (true) {
2+
return;
3+
}

test/parallel/test-cli-syntax.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var syntaxArgs = [
2020
'syntax/good_syntax',
2121
'syntax/good_syntax_shebang.js',
2222
'syntax/good_syntax_shebang',
23+
'syntax/illegal_if_not_wrapped.js'
2324
].forEach(function(file) {
2425
file = path.join(common.fixturesDir, file);
2526

0 commit comments

Comments
 (0)