Do not use lookahead when parsing construct signature declarations (#9995)
This commit is contained in:
parent
0430a48775
commit
f5b8140580
@ -397,13 +397,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
|
|
||||||
tsParseSignatureMember(
|
tsParseSignatureMember(
|
||||||
kind: "TSCallSignatureDeclaration" | "TSConstructSignatureDeclaration",
|
kind: "TSCallSignatureDeclaration" | "TSConstructSignatureDeclaration",
|
||||||
|
node: N.TsCallSignatureDeclaration | N.TsConstructSignatureDeclaration,
|
||||||
): 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.tsFillSignature(tt.colon, node);
|
||||||
this.tsParseTypeMemberSemicolon();
|
this.tsParseTypeMemberSemicolon();
|
||||||
return this.finishNode(node, kind);
|
return this.finishNode(node, kind);
|
||||||
@ -442,7 +437,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
node: N.TsPropertySignature | N.TsMethodSignature,
|
node: N.TsPropertySignature | N.TsMethodSignature,
|
||||||
readonly: boolean,
|
readonly: boolean,
|
||||||
): N.TsPropertySignature | N.TsMethodSignature {
|
): N.TsPropertySignature | N.TsMethodSignature {
|
||||||
this.parsePropertyName(node);
|
|
||||||
if (this.eat(tt.question)) node.optional = true;
|
if (this.eat(tt.question)) node.optional = true;
|
||||||
const nodeAny: any = node;
|
const nodeAny: any = node;
|
||||||
|
|
||||||
@ -462,17 +456,26 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
tsParseTypeMember(): N.TsTypeElement {
|
tsParseTypeMember(): N.TsTypeElement {
|
||||||
if (this.match(tt.parenL) || this.isRelational("<")) {
|
|
||||||
return this.tsParseSignatureMember("TSCallSignatureDeclaration");
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
this.match(tt._new) &&
|
|
||||||
this.tsLookAhead(this.tsIsStartOfConstructSignature.bind(this))
|
|
||||||
) {
|
|
||||||
return this.tsParseSignatureMember("TSConstructSignatureDeclaration");
|
|
||||||
}
|
|
||||||
// Instead of fullStart, we create a node here.
|
|
||||||
const node: any = this.startNode();
|
const node: any = this.startNode();
|
||||||
|
|
||||||
|
if (this.match(tt.parenL) || this.isRelational("<")) {
|
||||||
|
return this.tsParseSignatureMember("TSCallSignatureDeclaration", node);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const readonly = !!this.tsParseModifier(["readonly"]);
|
const readonly = !!this.tsParseModifier(["readonly"]);
|
||||||
|
|
||||||
const idx = this.tsTryParseIndexSignature(node);
|
const idx = this.tsTryParseIndexSignature(node);
|
||||||
@ -480,12 +483,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
if (readonly) node.readonly = true;
|
if (readonly) node.readonly = true;
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
return this.tsParsePropertyOrMethodSignature(node, readonly);
|
|
||||||
}
|
|
||||||
|
|
||||||
tsIsStartOfConstructSignature() {
|
this.parsePropertyName(node);
|
||||||
this.next();
|
return this.tsParsePropertyOrMethodSignature(node, readonly);
|
||||||
return this.match(tt.parenL) || this.isRelational("<");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tsParseTypeLiteral(): N.TsTypeLiteral {
|
tsParseTypeLiteral(): N.TsTypeLiteral {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user