Skip to content
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

Fix parentheses removal in nullish-coalescing operation #11014

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/babel-generator/src/node/parentheses.js
Expand Up @@ -2,6 +2,7 @@ import * as t from "@babel/types";

const PRECEDENCE = {
"||": 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's unobservable now, ?? should actually be the lowest precedence of all tokens. Meaning we'll need to increase every other token's precedence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so I am assigning a precedence of 0 to ?? and will increment that of others by 1. BTW, I am still not clear as to how to get to know the precedence that we follow here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually, you're right. SortCircuitExpression is both CoalesceExpression and LogicalORExpression, so they have the same precedence. I was remember when we had the spec using grammar flags, and there it was CoalesceExpression -> LogicalORExpression.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I had already made the changes. 😅 Reverting them.

"??": 0,
"&&": 1,
"|": 2,
"^": 3,
Expand Down
@@ -0,0 +1,2 @@
const foo = 'test'
console.log((foo ?? '') == '')
@@ -0,0 +1,2 @@
const foo = 'test';
console.log((foo ?? '') == '');