[TS] Disallow type casts in arrow parameters (#9612)
This commit is contained in:
parent
d72f3aa758
commit
f13f4adcbb
@ -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;
|
||||||
|
switch (expr.type) {
|
||||||
|
case "TSTypeCastExpression":
|
||||||
exprList[i] = this.typeCastToParameter(expr);
|
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);
|
||||||
|
|||||||
1
packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
async (a as T) => {};
|
||||||
3
packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected type cast in parameter position. (1:7)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-assertion/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-assertion/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
async (<T> a) => {};
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected type cast in parameter position. (1:7)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(a as T) => {};
|
||||||
3
packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected type cast in parameter position. (1:1)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(<T> a) => {};
|
||||||
3
packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected type cast in parameter position. (1:1)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user