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
Update coalesce precedence #11017
Merged
nicolo-ribaudo
merged 3 commits into
babel:master
from
JLHwung:update-coalesce-precedence
Jan 17, 2020
Merged
Update coalesce precedence #11017
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...parser/test/fixtures/es2020/nullish-coalescing-operator/no-paren-and-nullish/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"plugins": ["estree"], | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:0)" | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:7)" | ||
} |
2 changes: 1 addition & 1 deletion
2
...parser/test/fixtures/es2020/nullish-coalescing-operator/no-paren-nullish-and/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:5)" | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:7)" | ||
} |
2 changes: 1 addition & 1 deletion
2
...-parser/test/fixtures/es2020/nullish-coalescing-operator/no-paren-nullish-or/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:10)" | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:12)" | ||
} |
2 changes: 1 addition & 1 deletion
2
...-parser/test/fixtures/es2020/nullish-coalescing-operator/no-paren-or-nullish/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"plugins": ["estree"], | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:0)" | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:7)" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JLHwung If you follow the specs the precedence values is wrong :) The '??' should have lowest value.
There are a lot of docs and issue tickets about this, but here you can see it clearly
https://github.com/tc39/proposal-nullish-coalescing/blob/80a589d657c322fd2e152c1936bd9704904b2068/spec.html#L14-L17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That precedence statement does not follow from the grammar notation in the spec
That statement was updated in tc39/proposal-nullish-coalescing@99ff664 where a NullishExpression was introduced
apparently here
??
is lower than||
in this notation. But later it was changed toShortCircuitExpression
, whereCoalesceExpression
is eitherCoalesceExpression
orBitwiseORExpression
.LogicalORExpression
does not containCoalesceExpression
So the grammar itself does not conclude that the precedence of
coalesce
is higher or lower than thelogical_or
. The only thing we know is thatboth
coalesce
andlogical_or
are lower thanbit_or
. (f.1)logical_or
is lower thanlogical_and
. (f.2)Since the precedence of
coalesce
andlogical_or
is meant to solve the error of mixing coalesce and logical operators and now we throw when they are mixed, I don't think the exact precedence ofcoalesce
andlogical_or
will have any impact as long as the precedence specification satisfies (f.1) and (f.2).I can think of one advantage if you specify the precedence as
coalesce: 1, or: 2, and: 3
: you can now check iflogical
is mixed withcoalesce
byThis is similar to what is done in seafox but I think here code readability weighs more than performance, unless we do identify that parsing coalesce is the bottleneck.