Skip to content

Commit

Permalink
Do not use lookahead when parsing declare module or declare module.ex…
Browse files Browse the repository at this point in the history
…ports in flow (#9985)

* Do not use lookahead when parsing declare module or declare module.exports in flow

* Improve code
  • Loading branch information
danez committed May 16, 2019
1 parent 4da7a01 commit c2d303f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -239,13 +239,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.flowParseDeclareFunction(node);
} else if (this.match(tt._var)) {
return this.flowParseDeclareVariable(node);
} else if (this.isContextual("module")) {
if (this.lookahead().type === tt.dot) {
} else if (this.eatContextual("module")) {
if (this.match(tt.dot)) {
return this.flowParseDeclareModuleExports(node);
} else {
if (insideModule) {
this.unexpected(
null,
this.state.lastTokStart,
"`declare module` cannot be used inside another `declare module`",
);
}
Expand Down Expand Up @@ -276,8 +276,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

flowParseDeclareModule(node: N.FlowDeclareModule): N.FlowDeclareModule {
this.next();

this.scope.enter(SCOPE_OTHER);

if (this.match(tt.string)) {
Expand Down Expand Up @@ -422,8 +420,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
flowParseDeclareModuleExports(
node: N.FlowDeclareModuleExports,
): N.FlowDeclareModuleExports {
this.expectContextual("module");
this.expect(tt.dot);
this.next();
this.expectContextual("exports");
node.typeAnnotation = this.flowParseTypeAnnotation();
this.semicolon();
Expand Down

0 comments on commit c2d303f

Please sign in to comment.