diff --git a/compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts b/compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts index 365f94a78d..6dd0b482dd 100644 --- a/compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts +++ b/compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts @@ -13,11 +13,12 @@ type ReactForgetBabelPluginResult = { export default function runReactForgetBabelPlugin( text: string, - file: string + file: string, + language: "flow" | "typescript" ): ReactForgetBabelPluginResult { const ast = parser.parse(text, { sourceFilename: file, - plugins: ["typescript", "jsx"], + plugins: ["jsx", language], sourceType: "module", }); const result = transformFromAstSync(ast, text, { diff --git a/compiler/forget/src/__tests__/hir-test.ts b/compiler/forget/src/__tests__/hir-test.ts index edb56c6136..9880e80b44 100644 --- a/compiler/forget/src/__tests__/hir-test.ts +++ b/compiler/forget/src/__tests__/hir-test.ts @@ -28,6 +28,7 @@ wasmFolder( ); const Pragma_RE = /\/\/\s*@enable\((\w+)\)$/gm; +const FlowPragmas = [/\/\/\s@flow$/gm, /\*\s@flow$/gm]; describe("React Forget (HIR version)", () => { generateTestsFromFixtures( @@ -46,13 +47,21 @@ describe("React Forget (HIR version)", () => { } } + let useFlow: boolean = false; + for (const flowPragma of FlowPragmas) { + useFlow ||= !!input.match(flowPragma); + } + + let language: "flow" | "typescript" = useFlow ? "flow" : "typescript"; let items: Array = []; let error: Error | null = null; if (options.debug) { toggleLogging(options.debug); } try { - items.push({ js: runReactForgetBabelPlugin(input, file).code }); + items.push({ + js: runReactForgetBabelPlugin(input, file, language).code, + }); } catch (e) { error = e; }