[babel] Add flow support

Check if there's a pragma to toggle flow parsing
This commit is contained in:
Sathya Gunasekaran
2023-01-24 10:21:25 -05:00
parent 19dd29707b
commit 9aed0fc6b1
2 changed files with 13 additions and 3 deletions
@@ -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, {
+10 -1
View File
@@ -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<TestOutput> = [];
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;
}