forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix printing edge cases in Nullish Coalescing and Optional Chaining
This is a mix of changes, most importantly: - Always print parens when mixing nullish coalescing and another logical - Fixes assignment in the callee of an optional chain, which now blocks babel#11248 Also, cleans up a bit of code, and removes an unnecessary parens around `class A extends new B {}`
- Loading branch information
1 parent
f9d4b79
commit 519cdff
Showing
9 changed files
with
73 additions
and
35 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
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: 3 additions & 0 deletions
3
packages/babel-generator/test/fixtures/parentheses/assignment-expression/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,3 +1,6 @@ | ||
1 + (a = 2); | ||
1 + (a += 2); | ||
a = a || (a = {}); | ||
|
||
(a = b)(); | ||
(a = b)?.(); |
4 changes: 3 additions & 1 deletion
4
packages/babel-generator/test/fixtures/parentheses/assignment-expression/output.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,3 +1,5 @@ | ||
1 + (a = 2); | ||
1 + (a += 2); | ||
a = a || (a = {}); | ||
a = a || (a = {}); | ||
(a = b)(); | ||
(a = b)?.(); |
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
17 changes: 16 additions & 1 deletion
17
packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/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,2 +1,17 @@ | ||
const foo = 'test' | ||
console.log((foo ?? '') == '') | ||
console.log((foo ?? '') == '') | ||
|
||
|
||
a ?? (b ?? c); | ||
(a ?? b) ?? c; | ||
|
||
a ?? (b || c); | ||
a || (b ?? c); | ||
(a ?? b) || c; | ||
(a || b) ?? c; | ||
|
||
a ?? (b && c); | ||
a && (b ?? c); | ||
(a ?? b) && c; | ||
(a && b) ?? c; | ||
|
12 changes: 11 additions & 1 deletion
12
packages/babel-generator/test/fixtures/parentheses/nullish-coalescing/output.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,2 +1,12 @@ | ||
const foo = 'test'; | ||
console.log((foo ?? '') == ''); | ||
console.log((foo ?? '') == ''); | ||
a ?? b ?? c; | ||
a ?? b ?? c; | ||
a ?? (b || c); | ||
a || (b ?? c); | ||
(a ?? b) || c; | ||
(a || b) ?? c; | ||
a ?? (b && c); | ||
a && (b ?? c); | ||
(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
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