diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 7bc3623d78..7d1f81d1b8 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -2268,8 +2268,18 @@ export default (superClass: Class): Class => ): $ReadOnlyArray { for (let i = 0; i < exprList.length; i++) { const expr = exprList[i]; - if (expr && expr.type === "TSTypeCastExpression") { - exprList[i] = this.typeCastToParameter(expr); + if (!expr) continue; + 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); diff --git a/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/input.js b/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/input.js new file mode 100644 index 0000000000..746078a226 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/input.js @@ -0,0 +1 @@ +async (a as T) => {}; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/options.json b/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/options.json new file mode 100644 index 0000000000..69d9150249 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-as/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected type cast in parameter position. (1:7)" +} diff --git a/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-assertion/input.js b/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-assertion/input.js new file mode 100644 index 0000000000..5e3f1481d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-assertion/input.js @@ -0,0 +1 @@ +async ( a) => {}; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-assertion/options.json b/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-assertion/options.json new file mode 100644 index 0000000000..69d9150249 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/arrow-async-parameter-assertion/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected type cast in parameter position. (1:7)" +} diff --git a/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/input.js b/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/input.js new file mode 100644 index 0000000000..dc2282c6bd --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/input.js @@ -0,0 +1 @@ +(a as T) => {}; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/options.json b/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/options.json new file mode 100644 index 0000000000..b5bdba868c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-as/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected type cast in parameter position. (1:1)" +} diff --git a/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/input.js b/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/input.js new file mode 100644 index 0000000000..39dae7d0cf --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/input.js @@ -0,0 +1 @@ +( a) => {}; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/options.json b/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/options.json new file mode 100644 index 0000000000..b5bdba868c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/cast/arrow-parameter-assertion/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected type cast in parameter position. (1:1)" +}