Typescript function destructured params (#9431)

* fix typescript funtion destructured params for array

* update type name
This commit is contained in:
Downpooooour
2019-02-08 05:59:50 +08:00
committed by Nicolò Ribaudo
parent fdb65ab8b1
commit d1514f57bd
4 changed files with 173 additions and 10 deletions

View File

@@ -342,17 +342,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
tsParseBindingListForSignature(): $ReadOnlyArray<
N.Identifier | N.RestElement | N.ObjectPattern,
N.Identifier | N.RestElement | N.ObjectPattern | N.ArrayPattern,
> {
return this.parseBindingList(tt.parenR).map(pattern => {
if (
pattern.type !== "Identifier" &&
pattern.type !== "RestElement" &&
pattern.type !== "ObjectPattern"
pattern.type !== "ObjectPattern" &&
pattern.type !== "ArrayPattern"
) {
throw this.unexpected(
pattern.start,
`Name in a signature must be an Identifier or ObjectPattern, instead got ${
`Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${
pattern.type
}`,
);
@@ -794,6 +795,21 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return true;
}
if (this.match(tt.bracketL)) {
let braceStackCounter = 1;
this.next();
while (braceStackCounter > 0) {
if (this.match(tt.bracketL)) {
++braceStackCounter;
} else if (this.match(tt.bracketR)) {
--braceStackCounter;
}
this.next();
}
return true;
}
return false;
}

View File

@@ -1076,7 +1076,9 @@ export type TsSignatureDeclaration =
export type TsSignatureDeclarationOrIndexSignatureBase = NodeBase & {
// Not using TypeScript's "ParameterDeclaration" here, since it's inconsistent with regular functions.
parameters: $ReadOnlyArray<Identifier | RestElement | ObjectPattern>,
parameters: $ReadOnlyArray<
Identifier | RestElement | ObjectPattern | ArrayPattern,
>,
typeAnnotation: ?TsTypeAnnotation,
};