24 lines
1.0 KiB
TypeScript
24 lines
1.0 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { analyzeOptimizations, generate, optimizeAst, parse } from "../src/index.ts";
|
|
|
|
test("compiler folds literal branches and reports optimization opportunities", () => {
|
|
const ast = parse(`component Optimized {
|
|
props { title: string = "Hello" }
|
|
state count = 0
|
|
state unused = 1
|
|
functions {
|
|
client function increment(): void { count++ }
|
|
client function orphan(): void { unused++ }
|
|
}
|
|
style { .used { color: red } .unused-css { color: blue } }
|
|
view { <section class="used"><h1>{title}</h1>{#if false}<p>dead</p>{:else}<button @click="increment">{count}</button>{/if}</section> }
|
|
}`);
|
|
const report = analyzeOptimizations(ast);
|
|
expect(report.eliminatedBranches).toBeGreaterThan(0);
|
|
expect(report.unusedHandlers).toContain("orphan");
|
|
expect(report.unusedLocalCssClasses).toContain("unused-css");
|
|
expect(report.constantProps).toContain("title");
|
|
expect(optimizeAst(ast).ast.view).not.toEqual(ast.view);
|
|
expect(generate(ast)).not.toContain("dead");
|
|
});
|