(value: T): T => value; const view = {identity(3)}
;",
+ );
+ assertRunnable(code);
+ assert.match(code, /identity = \s*\(value\) => value/);
+});
+
+test("converts imports and exports to CommonJS for the frame shim", async () => {
+ const { code } = await compile(`
+ import React, { useState } from "react";
+ export default function App() { const [n] = useState(0); return {n}
; }
+ `);
+ assertRunnable(code);
+ assert.match(code, /require\(['"]react['"]\)/);
+ assert.match(code, /exports\.default = App/);
+ assert.doesNotMatch(code, /export default|/);
+});
+
+test("keeps unsupported package names in generated require calls", async () => {
+ const { code } = await compile(
+ 'import { motion } from "framer-motion"; export default () => ;',
+ );
+ assert.match(code, /require\(['"]framer-motion['"]\)/);
+});
+
+test("records fallback component declarations without choosing a mount target", async () => {
+ const result = await compile(`
+ function Helper() { return null; }
+ const Counter = () => ;
+ `);
+ assert.deepEqual(result.components, ["Helper", "Counter"]);
+});
+
+test("compiles a realistic stateful component end to end", async () => {
+ const result = await compile(`
+ import { useState } from "react";
+ interface Props { start: number }
+ export default function Counter({ start }: Props) {
+ const [n, setN] = useState(start);
+ return ;
+ }
+ `);
+ assertRunnable(result.code);
+ assert.match(result.code, /function Counter\(\{ start \}\)/);
+ assert.match(result.code, /useState\(start\)/);
+ assert.doesNotMatch(result.code, /interface|: Props||