Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError showing token not in the input #6427

Closed
msridhar opened this issue Apr 27, 2016 · 7 comments
Closed

SyntaxError showing token not in the input #6427

msridhar opened this issue Apr 27, 2016 · 7 comments
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@msridhar
Copy link

  • Version: v6.0.0
  • Platform: Mac OS X 10.11.4

Givenfoo.js just containing the following:

++

When I run node foo.js, I get:

/private/tmp/foo.js:3
});
^
SyntaxError: Unexpected token }
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:511:25)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:159:18)
    at node.js:444:3

But the token } does not appear in foo.js. This could be related to #3411, not sure. When I run with just v8, I get an appropriate error:

/tmp/foo.js:1: SyntaxError: Unexpected end of input
++
^^
SyntaxError: Unexpected end of input
@cjihrig
Copy link
Contributor

cjihrig commented Apr 27, 2016

I think this is expected due to Node wrapping your code.

@mscdex
Copy link
Contributor

mscdex commented Apr 27, 2016

Yes, the reason it does not point to your ++ line is because the parser is expecting a variable afterwards somewhere (even on a following line). So it instead sees } from the node module wrapper function which is not a valid variable name token and exits. You can verify this is the case with:

var n = 0;
++

n

console.log(n) // Prints `1`

@msridhar
Copy link
Author

To be clear, this is not a serious bug for me; I just wanted to report it in case it was indicative of some more important problem. Is this whole "node module wrapper function" behavior documented somewhere? It seems unfortunate that it can lead to such a confusing SyntaxError. But, it might not be worth it to fix this one.

@cjihrig
Copy link
Contributor

cjihrig commented Apr 27, 2016

I'm not sure if it's actually documented. Interestingly enough, the docs do say:

Variables local to the module will be private, as though the module was wrapped in a function. In this example the variable PI is private to circle.js.

Where "as though" could be interpreted as "because" :-)

@mscdex mscdex added the v8 engine Issues and PRs related to the V8 dependency. label Apr 27, 2016
@mtharrison
Copy link
Contributor

Doesn't seem to be documented anywhere. Might be useful to include so I made a PR: #6433

@stevemao
Copy link
Contributor

I think this is expected due to Node wrapping your code.

I feel user shouldn't know about this. At least the error shouldn't point to the internally code });.

@cjihrig
Copy link
Contributor

cjihrig commented Jun 16, 2016

This was closed a while back in 7164003.

@cjihrig cjihrig closed this as completed Jun 16, 2016
cjihrig referenced this issue Jun 16, 2016
Included a block in the modules.md file to explain the existence and
purpose of the module wrapper.

PR-URL: #6433
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

No branches or pull requests

5 participants