-
Notifications
You must be signed in to change notification settings - Fork 889
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
Acorn loose output does not conforms to ECMA specs #975
Comments
There is no spec on loose parsing, so I'm not sure where you're getting all your "should"s. Are you clean on what the loose parser does? It parses everything, never raising an error, and emitting a syntax tree for as much of the syntax as it could recognize (including incomplete constructs). |
My "should"s come from the ECMAScript® 2021 Language Specification. I agree there is no specs about it, but I thought a JS parser should follow the ECMA specs, that why the title on this issue. Example punctuators are never valid start of an expression except for a few, but still - as I mentioned - got an AssignmentExpression while parsing And it doesn't conform to the specs while parsing out an That was the things I found weird. I also noticed that it doesn't throw any errors, and you did a great job there :) |
It parses valid JS code. It does its own thing, creating a tree as close to the presented code as possible, for invalid code. |
I agree it almost passes valid JS code even thought some weird output etc. But I respect that you want fix it. |
Hi. I was playing around with Acorn loose, and got confused
= a
and also=
are parsed as anAssignmentExpression
.=
is not an start of an statement or expression and should be consumed.if
was parsed as an emptyIfStatement
with anEmptyStatement
as part of theConsequent
. Where did this semicolon come from? Or why is there anEmptyStatement
when the block body should not be parsed?It would make sense if there actually was an
;
because it's an valid start of an statement.try
parsed as anBlockStatement
. Where is theTryStatement
? Becauseswitch
parses out an emptySwitchStatement
so that is correct, so same rule should apply fortry
.catch
parsed as anEmptyStatement
. It's not an valid start of an statement, so should only be consumed.This case -
switch try
- is also weird. Try statement is missing and instead aBlockStatement
become part part of theSwitchCase
.For correct error recovery the
SwitchCase
should not be parsed out. A Try statement should be parsed outinstead because ``Try` is an valid statement start and should result in an empty Try statement.
You can see it here in my REPL how it should have been parsed.
+++
. Here the parser consumes the last+
. In fact it should be parsed as anUpdateExpression
andUnaryExpression
.I mention it because
++!
are parsed correct, so I'm not sure why+++
isn't parsed in the same way. Both+
and!
arepart of the
UnaryExpression
productionThis is only a few weird cases I found, but there are tons of them.
The text was updated successfully, but these errors were encountered: