Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from May 16, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -240,12 +240,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
} else if (this.match(tt._var)) {
return this.flowParseDeclareVariable(node);
} else if (this.isContextual("module")) {
if (this.lookahead().type === tt.dot) {
this.next();
danez marked this conversation as resolved.
Show resolved Hide resolved
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 +277,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 +421,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
flowParseDeclareModuleExports(
node: N.FlowDeclareModuleExports,
): N.FlowDeclareModuleExports {
this.expectContextual("module");
this.expect(tt.dot);
xtuc marked this conversation as resolved.
Show resolved Hide resolved
this.next();
this.expectContextual("exports");
node.typeAnnotation = this.flowParseTypeAnnotation();
this.semicolon();
Expand Down