src: wrap source before doing syntax check
authorEvan Lucas <evanlucas@me.com>
Thu, 29 Oct 2015 16:22:00 +0000 (11:22 -0500)
committerJames M Snell <jasnell@gmail.com>
Thu, 29 Oct 2015 19:40:23 +0000 (12:40 -0700)
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 <info@bnoordhuis.nl>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
src/node.js
test/fixtures/syntax/illegal_if_not_wrapped.js [new file with mode: 0644]
test/parallel/test-cli-syntax.js

index 7cfd2c0..1aa489b 100644 (file)
           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 (file)
index 0000000..d76a836
--- /dev/null
@@ -0,0 +1,3 @@
+if (true) {
+  return;
+}
index 20fdfdc..1118a63 100644 (file)
@@ -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);