[TS] Parse calls with type args in optional chains (#10631)
* [TS] Parse calls with type args in optional chains * Test output
This commit is contained in:
committed by
Huáng Jùnliàng
parent
abce0ef49d
commit
d023e105b7
@@ -628,7 +628,7 @@ export default class ExpressionParser extends LValParser {
|
||||
node.callee = base;
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
|
||||
node.optional = true;
|
||||
return this.finishNode(node, "OptionalCallExpression");
|
||||
return this.finishCallExpression(node, /* optional */ true);
|
||||
} else {
|
||||
node.object = base;
|
||||
node.property = this.parseIdentifier(true);
|
||||
@@ -683,11 +683,7 @@ export default class ExpressionParser extends LValParser {
|
||||
base.type !== "Super",
|
||||
node,
|
||||
);
|
||||
if (!state.optionalChainMember) {
|
||||
this.finishCallExpression(node);
|
||||
} else {
|
||||
this.finishOptionalCallExpression(node);
|
||||
}
|
||||
this.finishCallExpression(node, state.optionalChainMember);
|
||||
|
||||
if (state.maybeAsyncArrow && this.shouldParseAsyncArrow()) {
|
||||
state.stop = true;
|
||||
@@ -783,7 +779,10 @@ export default class ExpressionParser extends LValParser {
|
||||
);
|
||||
}
|
||||
|
||||
finishCallExpression(node: N.CallExpression): N.CallExpression {
|
||||
finishCallExpression<T: N.CallExpression | N.OptionalCallExpression>(
|
||||
node: T,
|
||||
optional: boolean,
|
||||
): T {
|
||||
if (node.callee.type === "Import") {
|
||||
if (node.arguments.length !== 1) {
|
||||
this.raise(node.start, "import() requires exactly one argument");
|
||||
@@ -794,21 +793,10 @@ export default class ExpressionParser extends LValParser {
|
||||
this.raise(importArg.start, "... is not allowed in import()");
|
||||
}
|
||||
}
|
||||
return this.finishNode(node, "CallExpression");
|
||||
}
|
||||
|
||||
finishOptionalCallExpression(node: N.CallExpression): N.CallExpression {
|
||||
if (node.callee.type === "Import") {
|
||||
if (node.arguments.length !== 1) {
|
||||
this.raise(node.start, "import() requires exactly one argument");
|
||||
}
|
||||
|
||||
const importArg = node.arguments[0];
|
||||
if (importArg && importArg.type === "SpreadElement") {
|
||||
this.raise(importArg.start, "... is not allowed in import()");
|
||||
}
|
||||
}
|
||||
return this.finishNode(node, "OptionalCallExpression");
|
||||
return this.finishNode(
|
||||
node,
|
||||
optional ? "OptionalCallExpression" : "CallExpression",
|
||||
);
|
||||
}
|
||||
|
||||
parseCallExpressionArguments(
|
||||
|
||||
@@ -2709,7 +2709,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
// $FlowFixMe
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
|
||||
node.optional = true;
|
||||
return this.finishNode(node, "OptionalCallExpression");
|
||||
return this.finishCallExpression(node, /* optional */ true);
|
||||
} else if (
|
||||
!noCalls &&
|
||||
this.shouldParseTypes() &&
|
||||
@@ -2722,11 +2722,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
|
||||
this.expect(tt.parenL);
|
||||
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
|
||||
if (subscriptState.optionalChainMember) {
|
||||
node.optional = false;
|
||||
return this.finishNode(node, "OptionalCallExpression");
|
||||
}
|
||||
return this.finishNode(node, "CallExpression");
|
||||
if (subscriptState.optionalChainMember) node.optional = false;
|
||||
return this.finishCallExpression(
|
||||
node,
|
||||
subscriptState.optionalChainMember,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
this.state = state;
|
||||
|
||||
@@ -1655,7 +1655,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
/* possibleAsync */ false,
|
||||
);
|
||||
node.typeParameters = typeArguments;
|
||||
return this.finishCallExpression(node);
|
||||
return this.finishCallExpression(node, state.optionalChainMember);
|
||||
} else if (this.match(tt.backQuote)) {
|
||||
return this.parseTaggedTemplateExpression(
|
||||
startPos,
|
||||
|
||||
Reference in New Issue
Block a user