-
Notifications
You must be signed in to change notification settings - Fork 45
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
ChainExpression #98
Comments
Cc @3cp |
The same problem with a?.[x]. Here you create an ExpressionStatement with a MemberExpression in expression and a ChainExpression in property. It should be the other way around. ExpressionStatement with a ChainExpression in expression and the MemberExpression in expression. Another thing. Since this is official in the AST specification, I guess chain expression should be enabled by default without the Next option or what? |
Sounds reasonable. As said before some students of mine did this code, and I personally avoid ESTree. @aladdin-add Ideas? |
I want it like this, which is the way Acorn generates it and seems to comply with the specification:
|
and for (a?.import("string")?.import.meta??(a)) is should look like this:
|
I did the migration from old estree spec to the new spec ChainExpression. |
The bug is from I used a global flag here. Line 3964 in d3de211
This is to record whether an expression contains optional chain, so that later we can wrap the whole expression in ChainExpression node according to the spec. But the usage of global flag is wrong, in @KFlash any suggestion on how to parse it correctly? Some flag to be saved with the expression itself, rather than globally? |
Maybe try to look at the Escaya source. |
The escaya is using old syntax OptionalExpression which doesn't require wrapping, just like the old meriyah implementation I think. |
Escaya are just following the ECMA specs. I updated the chaining code in escaya now to follow the specs 100%. It seems like ESTree tries to do the same, but more complex. Where is the wrapping? |
Lines 3990 to 3999 in d3de211
|
It looks like it is still needed to enable the next option for optional chaining. I think this should not be needed, since it is in the official specification now. -Thomas |
There are still some issues with this. Try a?.b[3].c?.(x).d, then Acorn outputs this tree:
Meriyah has problems with the [3] and (x) part. Also the ({})?.a["b"] parses wrong. It should look like this:
-Thomas |
|
This is fixed in latest commit in #112. |
Hi,
For the expression (a?.import("string")?.import.meta??(a)), the argument "string" is stored as a ChainExpression node with a Literal in expression property. The ChainExpression should be skipped and the Literal should be stored directly in arguments instead. According to the AST specifications, it is not allowed to have a Literal in expression property in a ChainExpression node:
https://github.com/estree/estree/blob/master/es2020.md#chainexpression
-Thomas
The text was updated successfully, but these errors were encountered: