From b7796b103a5f8682fa3f2728bfded409a830cd19 Mon Sep 17 00:00:00 2001 From: Ajay Ghanwat Date: Thu, 20 Aug 2026 00:51:21 +0530 Subject: [PATCH] fix(typecheck): drop legacy FunctionRuntime branches in contracts/index Fix round 1 for task 1: packages/typecheck also branched on the removed legacy runtime (componentContract's exclusion filter and the runtime-namespace loop). Removes both, adds a regression test. Co-Authored-By: Claude Opus 5 --- editors/vscode/src/language-server.cjs | 6 ++-- packages/typecheck/src/contracts.ts | 1 - packages/typecheck/src/index.ts | 2 +- .../test/legacy-runtime-removal.test.ts | 28 +++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 packages/typecheck/test/legacy-runtime-removal.test.ts diff --git a/editors/vscode/src/language-server.cjs b/editors/vscode/src/language-server.cjs index b22fa2ee..2d7835a4 100644 --- a/editors/vscode/src/language-server.cjs +++ b/editors/vscode/src/language-server.cjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -// WRN editor language server source hash: 047a3b701a20619b02c7dacecdb3af63e2989e1837abbc83c8b235981f694562 +// WRN editor language server source hash: 8f158f0d23d75de9b08a12cef6e20d2e5cdb48b6242db3b724634880277acd8c // WRN editor language server generator hash: f593a44aaf05495b789ce7a3086bee1eebb951b884d41c0e017bbcfe5f547e72 // @bun @bun-cjs (function(exports, require, module, __filename, __dirname) {var __create = Object.create; @@ -172681,7 +172681,7 @@ function componentContract(ast) { `); const outputs = ast.outputs.map((output) => ` ${safe(output.name)}(${output.payload ? `${output.payload.name}${output.payload.optional ? "?" : ""}: ${output.payload.valueType}` : ""}): void;`).join(` `); - const callable = ast.runtimeFunctions.filter((fn) => fn.runtime !== "legacy").map((fn) => ` ${safe(fn.name)}(${fn.parameters.map((param) => `${param.name}${param.optional ? "?" : ""}: ${param.valueType ?? "unknown"}`).join(", ")}): ${fn.returnType ?? (fn.async ? "Promise" : "unknown")};`).join(` + const callable = ast.runtimeFunctions.map((fn) => ` ${safe(fn.name)}(${fn.parameters.map((param) => `${param.name}${param.optional ? "?" : ""}: ${param.valueType ?? "unknown"}`).join(", ")}): ${fn.returnType ?? (fn.async ? "Promise" : "unknown")};`).join(` `); return `${typeSource ? `${typeSource} @@ -172960,7 +172960,7 @@ function virtualTypeScriptModule(source, filePath = "component.wrn", appRoot = f append(ast.kind === "global-store" || ast.kind === "page-store" ? storeContract(ast) : componentContract(ast)); append(importedWrnDeclarations(ast, filePath, appRoot)); const sharedNames = new Set(ast.runtimeFunctions.filter((fn) => fn.runtime === "shared").map((fn) => fn.name)); - for (const runtime of ["shared", "client", "server", "legacy"]) { + for (const runtime of ["shared", "client", "server"]) { const functions = ast.runtimeFunctions.filter((fn) => fn.runtime === runtime); if (!functions.length) continue; diff --git a/packages/typecheck/src/contracts.ts b/packages/typecheck/src/contracts.ts index 633cf45d..87ec7efe 100644 --- a/packages/typecheck/src/contracts.ts +++ b/packages/typecheck/src/contracts.ts @@ -22,7 +22,6 @@ export function componentContract(ast: PageAst): string { ) .join("\n"); const callable = ast.runtimeFunctions - .filter((fn) => fn.runtime !== "legacy") .map( (fn) => ` ${safe(fn.name)}(${fn.parameters.map((param) => `${param.name}${param.optional ? "?" : ""}: ${param.valueType ?? "unknown"}`).join(", ")}): ${fn.returnType ?? (fn.async ? "Promise" : "unknown")};`, diff --git a/packages/typecheck/src/index.ts b/packages/typecheck/src/index.ts index fdc6e00d..266524da 100644 --- a/packages/typecheck/src/index.ts +++ b/packages/typecheck/src/index.ts @@ -300,7 +300,7 @@ export function virtualTypeScriptModule( const sharedNames = new Set( ast.runtimeFunctions.filter((fn) => fn.runtime === "shared").map((fn) => fn.name), ); - for (const runtime of ["shared", "client", "server", "legacy"] as const) { + for (const runtime of ["shared", "client", "server"] as const) { const functions = ast.runtimeFunctions.filter((fn) => fn.runtime === runtime); if (!functions.length) continue; const localNames = new Set(functions.map((fn) => fn.name)); diff --git a/packages/typecheck/test/legacy-runtime-removal.test.ts b/packages/typecheck/test/legacy-runtime-removal.test.ts new file mode 100644 index 00000000..8f7490f5 --- /dev/null +++ b/packages/typecheck/test/legacy-runtime-removal.test.ts @@ -0,0 +1,28 @@ +import { expect, test } from "bun:test"; +import { parse } from "@wrnexus/syntax"; +import { componentContract, virtualTypeScriptModule } from "../src/index.ts"; + +const SOURCE = `component Probe { + functions { + function unmarkedHelper(): string { + return "both"; + } + } + view {
x
} +} +`; + +test("componentContract includes an unmarked function in the generated Functions interface", () => { + const ast = parse(SOURCE); + const contract = componentContract(ast); + + expect(contract).toContain("unmarkedHelper"); +}); + +test("generated declarations place an unmarked function in the shared namespace, not a legacy one", () => { + const module = virtualTypeScriptModule(SOURCE, "component.wrn"); + + expect(module.code).toContain("namespace __wrn_shared"); + expect(module.code).not.toContain("__wrn_legacy"); + expect(module.code).not.toContain('"legacy"'); +});