Fix parsing typescript function types with destructuring (#9035)

* Fix parsing typescript function types with destructuring

* Use integer instead of actual stack
This commit is contained in:
Daniel Tschinder
2018-11-19 13:55:58 -08:00
committed by GitHub
parent c11cdcb6d8
commit a2afb974be
4 changed files with 243 additions and 4 deletions

View File

@@ -314,13 +314,19 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
tsParseBindingListForSignature(): $ReadOnlyArray<
N.Identifier | N.RestElement,
N.Identifier | N.RestElement | N.ObjectPattern,
> {
return this.parseBindingList(tt.parenR).map(pattern => {
if (pattern.type !== "Identifier" && pattern.type !== "RestElement") {
if (
pattern.type !== "Identifier" &&
pattern.type !== "RestElement" &&
pattern.type !== "ObjectPattern"
) {
throw this.unexpected(
pattern.start,
"Name in a signature must be an Identifier.",
`Name in a signature must be an Identifier or ObjectPattern, instead got ${
pattern.type
}`,
);
}
return pattern;
@@ -747,6 +753,22 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.next();
return true;
}
if (this.match(tt.braceL)) {
let braceStackCounter = 1;
this.next();
while (braceStackCounter > 0) {
if (this.match(tt.braceL)) {
++braceStackCounter;
} else if (this.match(tt.braceR)) {
--braceStackCounter;
}
this.next();
}
return true;
}
return false;
}