Skip to content

Commit

Permalink
drop tsTryParseTypeArguments method
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Robertson committed May 21, 2019
1 parent b5a84b0 commit 0c165e3
Showing 1 changed file with 27 additions and 53 deletions.
80 changes: 27 additions & 53 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -1469,35 +1469,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
);
}

tsTryParseTypeArguments(): ?N.TsTypeParameterInstantiation {
if (!this.isRelational("<")) {
return undefined;
}
const state = this.state.clone();
const node = this.startNode();
const params = this.tsInType(() =>
// Temporarily remove a JSX parsing context, which makes us scan different tokens.
this.tsInNoContext(() => {
this.next();
return this.tsTryParseDelimitedList(
"TypeParametersOrArguments",
this.tsParseType.bind(this),
);
}),
);
if (params) {
node.params = params;
// This reads the next token after the `>` too, so do this in the enclosing context.
// But be sure not to parse a regex in the jsx expression `<C<number> />`, so set exprAllowed = false
this.state.exprAllowed = false;
if (this.eatRelational(">")) {
return this.finishNode(node, "TSTypeParameterInstantiation");
}
}
this.state = state;
return undefined;
}

tsParseTypeArguments(): N.TsTypeParameterInstantiation {
const node = this.startNode();
node.params = this.tsInType(() =>
Expand Down Expand Up @@ -1656,28 +1627,27 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const node: N.CallExpression = this.startNodeAt(startPos, startLoc);
node.callee = base;

const typeArguments = this.tsTryParseTypeArguments();
if (!typeArguments) {
return undefined;
}

if (!noCalls && this.eat(tt.parenL)) {
// possibleAsync always false here, because we would have handled it above.
// $FlowIgnore (won't be any undefined arguments)
node.arguments = this.parseCallExpressionArguments(
tt.parenR,
/* possibleAsync */ false,
);
node.typeParameters = typeArguments;
return this.finishCallExpression(node);
} else if (this.match(tt.backQuote)) {
return this.parseTaggedTemplateExpression(
startPos,
startLoc,
base,
state,
typeArguments,
);
const typeArguments = this.tsParseTypeArguments();

if (typeArguments) {
if (!noCalls && this.eat(tt.parenL)) {
// possibleAsync always false here, because we would have handled it above.
// $FlowIgnore (won't be any undefined arguments)
node.arguments = this.parseCallExpressionArguments(
tt.parenR,
/* possibleAsync */ false,
);
node.typeParameters = typeArguments;
return this.finishCallExpression(node);
} else if (this.match(tt.backQuote)) {
return this.parseTaggedTemplateExpression(
startPos,
startLoc,
base,
state,
typeArguments,
);
}
}

this.unexpected();
Expand Down Expand Up @@ -2473,8 +2443,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
jsxParseOpeningElementAfterName(
node: N.JSXOpeningElement,
): N.JSXOpeningElement {
const typeArguments = this.tsTryParseTypeArguments();
if (typeArguments) node.typeParameters = typeArguments;
if (this.isRelational("<")) {
const typeArguments = this.tsTryParseAndCatch(() =>
this.tsParseTypeArguments(),
);
if (typeArguments) node.typeParameters = typeArguments;
}
return super.jsxParseOpeningElementAfterName(node);
}

Expand Down

0 comments on commit 0c165e3

Please sign in to comment.