Do not use lookahead when parsing imports in declare module in flow (#9987)

This commit is contained in:
Daniel Tschinder 2019-05-16 02:31:37 -07:00 committed by GitHub
parent c2d303f8be
commit 5661de5908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -291,14 +291,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let bodyNode = this.startNode(); let bodyNode = this.startNode();
if (this.match(tt._import)) { if (this.match(tt._import)) {
const lookahead = this.lookahead(); this.next();
if (lookahead.value !== "type" && lookahead.value !== "typeof") { if (!this.isContextual("type") && !this.isContextual("typeof")) {
this.unexpected( this.unexpected(
null, this.state.lastTokStart,
"Imports within a `declare module` body must always be `import type` or `import typeof`", "Imports within a `declare module` body must always be `import type` or `import typeof`",
); );
} }
this.next();
this.parseImport(bodyNode); this.parseImport(bodyNode);
} else { } else {
this.expectContextual( this.expectContextual(