refactor(javascript): group domain semantics and contracts (#907)

This commit is contained in:
ysopwnable authored and GitHub committed 2026-10-07 17:16:58 +08:00
1 parent d5f28fb29c
commit f6a58f1062
253 files changed
+432 -410

No files matched your search

@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
describe("JavaScript static analysis findings", () => {
it("does not infer a webpack push from a dynamic computed key", () => {
const analysis = analyzeJavaScriptStaticSource(`
const push = "push";
const arr = {};
arr[push]([[1], { 1: function () {} }]);
`);
expect(analysis.bundler_registrations).toEqual([]);
});
it("retains every static reference and Electron property in large literals", () => {
const names = Array.from({ length: 10_001 }, (_, index) => `key${index}`);
const source = [
...names.map(
(name, index) => `import value${index} from "./${name}.js";`,
),
`new BrowserWindow({ webPreferences: { ${names.map((name) => `${name}: true`).join(", ")} } });`,
`contextBridge.exposeInMainWorld("api", { ${names.map((name) => `${name}: () => true`).join(", ")} });`,
`const { ${names.join(", ")} } = require("./addon.node");`,
].join("\n");
const analysis = analyzeJavaScriptStaticSource(source);
expect(analysis.parse_status).toBe("complete");
expect(analysis.references).toHaveLength(10_002);
expect(analysis.electron.browser_windows[0]?.web_preferences).toHaveLength(
10_001,
);
expect(analysis.electron.context_bridge_apis[0]?.members).toHaveLength(
10_001,
);
expect(analysis.electron.native_addon_bindings[0]?.members).toHaveLength(
10_001,
);
});
});