[ts] Error on invalid type casts in JSX (#12221)

This commit is contained in:
Brian Ng
2020-10-23 08:09:35 -05:00
committed by GitHub
parent 8b579a27dc
commit c00bb14f79
8 changed files with 294 additions and 18 deletions

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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,