Typescript - Tuple elements can be optional (#8720)

This commit is contained in:
Retsam
2018-10-02 12:29:51 -04:00
committed by Brian Ng
parent 3c87401714
commit a5b5ed928d
21 changed files with 584 additions and 1 deletions

View File

@@ -503,13 +503,23 @@ export default (superClass: Class<Parser>): Class<Parser> =>
const node: N.TsTupleType = this.startNode();
node.elementTypes = this.tsParseBracketedList(
"TupleElementTypes",
this.tsParseType.bind(this),
this.tsParseTupleElementType.bind(this),
/* bracket */ true,
/* skipFirstToken */ false,
);
return this.finishNode(node, "TSTupleType");
}
tsParseTupleElementType(): N.TsType {
const type = this.tsParseType();
if (this.eat(tt.question)) {
const optionalTypeNode: N.TsOptionalType = this.startNodeAtNode(type);
optionalTypeNode.typeAnnotation = type;
return this.finishNode(optionalTypeNode, "TSOptionalType");
}
return type;
}
tsParseParenthesizedType(): N.TsParenthesizedType {
const node = this.startNode();
this.expect(tt.parenL);