From 50560e169ca39c0b4ec163cb32897baf7620aa69 Mon Sep 17 00:00:00 2001
From: Jarred Sumner <jarred@jarredsumner.com>
Date: Sun, 27 Feb 2022 23:20:10 -0800
Subject: WASM

---
 src/api/demo/pages/index.tsx | 105 ++++++++++++++++++++++---------------------
 1 file changed, 53 insertions(+), 52 deletions(-)

(limited to 'src/api/demo/pages/index.tsx')

diff --git a/src/api/demo/pages/index.tsx b/src/api/demo/pages/index.tsx
index 4d60b4084..7274b3d39 100644
--- a/src/api/demo/pages/index.tsx
+++ b/src/api/demo/pages/index.tsx
@@ -1,70 +1,71 @@
 import Head from "next/head";
 import Image from "next/image";
 import styles from "../styles/Home.module.css";
-import "../lib/api.ts";
 
-export default function Home() {
+import React from "react";
+
+if (typeof window !== "undefined") {
+  globalThis.Run = await import("../lib/run");
+  await import("../lib/api.ts");
+}
+
+export async function getStaticProps(ctx) {
+  return {
+    props: {
+      code: Bun.readFile(
+        "/Users/jarred/Build/es-module-lexer/test/samples/magic-string.js"
+      ),
+    },
+  };
+}
+
+var textDecoder = new TextDecoder();
+export default function Home({ code }) {
+  const fileNameRef = React.useRef();
+  const [esbuildResult, setEsbuildResult] = React.useState("");
+  const [bunResult, setBunResult] = React.useState("");
+  const [swcResult, setSWCResult] = React.useState("");
+  React.useEffect(() => {
+    globalThis.Run.start();
+  }, []);
+
+  const runBuild = React.useCallback(
+    (event) => {
+      globalThis.Run.transform(
+        event.target.value,
+        fileNameRef.current.value
+      ).then((result) => {
+        setEsbuildResult(result.esbuild.code);
+        setBunResult(textDecoder.decode(result.bun.files[0].data));
+        setSWCResult(result.swc.code);
+      }, console.error);
+    },
+    [fileNameRef, setEsbuildResult, setBunResult, setSWCResult]
+  );
   return (
     <div className={styles.container}>
       <Head>
-        <title>Create Next App</title>
+        <title>Next.js</title>
         <meta name="description" content="Generated by create next app" />
         <link rel="icon" href="/favicon.ico" />
       </Head>
 
       <main className={styles.main}>
-        <h1 className={styles.title}>
-          Welcome to <a href="https://nextjs.org">Next.js!</a>
-        </h1>
-
-        <p className={styles.description}>
-          Get started by editing{" "}
-          <code className={styles.code}>pages/index.js</code>
-        </p>
-
-        <div className={styles.grid}>
-          <a href="https://nextjs.org/docs" className={styles.card}>
-            <h2>Documentation &rarr;</h2>
-            <p>Find in-depth information about Next.js features and API.</p>
-          </a>
+        <div>
+          <input
+            autoComplete="filename"
+            type="text"
+            placeholder="filename"
+            defaultValue="input.tsx"
+            ref={fileNameRef}
+          />
+          <textarea onChange={runBuild} defaultValue={code}></textarea>
 
-          <a href="https://nextjs.org/learn" className={styles.card}>
-            <h2>Learn &rarr;</h2>
-            <p>Learn about Next.js in an interactive course with quizzes!</p>
-          </a>
-
-          <a
-            href="https://github.com/vercel/next.js/tree/master/examples"
-            className={styles.card}
-          >
-            <h2>Examples &rarr;</h2>
-            <p>Discover and deploy boilerplate example Next.js projects.</p>
-          </a>
-
-          <a
-            href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
-            className={styles.card}
-          >
-            <h2>Deploy &rarr;</h2>
-            <p>
-              Instantly deploy your Next.js site to a public URL with Vercel.
-            </p>
-          </a>
+          <textarea readOnly value={esbuildResult}></textarea>
+          <textarea readOnly value={bunResult}></textarea>
+          <textarea readOnly value={swcResult}></textarea>
         </div>
       </main>
-
-      <footer className={styles.footer}>
-        <a
-          href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
-          target="_blank"
-          rel="noopener noreferrer"
-        >
-          Powered by{" "}
-          <span className={styles.logo}>
-            <Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
-          </span>
-        </a>
-      </footer>
     </div>
   );
 }
-- 
cgit v1.2.3

