mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
- Enforce oxlint and oxfmt for owned JavaScript and TypeScript with independent CI checks. - Preserve compiler import boundaries and protected fixtures while cleaning up lint findings. - Standardize source formatting and validate import, fixture, and embedded-source protections.
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { expect, test } from "vitest";
|
|
import { compile } from "../src/index.js";
|
|
|
|
test("native deep equality keeps opaque values and accessors explicitly refused", async () => {
|
|
const dir = mkdtempSync(join(tmpdir(), "scriptc-deep-equality-"));
|
|
try {
|
|
const entry = join(dir, "main.cjs");
|
|
writeFileSync(
|
|
entry,
|
|
`
|
|
const { isDeepStrictEqual: equal } = require("node:util");
|
|
function attempt(a, b) {
|
|
try { console.log(equal(a, b)); }
|
|
catch (error) { console.log(error.name, error.code, error.message); }
|
|
}
|
|
class Value { value = 1; }
|
|
attempt(new Value(), new Value());
|
|
attempt(new Map([[1, 2]]), new Map([[1, 2]]));
|
|
attempt(new Set([1]), new Set([1]));
|
|
attempt(new Error("fail"), new Error("fail"));
|
|
attempt({ get value() { return 1; } }, { value: 1 });
|
|
const ctor = () => 1;
|
|
attempt({ constructor: ctor }, { constructor: ctor });
|
|
console.log("after");
|
|
`,
|
|
);
|
|
const result = await compile(entry, {
|
|
dynamic: false,
|
|
sanitize: process.env["SCRIPTC_SAN"] === "1",
|
|
outDir: dir,
|
|
outPath: join(dir, "program"),
|
|
});
|
|
expect(result.ok, JSON.stringify(result.diagnostics)).toBe(true);
|
|
if (!result.ok) return;
|
|
const child = spawnSync(result.binaryPath, [], { encoding: "utf8" });
|
|
expect(child.status, child.stdout + child.stderr).toBe(0);
|
|
expect(child.stderr).toBe("");
|
|
expect(child.stdout).toBe(
|
|
"TypeError SC2020 util.isDeepStrictEqual over opaque native references is not supported yet\n" +
|
|
"TypeError SC2020 util.isDeepStrictEqual over native handles is not supported yet\n" +
|
|
"TypeError SC2020 util.isDeepStrictEqual over native handles is not supported yet\n" +
|
|
"TypeError SC2020 util.isDeepStrictEqual over native Error values is not supported yet\n" +
|
|
"TypeError SC2020 util.isDeepStrictEqual over native accessor properties is not supported yet\n" +
|
|
"TypeError SC2020 util.isDeepStrictEqual over native own constructor functions is not supported yet\nafter\n",
|
|
);
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|