Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: raise
SyntaxError
for unparenthesized assert and assign (#13099)
* fix: raise `SyntaxError` for unparenthesized assert and assign * chore
- Loading branch information
Showing
9 changed files
with
254 additions
and
17 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-parser/test/fixtures/typescript/cast/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 |
---|---|---|
@@ -1 +1,2 @@ | ||
(a as number) = 42; | ||
(a as number) = 42; | ||
({ a: (b as any) = 2000 } = x); |
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: 2 additions & 0 deletions
2
...ges/babel-parser/test/fixtures/typescript/cast/unparenthesized-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,2 @@ | ||
foo as any = 10; | ||
({ a: b as any = 2000 } = x); |
110 changes: 110 additions & 0 deletions
110
.../babel-parser/test/fixtures/typescript/cast/unparenthesized-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,110 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":29}}, | ||
"errors": [ | ||
"SyntaxError: Invalid left-hand side in assignment expression (1:0)", | ||
"SyntaxError: Invalid left-hand side in assignment expression (2:6)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":29}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "TSAsExpression", | ||
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}} | ||
} | ||
}, | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":13,"end":15,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":15}}, | ||
"extra": { | ||
"rawValue": 10, | ||
"raw": "10" | ||
}, | ||
"value": 10 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":17,"end":46,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":29}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":18,"end":44,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":27}}, | ||
"extra": { | ||
"parenthesized": true, | ||
"parenStart": 17 | ||
}, | ||
"operator": "=", | ||
"left": { | ||
"type": "ObjectPattern", | ||
"start":18,"end":40,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":23}}, | ||
"properties": [ | ||
{ | ||
"type": "ObjectProperty", | ||
"start":20,"end":38,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":21}}, | ||
"method": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":20,"end":21,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":4},"identifierName":"a"}, | ||
"name": "a" | ||
}, | ||
"computed": false, | ||
"shorthand": false, | ||
"value": { | ||
"type": "AssignmentPattern", | ||
"start":23,"end":38,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":21}}, | ||
"left": { | ||
"type": "TSAsExpression", | ||
"start":23,"end":31,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":14}}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":23,"end":24,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":7},"identifierName":"b"}, | ||
"name": "b" | ||
}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":28,"end":31,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14}} | ||
} | ||
}, | ||
"right": { | ||
"type": "NumericLiteral", | ||
"start":34,"end":38,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":21}}, | ||
"extra": { | ||
"rawValue": 2000, | ||
"raw": "2000" | ||
}, | ||
"value": 2000 | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"right": { | ||
"type": "Identifier", | ||
"start":43,"end":44,"loc":{"start":{"line":2,"column":26},"end":{"line":2,"column":27},"identifierName":"x"}, | ||
"name": "x" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...l-parser/test/fixtures/typescript/cast/unparenthesized-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 @@ | ||
<string>foo = '100'; |
47 changes: 47 additions & 0 deletions
47
...arser/test/fixtures/typescript/cast/unparenthesized-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,47 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"errors": [ | ||
"SyntaxError: Invalid left-hand side in assignment expression (1:0)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ExpressionStatement", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"expression": { | ||
"type": "AssignmentExpression", | ||
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}}, | ||
"operator": "=", | ||
"left": { | ||
"type": "TSTypeAssertion", | ||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start":1,"end":7,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":7}} | ||
}, | ||
"expression": { | ||
"type": "Identifier", | ||
"start":8,"end":11,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":11},"identifierName":"foo"}, | ||
"name": "foo" | ||
} | ||
}, | ||
"right": { | ||
"type": "StringLiteral", | ||
"start":14,"end":19,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":19}}, | ||
"extra": { | ||
"rawValue": "100", | ||
"raw": "'100'" | ||
}, | ||
"value": "100" | ||
} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |