Support parsing Flow's Indexed Access Types (#13053)

This commit is contained in:
Sosuke Suzuki
2021-04-07 18:15:46 +09:00
committed by Nicolò Ribaudo
parent eac0259ce2
commit f8aa32f767
15 changed files with 324 additions and 3 deletions

View File

@@ -1623,10 +1623,20 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let type = this.flowParsePrimaryType();
while (this.match(tt.bracketL) && !this.canInsertSemicolon()) {
const node = this.startNodeAt(startPos, startLoc);
node.elementType = type;
this.expect(tt.bracketL);
this.expect(tt.bracketR);
type = this.finishNode(node, "ArrayTypeAnnotation");
if (this.match(tt.bracketR)) {
node.elementType = type;
this.next(); // eat `]`
type = this.finishNode(node, "ArrayTypeAnnotation");
} else {
node.objectType = type;
node.indexType = this.flowParseType();
this.expect(tt.bracketR);
type = this.finishNode<N.FlowIndexedAccessType>(
node,
"IndexedAccessType",
);
}
}
return type;
}