Skip to content

Commit 5d1f1c5

Browse files
evanlucasjasnell
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 a2786dd commit 5d1f1c5

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
@@ -104,6 +104,8 @@
104104
var source = fs.readFileSync(filename, 'utf-8');
105105
// remove shebang and BOM
106106
source = internalModule.stripBOM(source.replace(/^\#\!.*/, ''));
107+
// wrap it
108+
source = Module.wrap(source);
107109
// compile the script, this will throw if it fails
108110
new vm.Script(source, {filename: filename, displayErrors: true});
109111
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)