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:
Sakibul Mowla
2019-11-11 21:38:13 +00:00
committed by Nicolò Ribaudo
parent b2767c7d8a
commit 4cb5e0a013
3 changed files with 283 additions and 5 deletions

View File

@@ -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;
}
}