Skip to content

Commit

Permalink
fix: parse a satisfies b as left value (#15096)
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
liuxingbaoyu committed Oct 31, 2022
1 parent df147ad commit 292e5d6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -3540,6 +3540,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
this.toAssignableParenthesizedExpression(node, isLHS);
break;
case "TSAsExpression":
case "TSSatisfiesExpression":
case "TSNonNullExpression":
case "TSTypeAssertion":
if (isLHS) {
Expand All @@ -3565,6 +3566,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
toAssignableParenthesizedExpression(node: N.Node, isLHS: boolean): void {
switch (node.expression.type) {
case "TSAsExpression":
case "TSSatisfiesExpression":
case "TSNonNullExpression":
case "TSTypeAssertion":
case "ParenthesizedExpression":
Expand All @@ -3578,6 +3580,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
checkToRestConversion(node: N.Node, allowPattern: boolean): void {
switch (node.type) {
case "TSAsExpression":
case "TSSatisfiesExpression":
case "TSTypeAssertion":
case "TSNonNullExpression":
this.checkToRestConversion(node.expression, false);
Expand All @@ -3594,6 +3597,7 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
| "TSParameterProperty"
| "TSNonNullExpression"
| "TSAsExpression"
| "TSSatisfiesExpression"
| "TSTypeAssertion",
isUnparenthesizedInAssign: boolean,
binding: BindingTypes,
Expand All @@ -3609,6 +3613,8 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
TSNonNullExpression: "expression",
TSAsExpression: (binding !== BIND_NONE ||
!isUnparenthesizedInAssign) && ["expression", true],
TSSatisfiesExpression: (binding !== BIND_NONE ||
!isUnparenthesizedInAssign) && ["expression", true],
TSTypeAssertion: (binding !== BIND_NONE ||
!isUnparenthesizedInAssign) && ["expression", true],
},
Expand Down
@@ -1,2 +1,4 @@
x satisfies T;
x < y satisfies boolean; // (x < y) satisfies boolean;
(a satisfies any) = null;
[(a satisfies any)] = b;
@@ -1,9 +1,9 @@
{
"type": "File",
"start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":54,"index":69}},
"start":0,"end":120,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":24,"index":120}},
"program": {
"type": "Program",
"start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":54,"index":69}},
"start":0,"end":120,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":24,"index":120}},
"sourceType": "module",
"interpreter": null,
"body": [
Expand Down Expand Up @@ -62,6 +62,80 @@
"start":40,"end":69,"loc":{"start":{"line":2,"column":25,"index":40},"end":{"line":2,"column":54,"index":69}}
}
]
},
{
"type": "ExpressionStatement",
"start":70,"end":95,"loc":{"start":{"line":3,"column":0,"index":70},"end":{"line":3,"column":25,"index":95}},
"expression": {
"type": "AssignmentExpression",
"start":70,"end":94,"loc":{"start":{"line":3,"column":0,"index":70},"end":{"line":3,"column":24,"index":94}},
"operator": "=",
"left": {
"type": "TSSatisfiesExpression",
"start":71,"end":86,"loc":{"start":{"line":3,"column":1,"index":71},"end":{"line":3,"column":16,"index":86}},
"expression": {
"type": "Identifier",
"start":71,"end":72,"loc":{"start":{"line":3,"column":1,"index":71},"end":{"line":3,"column":2,"index":72},"identifierName":"a"},
"name": "a"
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start":83,"end":86,"loc":{"start":{"line":3,"column":13,"index":83},"end":{"line":3,"column":16,"index":86}}
},
"extra": {
"parenthesized": true,
"parenStart": 70
}
},
"right": {
"type": "NullLiteral",
"start":90,"end":94,"loc":{"start":{"line":3,"column":20,"index":90},"end":{"line":3,"column":24,"index":94}}
}
},
"leadingComments": [
{
"type": "CommentLine",
"value": " (x < y) satisfies boolean;",
"start":40,"end":69,"loc":{"start":{"line":2,"column":25,"index":40},"end":{"line":2,"column":54,"index":69}}
}
]
},
{
"type": "ExpressionStatement",
"start":96,"end":120,"loc":{"start":{"line":4,"column":0,"index":96},"end":{"line":4,"column":24,"index":120}},
"expression": {
"type": "AssignmentExpression",
"start":96,"end":119,"loc":{"start":{"line":4,"column":0,"index":96},"end":{"line":4,"column":23,"index":119}},
"operator": "=",
"left": {
"type": "ArrayPattern",
"start":96,"end":115,"loc":{"start":{"line":4,"column":0,"index":96},"end":{"line":4,"column":19,"index":115}},
"elements": [
{
"type": "TSSatisfiesExpression",
"start":98,"end":113,"loc":{"start":{"line":4,"column":2,"index":98},"end":{"line":4,"column":17,"index":113}},
"expression": {
"type": "Identifier",
"start":98,"end":99,"loc":{"start":{"line":4,"column":2,"index":98},"end":{"line":4,"column":3,"index":99},"identifierName":"a"},
"name": "a"
},
"typeAnnotation": {
"type": "TSAnyKeyword",
"start":110,"end":113,"loc":{"start":{"line":4,"column":14,"index":110},"end":{"line":4,"column":17,"index":113}}
},
"extra": {
"parenthesized": true,
"parenStart": 97
}
}
]
},
"right": {
"type": "Identifier",
"start":118,"end":119,"loc":{"start":{"line":4,"column":22,"index":118},"end":{"line":4,"column":23,"index":119},"identifierName":"b"},
"name": "b"
}
}
}
],
"directives": []
Expand Down

0 comments on commit 292e5d6

Please sign in to comment.