Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Factor out overridable parseNewArguments to replace parseNewTypeArgum…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
Andy Hanson committed Jun 26, 2017
1 parent 87564dc commit 102be0e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
22 changes: 9 additions & 13 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,26 +793,22 @@ export default class ExpressionParser extends LValParser {
}

node.callee = this.parseNoCallExpr();
const optional = this.eat(tt.questionDot);

this.parseNewTypeArguments(node);
if (this.eat(tt.questionDot)) node.optional = true;
this.parseNewArguments(node);
return this.finishNode(node, "NewExpression");
}

parseNewArguments(node: N.NewExpression): void {
if (this.eat(tt.parenL)) {
node.arguments = this.parseExprList(tt.parenR);
this.toReferencedList(node.arguments);
const args = this.parseExprList(tt.parenR);
this.toReferencedList(args);
// $FlowFixMe (parseExprList should be all non-null in this case)
node.arguments = args;
} else {
node.arguments = [];
}
if (optional) {
node.optional = true;
}

return this.finishNode(node, "NewExpression");
}

// eslint-disable-next-line no-unused-vars
parseNewTypeArguments(node: N.NewExpression) {}

// Parse template expression.

parseTemplateElement(isTagged: boolean): N.TemplateElement {
Expand Down
16 changes: 8 additions & 8 deletions src/plugins/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1147,16 +1147,16 @@ export default (superClass: Class<Parser>): Class<Parser> => class extends super
return super.parseSubscript(base, startPos, startLoc, noCalls, state);
}

parseNewTypeArguments(node: N.NewExpression): void {
if (!this.isRelational("<")) { // tsTryParseAndCatch is expensive, so avoid if not necessary.
return;
parseNewArguments(node: N.NewExpression): void {
if (this.isRelational("<")) { // tsTryParseAndCatch is expensive, so avoid if not necessary.
// 99% certain this is `new C<T>();`. But may be `new C < T;`, which is also legal.
const typeParameters = this.tsTryParseAndCatch(this.tsParseTypeArguments.bind(this));
if (typeParameters) {
node.typeParameters = typeParameters;
}
}

// 99% certain this is `new C<T>();`. But may be `new C < T;`, which is also legal.
const typeParameters = this.tsTryParseAndCatch(this.tsParseTypeArguments.bind(this));
if (typeParameters) {
node.typeParameters = typeParameters;
}
super.parseNewArguments(node);
}

parseExprOp(
Expand Down
1 change: 1 addition & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ export type CallExpression = CallOrNewBase & {

export type NewExpression = CallOrNewBase & {
type: "NewExpression";
optional?: boolean; // TODO: Not in spec
};

export type SequenceExpression = NodeBase & {
Expand Down

0 comments on commit 102be0e

Please sign in to comment.