Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parenthesis for nullish coalescing (#10269)
* 鈾伙笍 added condition to check for left and right of nullish coalescing operator and if any is a logical expression without a paren then throw an error * 馃悰 bugs fixed and test cases updated for babel parser * 鈾伙笍 code comments added * 馃悰 spell error rectified * 鈾伙笍 failing test updated * 馃悰 push tests after make build * Skip nullish-coalescing flow precedence tests They're now incorrect * 鈾伙笍 error message updated, binop priority of other logical operators +1 from ?? and * 鈾伙笍 increaed the binOp for in and instanceOf, added logic to print the brackets in an ?? && || expression, test cases added * 馃悰 failing test fixed and comments updated * 鈾伙笍 new lines added between tests * 鈾伙笍 basic tests for checking the binOp of instanceOf, in and relational operators to be equal added * 鈾伙笍 new lines added in between tests
- Loading branch information
1 parent
3e8a5c5
commit b02e35c
Showing
26 changed files
with
271 additions
and
131 deletions.
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
3 changes: 2 additions & 1 deletion
3
packages/babel-generator/test/fixtures/types/LogicalExpression/input.js
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,5 @@ | ||
foo ||bar; | ||
(x => x)|| bar; | ||
(function a(x){return x;})|| 2; | ||
0||(function(){return alpha;}); | ||
0||(function(){return alpha;}); | ||
a ?? (b || c); |
3 changes: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/types/LogicalExpression/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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["nullishCoalescingOperator"] | ||
} |
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 |
---|---|---|
|
@@ -7,4 +7,6 @@ foo || bar; | |
|
||
0 || function () { | ||
return alpha; | ||
}; | ||
}; | ||
|
||
a ?? (b || c); |
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
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
.../babel-parser/test/fixtures/experimental/nullish-coalescing-operator/and-nullish/input.js
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 +1 @@ | ||
a && b ?? c; | ||
(a && b) ?? c; |
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
1 change: 1 addition & 0 deletions
1
...rser/test/fixtures/experimental/nullish-coalescing-operator/no-paren-and-nullish/input.js
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
c && d ?? e; |
7 changes: 7 additions & 0 deletions
7
.../test/fixtures/experimental/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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": [ | ||
"nullishCoalescingOperator", | ||
"estree" | ||
], | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:0)" | ||
} |
1 change: 1 addition & 0 deletions
1
...rser/test/fixtures/experimental/nullish-coalescing-operator/no-paren-nullish-and/input.js
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
a ?? b && c; |
6 changes: 6 additions & 0 deletions
6
.../test/fixtures/experimental/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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"nullishCoalescingOperator" | ||
], | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:5)" | ||
} |
1 change: 1 addition & 0 deletions
1
...arser/test/fixtures/experimental/nullish-coalescing-operator/no-paren-nullish-or/input.js
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
e ?? f ?? g || h; |
6 changes: 6 additions & 0 deletions
6
...r/test/fixtures/experimental/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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"nullishCoalescingOperator" | ||
], | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:10)" | ||
} |
1 change: 1 addition & 0 deletions
1
...arser/test/fixtures/experimental/nullish-coalescing-operator/no-paren-or-nullish/input.js
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
h || i ?? j; |
7 changes: 7 additions & 0 deletions
7
...r/test/fixtures/experimental/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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": [ | ||
"nullishCoalescingOperator", | ||
"estree" | ||
], | ||
"throws": "Nullish coalescing operator(??) requires parens when mixing with logical operators (1:0)" | ||
} |
2 changes: 1 addition & 1 deletion
2
.../babel-parser/test/fixtures/experimental/nullish-coalescing-operator/nullish-and/input.js
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 +1 @@ | ||
a ?? b && c; | ||
a ?? (b && c); |
Oops, something went wrong.