Allow TypeScript type assertions in array destructuring (#10592)
* Add test * Add fix * Fix test, destructure with as assertion * Add angle-bracket assertion case * Use isBinding to make typeCastToParameter decision
This commit is contained in:
committed by
Nicolò Ribaudo
parent
b2767c7d8a
commit
4cb5e0a013
@@ -2483,7 +2483,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
}
|
||||
}
|
||||
|
||||
toAssignableList(exprList: N.Expression[]): $ReadOnlyArray<N.Pattern> {
|
||||
toAssignableList(
|
||||
exprList: N.Expression[],
|
||||
isBinding: ?boolean,
|
||||
): $ReadOnlyArray<N.Pattern> {
|
||||
for (let i = 0; i < exprList.length; i++) {
|
||||
const expr = exprList[i];
|
||||
if (!expr) continue;
|
||||
@@ -2493,10 +2496,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
break;
|
||||
case "TSAsExpression":
|
||||
case "TSTypeAssertion":
|
||||
this.raise(
|
||||
expr.start,
|
||||
"Unexpected type cast in parameter position.",
|
||||
);
|
||||
if (!isBinding) {
|
||||
exprList[i] = this.typeCastToParameter(expr);
|
||||
} else {
|
||||
this.raise(
|
||||
expr.start,
|
||||
"Unexpected type cast in parameter position.",
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user