From bc08f057e3ee6c1176df9b8a7bfaf74de826a8f6 Mon Sep 17 00:00:00 2001 From: Alan Pierce Date: Sun, 25 Nov 2018 13:40:10 -0800 Subject: [PATCH] Fix infinite loop in flow `declare module` parsing (#359) --- src/parser/plugins/flow.ts | 2 ++ test/flow-test.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/parser/plugins/flow.ts b/src/parser/plugins/flow.ts index 03570e2e..03ee16c5 100644 --- a/src/parser/plugins/flow.ts +++ b/src/parser/plugins/flow.ts @@ -152,6 +152,8 @@ function flowParseDeclareModule(): void { if (match(tt._import)) { next(); parseImport(); + } else { + unexpected(); } } expect(tt.braceR); diff --git a/test/flow-test.ts b/test/flow-test.ts index 8e3bfcdc..b2b25d00 100644 --- a/test/flow-test.ts +++ b/test/flow-test.ts @@ -1,3 +1,5 @@ +import {throws} from "assert"; +import {transform} from "../src"; import {IMPORT_DEFAULT_PREFIX} from "./prefixes"; import {assertResult} from "./util"; @@ -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\)/, + ); + }); });