From 43686787a0b9f62d896037485a2d7e8d9601fccf Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Mon, 21 Nov 2022 13:19:36 -0500 Subject: [PATCH] [playground] add link to view sourcemap (#798) --- .../components/Editor/HIRTabContent.tsx | 60 +++++++++++++++---- 1 file changed, 49 insertions(+), 11 deletions(-) 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 && ( +