diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 0940878ae2..e94617060b 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -331,36 +331,6 @@ export default (superClass: Class): Class => return null; } - tsCheckLiteralForConstantContext(node: N.Node) { - switch (node.type) { - case "StringLiteral": - case "TemplateLiteral": - case "NumericLiteral": - case "BooleanLiteral": - case "SpreadElement": - case "ObjectMethod": - case "ObjectExpression": - return; - case "ArrayExpression": - return (node: N.ArrayExpression).elements.forEach(element => { - if (element) { - this.tsCheckLiteralForConstantContext(element); - } - }); - case "ObjectProperty": - return this.tsCheckLiteralForConstantContext( - (node: N.ObjectProperty).value, - ); - case "UnaryExpression": - return this.tsCheckLiteralForConstantContext(node.argument); - default: - this.raise( - node.start, - "Only literal values are allowed in constant contexts", - ); - } - } - // Note: In TypeScript implementation we must provide `yieldContext` and `awaitContext`, // but here it's always false, because this is only used for types. tsFillSignature( @@ -1011,9 +981,6 @@ export default (superClass: Class): Class => node.typeAnnotation = _const || this.tsNextThenParseType(); this.expectRelational(">"); node.expression = this.parseMaybeUnary(); - if (_const) { - this.tsCheckLiteralForConstantContext(node.expression); - } return this.finishNode(node, "TSTypeAssertion"); } @@ -1679,7 +1646,6 @@ export default (superClass: Class): Class => node.expression = left; const _const = this.tsTryNextParseConstantContext(); if (_const) { - this.tsCheckLiteralForConstantContext(node.expression); node.typeAnnotation = _const; } else { node.typeAnnotation = this.tsNextThenParseType(); diff --git a/packages/babel-parser/test/fixtures/typescript/cast/as-const-2/input.js b/packages/babel-parser/test/fixtures/typescript/cast/as-const-2/input.js deleted file mode 100644 index d7726d95d3..0000000000 --- a/packages/babel-parser/test/fixtures/typescript/cast/as-const-2/input.js +++ /dev/null @@ -1 +0,0 @@ -let e = v as const; // Error \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/as-const-2/options.json b/packages/babel-parser/test/fixtures/typescript/cast/as-const-2/options.json deleted file mode 100644 index 5f9e8f5684..0000000000 --- a/packages/babel-parser/test/fixtures/typescript/cast/as-const-2/options.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sourceType": "module", - "plugins": [ - "typescript" - ], - "throws": "Only literal values are allowed in constant contexts (1:8)" -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/as-const-3/input.js b/packages/babel-parser/test/fixtures/typescript/cast/as-const-3/input.js deleted file mode 100644 index 595a2da190..0000000000 --- a/packages/babel-parser/test/fixtures/typescript/cast/as-const-3/input.js +++ /dev/null @@ -1 +0,0 @@ -let e = (true ? 1 : 0) as const; // Error \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/as-const-3/options.json b/packages/babel-parser/test/fixtures/typescript/cast/as-const-3/options.json deleted file mode 100644 index 921c09e5f1..0000000000 --- a/packages/babel-parser/test/fixtures/typescript/cast/as-const-3/options.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sourceType": "module", - "plugins": [ - "typescript" - ], - "throws": "Only literal values are allowed in constant contexts (1:9)" -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/as-const-4/input.js b/packages/babel-parser/test/fixtures/typescript/cast/as-const-4/input.js deleted file mode 100644 index 1ebd71b2dc..0000000000 --- a/packages/babel-parser/test/fixtures/typescript/cast/as-const-4/input.js +++ /dev/null @@ -1 +0,0 @@ -let e = id(1) as const; // Error \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/as-const-4/options.json b/packages/babel-parser/test/fixtures/typescript/cast/as-const-4/options.json deleted file mode 100644 index 5f9e8f5684..0000000000 --- a/packages/babel-parser/test/fixtures/typescript/cast/as-const-4/options.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sourceType": "module", - "plugins": [ - "typescript" - ], - "throws": "Only literal values are allowed in constant contexts (1:8)" -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/as-const-5/input.js b/packages/babel-parser/test/fixtures/typescript/cast/as-const-5/input.js deleted file mode 100644 index b68d9dea18..0000000000 --- a/packages/babel-parser/test/fixtures/typescript/cast/as-const-5/input.js +++ /dev/null @@ -1 +0,0 @@ -let e = [v()] as const; // Error \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/cast/as-const-5/options.json b/packages/babel-parser/test/fixtures/typescript/cast/as-const-5/options.json deleted file mode 100644 index 921c09e5f1..0000000000 --- a/packages/babel-parser/test/fixtures/typescript/cast/as-const-5/options.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sourceType": "module", - "plugins": [ - "typescript" - ], - "throws": "Only literal values are allowed in constant contexts (1:9)" -} \ No newline at end of file