Move check for TSTypeCastExpression to catch another case (#12161)
This commit is contained in:
parent
62965e3880
commit
13a1cfd396
@ -1803,6 +1803,27 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parseExprListItem(
|
||||||
|
allowEmpty: ?boolean,
|
||||||
|
refExpressionErrors?: ?ExpressionErrors,
|
||||||
|
refNeedsArrowPos: ?Pos,
|
||||||
|
allowPlaceholder: ?boolean,
|
||||||
|
): ?N.Expression {
|
||||||
|
const node = super.parseExprListItem(
|
||||||
|
allowEmpty,
|
||||||
|
refExpressionErrors,
|
||||||
|
refNeedsArrowPos,
|
||||||
|
allowPlaceholder,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle `func(a: T)` or `func<T>(a: T)`
|
||||||
|
if (!refNeedsArrowPos && node?.type === "TSTypeCastExpression") {
|
||||||
|
this.raise(node.start, TSErrors.UnexpectedTypeAnnotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
parseSubscript(
|
parseSubscript(
|
||||||
base: N.Expression,
|
base: N.Expression,
|
||||||
startPos: number,
|
startPos: number,
|
||||||
@ -2725,20 +2746,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
return node.expression;
|
return node.expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
toReferencedList(
|
|
||||||
exprList: $ReadOnlyArray<?N.Expression>,
|
|
||||||
isInParens?: boolean, // eslint-disable-line no-unused-vars
|
|
||||||
): $ReadOnlyArray<?N.Expression> {
|
|
||||||
for (let i = 0; i < exprList.length; i++) {
|
|
||||||
const expr = exprList[i];
|
|
||||||
if (expr?.type === "TSTypeCastExpression") {
|
|
||||||
this.raise(expr.start, TSErrors.UnexpectedTypeAnnotation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return exprList;
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldParseArrow() {
|
shouldParseArrow() {
|
||||||
return this.match(tt.colon) || super.shouldParseArrow();
|
return this.match(tt.colon) || super.shouldParseArrow();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
func(a: T);
|
func(a: T);
|
||||||
|
func<T>(a: T);
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
|
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":14}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Did not expect a type annotation here. (1:5)"
|
"SyntaxError: Did not expect a type annotation here. (1:5)",
|
||||||
|
"SyntaxError: Did not expect a type annotation here. (2:8)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
|
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":14}},
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
"interpreter": null,
|
"interpreter": null,
|
||||||
"body": [
|
"body": [
|
||||||
@ -46,6 +47,58 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ExpressionStatement",
|
||||||
|
"start":12,"end":26,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":14}},
|
||||||
|
"expression": {
|
||||||
|
"type": "CallExpression",
|
||||||
|
"start":12,"end":25,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":13}},
|
||||||
|
"callee": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":12,"end":16,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":4},"identifierName":"func"},
|
||||||
|
"name": "func"
|
||||||
|
},
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeCastExpression",
|
||||||
|
"start":20,"end":24,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":12}},
|
||||||
|
"expression": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":20,"end":21,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9},"identifierName":"a"},
|
||||||
|
"name": "a"
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":21,"end":24,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeReference",
|
||||||
|
"start":23,"end":24,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12}},
|
||||||
|
"typeName": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":23,"end":24,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":12},"identifierName":"T"},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeParameters": {
|
||||||
|
"type": "TSTypeParameterInstantiation",
|
||||||
|
"start":16,"end":19,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":7}},
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"type": "TSTypeReference",
|
||||||
|
"start":17,"end":18,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6}},
|
||||||
|
"typeName": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":17,"end":18,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":6},"identifierName":"T"},
|
||||||
|
"name": "T"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"directives": []
|
"directives": []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user