Skip to content

Commit

Permalink
Do not use lookahead when parsing construct signature declarations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed May 21, 2019
1 parent 0430a48 commit f5b8140
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -397,13 +397,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>

tsParseSignatureMember(
kind: "TSCallSignatureDeclaration" | "TSConstructSignatureDeclaration",
node: N.TsCallSignatureDeclaration | N.TsConstructSignatureDeclaration,
): N.TsCallSignatureDeclaration | N.TsConstructSignatureDeclaration {
const node:
| N.TsCallSignatureDeclaration
| N.TsConstructSignatureDeclaration = this.startNode();
if (kind === "TSConstructSignatureDeclaration") {
this.expect(tt._new);
}
this.tsFillSignature(tt.colon, node);
this.tsParseTypeMemberSemicolon();
return this.finishNode(node, kind);
Expand Down Expand Up @@ -442,7 +437,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
node: N.TsPropertySignature | N.TsMethodSignature,
readonly: boolean,
): N.TsPropertySignature | N.TsMethodSignature {
this.parsePropertyName(node);
if (this.eat(tt.question)) node.optional = true;
const nodeAny: any = node;

Expand All @@ -462,30 +456,36 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

tsParseTypeMember(): N.TsTypeElement {
const node: any = this.startNode();

if (this.match(tt.parenL) || this.isRelational("<")) {
return this.tsParseSignatureMember("TSCallSignatureDeclaration");
return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
}
if (
this.match(tt._new) &&
this.tsLookAhead(this.tsIsStartOfConstructSignature.bind(this))
) {
return this.tsParseSignatureMember("TSConstructSignatureDeclaration");

if (this.match(tt._new)) {
const id: N.Identifier = this.startNode();
this.next();
if (this.match(tt.parenL) || this.isRelational("<")) {
return this.tsParseSignatureMember(
"TSConstructSignatureDeclaration",
node,
);
} else {
node.key = this.createIdentifier(id, "new");
return this.tsParsePropertyOrMethodSignature(node, false);
}
}
// Instead of fullStart, we create a node here.
const node: any = this.startNode();

const readonly = !!this.tsParseModifier(["readonly"]);

const idx = this.tsTryParseIndexSignature(node);
if (idx) {
if (readonly) node.readonly = true;
return idx;
}
return this.tsParsePropertyOrMethodSignature(node, readonly);
}

tsIsStartOfConstructSignature() {
this.next();
return this.match(tt.parenL) || this.isRelational("<");
this.parsePropertyName(node);
return this.tsParsePropertyOrMethodSignature(node, readonly);
}

tsParseTypeLiteral(): N.TsTypeLiteral {
Expand Down

0 comments on commit f5b8140

Please sign in to comment.