Skip to content

Commit 08166cb

Browse files
committed
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 810cc05 commit 08166cb

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/node.js

Lines changed: 2 additions & 0 deletions
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);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (true) {
2+
return;
3+
}

test/parallel/test-cli-syntax.js

Lines changed: 1 addition & 0 deletions
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)