Fix: remove constant context type check for TS (#9869)
This commit is contained in:
parent
338853b5d3
commit
4198d91b89
@ -331,36 +331,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
return null;
|
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`,
|
// Note: In TypeScript implementation we must provide `yieldContext` and `awaitContext`,
|
||||||
// but here it's always false, because this is only used for types.
|
// but here it's always false, because this is only used for types.
|
||||||
tsFillSignature(
|
tsFillSignature(
|
||||||
@ -1011,9 +981,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
node.typeAnnotation = _const || this.tsNextThenParseType();
|
node.typeAnnotation = _const || this.tsNextThenParseType();
|
||||||
this.expectRelational(">");
|
this.expectRelational(">");
|
||||||
node.expression = this.parseMaybeUnary();
|
node.expression = this.parseMaybeUnary();
|
||||||
if (_const) {
|
|
||||||
this.tsCheckLiteralForConstantContext(node.expression);
|
|
||||||
}
|
|
||||||
return this.finishNode(node, "TSTypeAssertion");
|
return this.finishNode(node, "TSTypeAssertion");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1679,7 +1646,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
node.expression = left;
|
node.expression = left;
|
||||||
const _const = this.tsTryNextParseConstantContext();
|
const _const = this.tsTryNextParseConstantContext();
|
||||||
if (_const) {
|
if (_const) {
|
||||||
this.tsCheckLiteralForConstantContext(node.expression);
|
|
||||||
node.typeAnnotation = _const;
|
node.typeAnnotation = _const;
|
||||||
} else {
|
} else {
|
||||||
node.typeAnnotation = this.tsNextThenParseType();
|
node.typeAnnotation = this.tsNextThenParseType();
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
let e = v as const; // Error
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"sourceType": "module",
|
|
||||||
"plugins": [
|
|
||||||
"typescript"
|
|
||||||
],
|
|
||||||
"throws": "Only literal values are allowed in constant contexts (1:8)"
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
let e = (true ? 1 : 0) as const; // Error
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"sourceType": "module",
|
|
||||||
"plugins": [
|
|
||||||
"typescript"
|
|
||||||
],
|
|
||||||
"throws": "Only literal values are allowed in constant contexts (1:9)"
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
let e = id(1) as const; // Error
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"sourceType": "module",
|
|
||||||
"plugins": [
|
|
||||||
"typescript"
|
|
||||||
],
|
|
||||||
"throws": "Only literal values are allowed in constant contexts (1:8)"
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
let e = [v()] as const; // Error
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"sourceType": "module",
|
|
||||||
"plugins": [
|
|
||||||
"typescript"
|
|
||||||
],
|
|
||||||
"throws": "Only literal values are allowed in constant contexts (1:9)"
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user