-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Division with comment containing '/' - SyntaxError #9300
Comments
Interesting... I'm able to reproduce only in the REPL and only when the line |
Yes, that's what I found out too. It also does not fail if you use more than one slash. However, it fails even if the comment is not in the same line. |
It works for me with node v6.9.1, even with strict mode. It looks like this is indeed REPL-specific. /cc @princejwesley ? |
It's a Update: With our ad-hoc parser, first |
Without proper state machine, Its not easy to deduce whether '/' is a division operator or start of regex literal. @dlangerenken Worst case, type/paste in |
I'm investigating this issue now. I think it should be possible to correctly distinguish between division and regex literals in almost all cases, with only a single lookbehind. A regex literal is almost always1 preceded by 1 An exception is code like this: function foo() {
return
/regex/ // not preceded by ;
} 2 An exception is code like this: ({ ok: true } / 3) Both of these exceptional cases are sort of obselete (they either require dead code, or dividing an object literal by something), so I think using a single-character lookbehind would be an improvement over the current behavior. |
This improves the heuristic used in multiline-prompt mode to determine whether a given slash character is at the beginning of a regular expression. PR-URL: nodejs#10103 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@keybase.io> Fixes: nodejs#9300
This improves the heuristic used in multiline-prompt mode to determine whether a given slash character is at the beginning of a regular expression. PR-URL: nodejs#10103 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: James M Snell <jasnell@keybase.io> Fixes: nodejs#9300
Following function fails parsing:
SyntaxError: Unexpected end of input
tested with:
This code parses correctly in some node versions 5.X
The text was updated successfully, but these errors were encountered: