diff --git a/compiler/forget/packages/playground/components/Editor/HIRTabContent.tsx b/compiler/forget/packages/playground/components/Editor/HIRTabContent.tsx index e164fde0e4..ef6f5d3d86 100644 --- a/compiler/forget/packages/playground/components/Editor/HIRTabContent.tsx +++ b/compiler/forget/packages/playground/components/Editor/HIRTabContent.tsx @@ -9,6 +9,9 @@ import clsx from "clsx"; import { HIR } from "babel-plugin-react-forget"; import { useState } from "react"; +import generate from "@babel/generator"; +import prettier from "prettier"; +import prettierParserBabel from "prettier/parser-babel"; const { parseFunctions, @@ -20,12 +23,14 @@ const { leaveSSA, lower, printHIR, + codegen, } = HIR; export default function HIRTabContent({ source }: { source: string }) { const astFunctions = parseFunctions(source); const [flags, setFlags] = useState({ + codegen: true, eliminateRedundantPhi: true, inferReferenceEffects: true, inferMutableRanges: true, @@ -53,8 +58,17 @@ export default function HIRTabContent({ source }: { source: string }) { if (flags.leaveSSA) { leaveSSA(ir); } - const textHIR = printHIR(ir.body); - body =
{textHIR};
+ const output = flags.codegen
+ ? prettier.format(
+ generate(codegen(ir)).code.replace("\n\n", "\n"),
+ {
+ semi: true,
+ parser: "babel",
+ plugins: [prettierParserBabel],
+ }
+ )
+ : printHIR(ir.body);
+ body = {output};
} catch (e: any) {
body =