Move check for TSTypeCastExpression to catch another case (#12161)

This commit is contained in:
Brian Ng
2020-10-11 06:03:57 -05:00
committed by GitHub
parent 62965e3880
commit 13a1cfd396
3 changed files with 78 additions and 17 deletions

View File

@@ -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(
base: N.Expression,
startPos: number,
@@ -2725,20 +2746,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
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() {
return this.match(tt.colon) || super.shouldParseArrow();
}