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
Should a || b || c
and a || (b || c)
be parsed to the same AST?
#246
Comments
I think this would be a significant breaking change to split up commutative operations vs non-commutative in separate nodes. It shouldn't be hard to rebalance tree afterwards if it's something you need though. What is your use-case? |
Could you give an example of differences? |
@bradzacher I mean the result of parsing these two expressions is different whereas e.g. for {
"type": "LogicalExpression",
"left": {
"type": "LogicalExpression",
"left": { "type": "Identifier", "name": "a" },
"right": { "type": "Identifier", "name": "b" }
},
"right": { "type": "Identifier", "name": "c" }
} vs {
"type": "LogicalExpression",
"left": { "type": "Identifier", "name": "a" },
"right": {
"type": "LogicalExpression",
"left": { "type": "Identifier", "name": "b" },
"right": { "type": "Identifier", "name": "c" }
}
} @RReverser What will break if parsers start ignoring these parentheses? I don't really have a use case (I'd be glad to remove the rebalancing from Prettier though). I just see a conceptual inconsistency here. |
If you parse a binary expression with parens in the same location as your logic expression example ( |
My understanding of this is that it's just easier for parsers to follow one set of logic. The logic of "parse in source order pairings, but group by parens first" is simpler to build, and easier to achieve consistency on rather than "parse in source order pairings, but group by parens first; unless the precedence of the operator is such that the parens are unnecessary" Also for most use cases I'd assume that they don't care about the commutativity of the expressions. |
This is not really about precedence or commutativity (associativity probably?). Rather about short-circuiting. Because it's short-circuiting that makes these two expressions equivalent. Note that |
How so? What operations are applied to additions that would change the outcome based on parentheses? |
|
This behaviour is also not JavaScript-specific. Standard IEEE 754 floating-point arithmetic is simply not associative due to rounding errors. I think this issue could therefore be closed because |
The issue is about short-circuit operators: |
Seems like this hasn't been discussed yet. Effectively, there is no difference between these two expressions, but currently JS parsers parse them differently, which doesn't serve any good purpose and conflicts with the general approach of ESTree that insignificant parentheses shouldn't be reflected in the AST. Can be something done about this? Or is it too late?
The text was updated successfully, but these errors were encountered: