[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:
Nicolò Ribaudo
2019-11-04 19:25:15 +01:00
committed by Huáng Jùnliàng
parent abce0ef49d
commit d023e105b7
6 changed files with 204 additions and 29 deletions

View File

@@ -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;

View File

@@ -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,