diff --git a/compiler/forget/packages/playground/components/Editor/HIRTabContent.tsx b/compiler/forget/packages/playground/components/Editor/HIRTabContent.tsx index ef6f5d3d86..fcf8350b11 100644 --- a/compiler/forget/packages/playground/components/Editor/HIRTabContent.tsx +++ b/compiler/forget/packages/playground/components/Editor/HIRTabContent.tsx @@ -58,17 +58,43 @@ export default function HIRTabContent({ source }: { source: string }) { if (flags.leaveSSA) { leaveSSA(ir); } - 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};
+
+ if (flags.codegen) {
+ const ast = codegen(ir);
+ // TODO: codegen should set this correctly directly
+ ast.loc = func.node.loc;
+ const generated = generate(
+ ast,
+ {
+ sourceMaps: true,
+ sourceFileName: "input.js",
+ },
+ source
+ );
+ const formatted = prettier.format(generated.code, {
+ semi: true,
+ parser: "babel",
+ plugins: [prettierParserBabel],
+ });
+ const sourceMapUrl = getSourceMapUrl(
+ generated.code,
+ JSON.stringify(generated.map)
+ );
+ body = (
+ <>
+ {formatted}
+ {sourceMapUrl && (
+
+ )}
+ >
+ );
+ } else {
+ body = {printHIR(ir.body)};
+ }
} catch (e: any) {
body =