mirror of
https://github.com/morluto/rea
synced 2026-10-26 22:28:27 -04:00
9ac76d3d94
Index unshadowed direct-eval sites once at the semantic owner. Distinguish lexical rebinding, non-strict eval-introduced names, and possible mutation of reachable objects. Reuse existing effect timing and capture proofs; retain original definitions and module origins without inventing assignments or parsing or executing eval payloads. Query object uncertainty conservatively across the owning activation so aliases remain covered when names are shadowed or leave block scope. Retain no binding-by-eval table. Use the shared facts for values, read provenance, reference effects and child argument shapes. Preserve indirect/optional/shadowed eval controls, unrelated activations, immutable shapes, strict-mode bindings and prior primitive captures. Remove obsolete reference plumbing and the source-wide eval blocker. Validation: 306 focused checks across 16 files pass, including compiled CLI and stdio MCP return projections, constructor uncertainty and child-process consumers. Against the preceding SQLite commit, 9 of 23 selected checks fail and 14 controls pass. Static/docs/test discovery (1559 files) pass. Two source reviews found no remaining scoped blocker after alias and sloppy-name fixes. No analyzed JavaScript, SQLite engine, heavy test or profiler was executed. Conservative object reachability can intentionally lose exactness; large-case opaque-query CPU and memory remain unmeasured. Fixes #4875
51 lines
2.7 KiB
TypeScript
51 lines
2.7 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
|
|
|
it.each([
|
|
'class Database { constructor(name) { this.name = name; } } new Database("hello");',
|
|
'const Database = class {}; new Database("hello");',
|
|
'function Database(name) { return {name}; } new Database("hello");',
|
|
'class Local {} const Database = Local; new Database("hello");',
|
|
])("omits a proven local constructor: %s", (source) => {
|
|
expect(analyzeJavaScriptStaticSource(source).storage).toEqual([]);
|
|
});
|
|
|
|
it.each([
|
|
'new Database("shared");',
|
|
'import type Database = require("better-sqlite3"); new Database("shared");',
|
|
'let Database = require("better-sqlite3"); eval("Database = Other"); new Database("shared");',
|
|
'import * as sqlite from "sqlite3"; const alias = sqlite; alias.Database = Other; new sqlite.Database("shared");',
|
|
'import Database from "better-sqlite3"; expose(Database); new Database("shared");',
|
|
'import type TypeDatabase from "better-sqlite3"; const Database = TypeDatabase; new Database("shared");',
|
|
'import * as Database from "better-sqlite3"; new Database("shared");',
|
|
'const Database = require("better-sqlite3").default; new Database("shared");',
|
|
'const sqlite = require("sqlite3").default; new sqlite.Database("shared");',
|
|
'import type Database from "better-sqlite3"; new Database("shared");',
|
|
'import * as sqlite from "sqlite3"; new sqlite.default.default.Database("shared");',
|
|
'function run(Database) { return new Database("shared"); }',
|
|
'import Database from "unknown-library"; new Database("shared");',
|
|
'import Database from "better-sqlite3"; Database = Other; new Database("shared");',
|
|
'import * as sqlite from "sqlite3"; sqlite.Database = Other; new sqlite.Database("shared");',
|
|
])("retains uncertain SQLite names as candidates: %s", (source) => {
|
|
expect(analyzeJavaScriptStaticSource(source).storage).toMatchObject([
|
|
{ kind: "sqlite", name: "shared", interpretation: "candidate" },
|
|
]);
|
|
});
|
|
|
|
it.each([
|
|
'import Database from "better-sqlite3"; new Database("known.db");',
|
|
'import Database = require("better-sqlite3"); new Database("known.db");',
|
|
'import sqlite = require("sqlite3"); new sqlite.Database("known.db");',
|
|
'const Database = require("better-sqlite3"); new Database("known.db");',
|
|
'import {Database} from "sqlite3"; new Database("known.db");',
|
|
'import * as sqlite from "sqlite3"; new sqlite.Database("known.db");',
|
|
])("retains proven SQLite API origins: %s", (source) => {
|
|
const analysis = analyzeJavaScriptStaticSource(source);
|
|
expect(analysis.storage).toHaveLength(1);
|
|
expect(analysis.storage[0]).toMatchObject({
|
|
kind: "sqlite",
|
|
name: "known.db",
|
|
});
|
|
expect(analysis.storage[0]).not.toHaveProperty("interpretation");
|
|
});
|