-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ts): Allow parenthesized "assert and assign" (#12933)
Co-authored-by: Nicol貌 Ribaudo <7000710+nicolo-ribaudo@users.noreply.github.com>
- Loading branch information
1 parent
69e22c3
commit 4f72713
Showing
19 changed files
with
306 additions
and
0 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
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/typescript/assign/parenthesized-object-assign/input.ts
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 @@ | ||
({}) = x |
3 changes: 3 additions & 0 deletions
3
...ges/babel-parser/test/fixtures/typescript/assign/parenthesized-object-assign/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 @@ | ||
{ | ||
"createParenthesizedExpressions": true | ||
} |
39 changes: 39 additions & 0 deletions
39
...ages/babel-parser/test/fixtures/typescript/assign/parenthesized-object-assign/output.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,39 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, | ||
"errors": [ | ||
"SyntaxError: Invalid parenthesized assignment pattern (1:0)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ParenthesizedExpression", | ||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}}, | ||
"expression": { | ||
"type": "ObjectPattern", | ||
"start":1,"end":3,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":3}}, | ||
"properties": [] | ||
} | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...abel-parser/test/fixtures/typescript/cast/nested-parenthesized-assert-and-assign/input.ts
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 as any) as string) = null |
3 changes: 3 additions & 0 deletions
3
...-parser/test/fixtures/typescript/cast/nested-parenthesized-assert-and-assign/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 @@ | ||
{ | ||
"createParenthesizedExpressions": true | ||
} |
55 changes: 55 additions & 0 deletions
55
...l-parser/test/fixtures/typescript/cast/nested-parenthesized-assert-and-assign/output.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,55 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ParenthesizedExpression", | ||
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, | ||
"expression": { | ||
"type": "TSAsExpression", | ||
"start":1,"end":21,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":21}}, | ||
"expression": { | ||
"type": "ParenthesizedExpression", | ||
"start":1,"end":11,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":11}}, | ||
"expression": { | ||
"type": "TSAsExpression", | ||
"start":2,"end":10,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":10}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":2,"end":3,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}} | ||
} | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start":15,"end":21,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":21}} | ||
} | ||
} | ||
}, | ||
"right": { | ||
"type": "NullLiteral", | ||
"start":25,"end":29,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":29}} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/typescript/cast/parenthesized-as-and-assign/input.ts
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 as number) = 42; |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/typescript/cast/parenthesized-as-and-assign/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 @@ | ||
{ | ||
"createParenthesizedExpressions": true | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/babel-parser/test/fixtures/typescript/cast/parenthesized-as-and-assign/output.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,48 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ParenthesizedExpression", | ||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, | ||
"expression": { | ||
"type": "TSAsExpression", | ||
"start":1,"end":12,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":12}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSNumberKeyword", | ||
"start":6,"end":12,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":12}} | ||
} | ||
} | ||
}, | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":16,"end":18,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":18}}, | ||
"extra": { | ||
"rawValue": 42, | ||
"raw": "42" | ||
}, | ||
"value": 42 | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/typescript/cast/parenthesized-assert-and-assign/input.ts
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 as any) = null |
3 changes: 3 additions & 0 deletions
3
...s/babel-parser/test/fixtures/typescript/cast/parenthesized-assert-and-assign/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 @@ | ||
{ | ||
"createParenthesizedExpressions": true | ||
} |
43 changes: 43 additions & 0 deletions
43
...es/babel-parser/test/fixtures/typescript/cast/parenthesized-assert-and-assign/output.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,43 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ParenthesizedExpression", | ||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, | ||
"expression": { | ||
"type": "TSAsExpression", | ||
"start":1,"end":9,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":9}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}} | ||
} | ||
} | ||
}, | ||
"right": { | ||
"type": "NullLiteral", | ||
"start":13,"end":17,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":17}} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...bel-parser/test/fixtures/typescript/cast/parenthesized-null-assertion-and-assign/input.ts
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 @@ | ||
(x!) = null; |
3 changes: 3 additions & 0 deletions
3
...parser/test/fixtures/typescript/cast/parenthesized-null-assertion-and-assign/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 @@ | ||
{ | ||
"createParenthesizedExpressions": true | ||
} |
39 changes: 39 additions & 0 deletions
39
...-parser/test/fixtures/typescript/cast/parenthesized-null-assertion-and-assign/output.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,39 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ParenthesizedExpression", | ||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}}, | ||
"expression": { | ||
"type": "TSNonNullExpression", | ||
"start":1,"end":3,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":3}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":1,"end":2,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":2},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
} | ||
}, | ||
"right": { | ||
"type": "NullLiteral", | ||
"start":7,"end":11,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":11}} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...bel-parser/test/fixtures/typescript/cast/parenthesized-type-assertion-and-assign/input.ts
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 @@ | ||
(<number>x) = null |
3 changes: 3 additions & 0 deletions
3
...parser/test/fixtures/typescript/cast/parenthesized-type-assertion-and-assign/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 @@ | ||
{ | ||
"createParenthesizedExpressions": true | ||
} |
43 changes: 43 additions & 0 deletions
43
...-parser/test/fixtures/typescript/cast/parenthesized-type-assertion-and-assign/output.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,43 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ParenthesizedExpression", | ||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"expression": { | ||
"type": "TSTypeAssertion", | ||
"start":1,"end":10,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":10}}, | ||
"typeAnnotation": { | ||
"type": "TSNumberKeyword", | ||
"start":2,"end":8,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":8}} | ||
}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
} | ||
}, | ||
"right": { | ||
"type": "NullLiteral", | ||
"start":14,"end":18,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":18}} | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |