Skip to content

Commit

Permalink
Fix infinite loop in flow declare module parsing (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangpierce authored Nov 25, 2018
1 parent 196f86e commit bc08f05
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser/plugins/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ function flowParseDeclareModule(): void {
if (match(tt._import)) {
next();
parseImport();
} else {
unexpected();
}
}
expect(tt.braceR);
Expand Down
17 changes: 17 additions & 0 deletions test/flow-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {throws} from "assert";
import {transform} from "../src";
import {IMPORT_DEFAULT_PREFIX} from "./prefixes";
import {assertResult} from "./util";

Expand Down Expand Up @@ -390,4 +392,19 @@ describe("transform flow", () => {
`,
);
});

it("does not infinite loop on declare module declarations", () => {
throws(
() =>
transform(
`
declare module 'ReactFeatureFlags' {
declare module.exports: any;
}
`,
{transforms: ["flow"]},
),
/SyntaxError: Unexpected token \(3:9\)/,
);
});
});

0 comments on commit bc08f05

Please sign in to comment.