Files
scriptc/packages/compiler/test/native-class-array-boundaries.test.ts
T
Chris Tate 0d66098dda Support three.js meshes and materials in static builds
- Compile mesh construction, transforms, cloning, and material updates for native and WASI targets.
- Preserve subclass dispatch, fluent returns, and shared array identity in JavaScript packages.
- Support native class arrays and recursive conversions without materializing classes for type checks.
2026-09-29 23:32:14 -05:00

43 lines
1.6 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { expect, test } from "vitest";
import { compile } from "../src/index.js";
test("checked class arrays reject unbranded and differently branded elements", async () => {
const dir = mkdtempSync("/tmp/scriptc-class-arrays-");
try {
const entry = join(dir, "main.ts");
writeFileSync(entry, `
class Item { value = 1; }
class Other { value = 1; }
function check(input: unknown): void {
try { const items = input as Item[]; console.log('accepted', items.length); }
catch (error) { console.log('rejected', error instanceof TypeError); }
}
check([new Item()]);
check([new Other()]);
check([{value: 1}]);
const mixed: unknown[] = [];
mixed.push(new Item()); mixed.push({value: 1});
check(mixed);
check(null);
check([1]);
check([]);
`);
const result = await compile(entry, {
dynamic: false, outDir: dir, outPath: join(dir, "program"),
sanitize: process.env["SCRIPTC_SAN"] === "1",
});
if (!result.ok) throw new Error(JSON.stringify(result.diagnostics));
const child = spawnSync(result.binaryPath, [], {encoding: "utf8", timeout: 30_000});
expect(child.error).toBeUndefined();
expect({status: child.status, signal: child.signal, stdout: child.stdout, stderr: child.stderr}).toEqual({
status: 0, signal: null, stderr: "",
stdout: "accepted 1\nrejected true\nrejected true\nrejected true\nrejected true\nrejected true\naccepted 0\n",
});
} finally {
rmSync(dir, {recursive: true, force: true});
}
});