fix: compile typed catches and reject event loop syntax
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { diagnose, parse } from "../src/index.ts";
|
||||
import { diagnose, eraseFunctionTypes, parse } from "../src/index.ts";
|
||||
|
||||
const source = `import type { PublicUser } from "@/types/user.ts"
|
||||
import PublicLayout from "@/layouts/PublicLayout.wrn"
|
||||
@@ -118,3 +118,20 @@ test("readonly prop diagnostics still reject direct prop assignments", () => {
|
||||
}`);
|
||||
expect(diagnostics.some((diagnostic) => diagnostic.code === "WRN-PROP-READONLY")).toBe(true);
|
||||
});
|
||||
|
||||
test("browser type erasure removes typed catch bindings", () => {
|
||||
const source = `async function load(): Promise<void> {
|
||||
try { await fetch("/api") } catch (error: any) { console.error(error) }
|
||||
}`;
|
||||
expect(eraseFunctionTypes(source)).toContain("catch (error)");
|
||||
expect(eraseFunctionTypes(source)).not.toContain(": any");
|
||||
});
|
||||
|
||||
test("diagnoses event syntax mistakenly used for loop directives", () => {
|
||||
const diagnostics = diagnose(`component Rows {
|
||||
view { <ul><li @for="row in rows" @key="row.id">{row.name}</li></ul> }
|
||||
}`);
|
||||
expect(diagnostics.filter((entry) => entry.code === "WRN-TEMPLATE-LOOP-DIRECTIVE")).toHaveLength(
|
||||
2,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user