[ts] Error on invalid type casts in JSX (#12221)
This commit is contained in:
@@ -379,16 +379,19 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return node;
|
||||
}
|
||||
|
||||
toReferencedListDeep(
|
||||
exprList: $ReadOnlyArray<?N.Expression>,
|
||||
isParenthesizedExpr?: boolean,
|
||||
): void {
|
||||
toReferencedArguments(
|
||||
node:
|
||||
| N.CallExpression
|
||||
| N.OptionalCallExpression
|
||||
| N.EstreeImportExpression,
|
||||
/* isParenthesizedExpr?: boolean, */
|
||||
) {
|
||||
// ImportExpressions do not have an arguments array.
|
||||
if (!exprList) {
|
||||
if (node.type === "ImportExpression") {
|
||||
return;
|
||||
}
|
||||
|
||||
super.toReferencedListDeep(exprList, isParenthesizedExpr);
|
||||
super.toReferencedArguments(node);
|
||||
}
|
||||
|
||||
parseExport(node: N.Node) {
|
||||
|
||||
@@ -2233,6 +2233,31 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return exprList;
|
||||
}
|
||||
|
||||
parseArrayLike(
|
||||
close: TokenType,
|
||||
canBePattern: boolean,
|
||||
isTuple: boolean,
|
||||
refExpressionErrors: ?ExpressionErrors,
|
||||
): N.ArrayExpression | N.TupleExpression {
|
||||
const node = super.parseArrayLike(
|
||||
close,
|
||||
canBePattern,
|
||||
isTuple,
|
||||
refExpressionErrors,
|
||||
);
|
||||
|
||||
// This could be an array pattern:
|
||||
// ([a: string, b: string]) => {}
|
||||
// In this case, we don't have to call toReferencedList. We will
|
||||
// call it, if needed, when we are sure that it is a parenthesized
|
||||
// expression by calling toReferencedListDeep.
|
||||
if (canBePattern && !this.state.maybeInArrowParameters) {
|
||||
this.toReferencedList(node.elements);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
checkLVal(
|
||||
expr: N.Expression,
|
||||
bindingType: BindingTypes = BIND_NONE,
|
||||
|
||||
@@ -1839,6 +1839,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return exprList;
|
||||
}
|
||||
|
||||
parseArrayLike(...args): N.ArrayExpression | N.TupleExpression {
|
||||
const node = super.parseArrayLike(...args);
|
||||
|
||||
if (node.type === "ArrayExpression") {
|
||||
this.tsCheckForInvalidTypeCasts(node.elements);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
parseSubscript(
|
||||
base: N.Expression,
|
||||
startPos: number,
|
||||
|
||||
Reference in New Issue
Block a user