From 06ca8b102609a77efb3d18f2e982ca670bb83dc6 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Thu, 24 Nov 2022 15:28:38 +0000 Subject: [PATCH] [playground] Refactor compilation of HIR Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react-forget/pull/825). * __->__ #825 [playground] Refactor compilation of HIR --- .../playground/components/Editor/Output.tsx | 167 +++++++++++------- 1 file changed, 102 insertions(+), 65 deletions(-) diff --git a/compiler/forget/packages/playground/components/Editor/Output.tsx b/compiler/forget/packages/playground/components/Editor/Output.tsx index 2530d77ccf..7dfa2542e5 100644 --- a/compiler/forget/packages/playground/components/Editor/Output.tsx +++ b/compiler/forget/packages/playground/components/Editor/Output.tsx @@ -10,7 +10,7 @@ import MonacoEditor from "@monaco-editor/react"; import { Diagnostic, HIR, OutputKind } from "babel-plugin-react-forget"; import prettier from "prettier"; import prettierParserBabel from "prettier/parser-babel"; -import { memo } from "react"; +import { memo, useMemo } from "react"; import type { Store } from "../../lib/stores"; import TabbedWindow from "../TabbedWindow"; import { monacoOptions } from "./monacoOptions"; @@ -36,14 +36,26 @@ type Props = { updateDiagnostics: (newDiags: Diagnostic[]) => void; }; -// TODO(gsn: Update diagnostics ƒrom HIR output -function Output({ store }: Props) { - const astFunctions = parseFunctions(store.source); - if (astFunctions.length === 0) { - return
; - } +type CompilerOutput = { + ssaOutput: string; + hirOutput: string; + eliminateRedundantPhiOutput: string; + inferReferenceEffectsOutput: string; + inferMutableRangesOutput: string; + leaveSSAOutput: string; + codegenOutput: string; + sourceMapUrl: string | null; +}; +type CompilerError = string; + +function compile(source: string): CompilerOutput | CompilerError { try { + const astFunctions = parseFunctions(source); + if (astFunctions.length === 0) { + return ""; + } + // TODO: Handle multiple functions const func = astFunctions[0]; const env = new Environment(); @@ -74,7 +86,7 @@ function Output({ store }: Props) { sourceMaps: true, sourceFileName: "input.js", }, - store.source + source ); const sourceMapUrl = getSourceMapUrl( generated.code, @@ -85,67 +97,92 @@ function Output({ store }: Props) { parser: "babel", plugins: [prettierParserBabel], }); - return ( - - ), - SSA: ( - - ), - EliminateRedundantPhi: ( - - ), - InferReferenceEffects: ( - - ), - InferMutableRanges: ( - - ), - LeaveSSA: ( - - ), - JS: , - SourceMap: ( - <> - {" "} - {sourceMapUrl && ( -