[TS] Disallow type casts in arrow parameters (#9612)

This commit is contained in:
Nicolò Ribaudo 2019-02-28 23:58:27 +01:00 committed by GitHub
parent d72f3aa758
commit f13f4adcbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 2 deletions

View File

@ -2268,8 +2268,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
): $ReadOnlyArray<N.Pattern> { ): $ReadOnlyArray<N.Pattern> {
for (let i = 0; i < exprList.length; i++) { for (let i = 0; i < exprList.length; i++) {
const expr = exprList[i]; const expr = exprList[i];
if (expr && expr.type === "TSTypeCastExpression") { if (!expr) continue;
exprList[i] = this.typeCastToParameter(expr); switch (expr.type) {
case "TSTypeCastExpression":
exprList[i] = this.typeCastToParameter(expr);
break;
case "TSAsExpression":
case "TSTypeAssertion":
this.raise(
expr.start,
"Unexpected type cast in parameter position.",
);
break;
} }
} }
return super.toAssignableList(exprList, isBinding, contextDescription); return super.toAssignableList(exprList, isBinding, contextDescription);

View File

@ -0,0 +1 @@
async (a as T) => {};

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected type cast in parameter position. (1:7)"
}

View File

@ -0,0 +1 @@
async (<T> a) => {};

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected type cast in parameter position. (1:7)"
}

View File

@ -0,0 +1 @@
(a as T) => {};

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected type cast in parameter position. (1:1)"
}

View File

@ -0,0 +1 @@
(<T> a) => {};

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected type cast in parameter position. (1:1)"
}