Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/check-driver-memory-census.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,7 @@ import { join, dirname, relative, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import { execFileSync } from 'node:child_process';
import ts from 'typescript';
import { parseSourceFile } from './ts-parse.mjs';

const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const LEDGER_PATH = join(ROOT, 'scripts', 'driver-memory-census.ledger.json');
Expand DownExpand Up@@ -229,7 +230,7 @@ function classify(node) {

/** Every occurrence of the specifier in one source text, classified. */
export function scanSource(fileName, text) {
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true);
const sf = parseSourceFile(fileName, text);
const found = [];
const visit = (node) => {
if ((ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) && namesPackage(node.text)) {
Expand Down
9 changes: 5 additions & 4 deletions scripts/check-durability-degradation-log-level.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -240,6 +240,7 @@ import { readFileSync, readdirSync, statSync, existsSync } from 'node:fs';
import { join, relative, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
import { parseSourceFile } from './ts-parse.mjs';

const ROOT = fileURLToPath(new URL('..', import.meta.url));
const BASELINE_PATH = join(ROOT, 'scripts', 'durability-degradation.baseline.json');
Expand DownExpand Up@@ -2441,7 +2442,7 @@ function runReadSeamRule({ list = false } = {}) {
for (const file of collectSourceFiles(join(ROOT, root))) {
const text = readFileSync(file, 'utf8');
if (!text.includes('catch')) continue;
const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
const sf = parseSourceFile(file, text, ts.ScriptKind.TS);
analyzeReadSeams(sf, relative(ROOT, file).split(sep).join('/'), findings, seams, {
usedDiscriminators,
});
Expand DownExpand Up@@ -2716,7 +2717,7 @@ function run({ list = false } = {}) {
for (const file of files) {
const text = readFileSync(file, 'utf8');
if (!text.includes('catch')) continue;
const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
const sf = parseSourceFile(file, text, ts.ScriptKind.TS);
analyzeSourceFile(sf, relative(ROOT, file).split(sep).join('/'), findings, seams, {
usedPropagationSites,
summaryBranches,
Expand DownExpand Up@@ -3815,7 +3816,7 @@ function selfTest() {

let failures = 0;
for (const c of cases) {
const sf = ts.createSourceFile('t.ts', c.code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
const sf = parseSourceFile('t.ts', c.code, ts.ScriptKind.TS);
const findings = [];
const seams = [];
const summaryBranches = [];
Expand DownExpand Up@@ -4481,7 +4482,7 @@ function selfTestReadSeams() {

let failures = 0;
for (const c of cases) {
const sf = ts.createSourceFile('t.ts', c.code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
const sf = parseSourceFile('t.ts', c.code, ts.ScriptKind.TS);
const findings = [];
const seams = [];
const usedDiscriminators = new Set();
Expand Down
19 changes: 10 additions & 9 deletions scripts/check-engine-double-contract.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -275,6 +275,7 @@ import { readFileSync, readdirSync, existsSync, writeFileSync } from 'node:fs';
import { join, dirname, relative, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
import { parseSourceFile } from './ts-parse.mjs';

const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const BASELINE_PATH = join(ROOT, 'scripts', 'engine-double-contract.baseline.json');
Expand DownExpand Up@@ -816,7 +817,7 @@ function localFunctions(sourceFile) {
* #5393 hit and #5480 removed the excuse for.
*/
function scanSource(fileName, text, slice = SLICES[0], opts = {}) {
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
const sf = parseSourceFile(fileName, text);
const pinnedNames = pinnedImportsOf(sf, slice);
const locals = localFunctions(sf);
const doubles = [];
Expand DownExpand Up@@ -960,7 +961,7 @@ function declaredBindings(sf) {
* construct left the population without any verdict being recorded.
*/
function censusSource(fileName, text, slice) {
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
const sf = parseSourceFile(fileName, text);
const declared = declaredBindings(sf);
const unrecognised = [];
const scopedOut = [];
Expand DownExpand Up@@ -1202,7 +1203,7 @@ function censusRecognizer() {
const rel = relative(ROOT, abs).split(sep).join('/');
const text = readFileSync(abs, 'utf8');
if (!/\b(delete|update)\s*[(:,}]/.test(text)) continue;
const sf = ts.createSourceFile(abs, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
const sf = parseSourceFile(abs, text);

const consider = (props) => {
for (const m of props) {
Expand DownExpand Up@@ -1802,7 +1803,7 @@ function envelopeImportsOf(sourceFile) {
* caller-supplied id, in a function that answers a receipt.
*/
function scanSeams(fileName, text) {
const sf = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
const sf = parseSourceFile(fileName, text, ts.ScriptKind.TS);
const envelopeNames = envelopeImportsOf(sf);
const localFns = localFunctions(sf);
const methodFns = classMethods(sf);
Expand DownExpand Up@@ -1949,7 +1950,7 @@ function declaredFunctionNames(sourceFile) {
function fileDeclaresFunction(file, fn) {
const abs = join(ROOT, file);
if (!existsSync(abs)) return false;
const sf = ts.createSourceFile(file, readFileSync(abs, 'utf8'), ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
const sf = parseSourceFile(file, readFileSync(abs, 'utf8'), ts.ScriptKind.TS);
return declaredFunctionNames(sf).has(fn);
}

Expand DownExpand Up@@ -3517,7 +3518,7 @@ ${body}
// (`scalarWhereIdOf` is where "scalar" means something) and this pins it
// where a mutation can reach it.
const whereIdOf = (src) => {
const f = ts.createSourceFile('t.ts', src, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
const f = parseSourceFile('t.ts', src, ts.ScriptKind.TS);
let lit = null;
const v = (n) => { if (!lit && ts.isObjectLiteralExpression(n) && propertyNamed(n, 'where')) lit = n; ts.forEachChild(n, v); };
v(f);
Expand DownExpand Up@@ -3929,7 +3930,7 @@ class Svc {
// a walker blind to one of them would classify that seam's loss as the
// quieter story — and the classifier would still look healthy.
const namesOf = (src) => declaredFunctionNames(
ts.createSourceFile('d.ts', src, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS));
parseSourceFile('d.ts', src, ts.ScriptKind.TS));
expect('declaredFunctionNames reads a top-level function declaration (`callData`s shape)',
namesOf('export async function callData(deps) { return 1; }').has('callData'));
expect('…an OBJECT LITERAL method (`protocol.updateData` / the MCP bridge’s shape)',
Expand DownExpand Up@@ -4053,7 +4054,7 @@ const engine: any = { registry: {}, insert: async (o: string, d: any) => d, find
// another would print a confident table and hide the same blind spot the
// constants did.
const kindsOf = (src) => {
const sf = ts.createSourceFile('k.test.ts', src, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
const sf = parseSourceFile('k.test.ts', src, ts.ScriptKind.TSX);
const out = [];
const visit = (n) => {
if (ts.isObjectLiteralExpression(n) || ts.isClassDeclaration(n)) {
Expand All@@ -4076,7 +4077,7 @@ const engine: any = { registry: {}, insert: async (o: string, d: any) => d, find
expect('#9943 — a method body is its own kind too', kindsOf('const e = { async update(o, d) {} };') === 'method body');

const assignSites = (src) => objectAssignSites(
ts.createSourceFile('a.test.ts', src, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX), SCANNED_VERBS,
parseSourceFile('a.test.ts', src, ts.ScriptKind.TSX), SCANNED_VERBS,
);
let sites = assignSites('const ql = Object.assign(makeQl(), { async find() { return []; }, async insert() { return null; } });');
expect('#8553 — an Object.assign override varying OTHER engine members reads as BASE-accounted '
Expand Down
3 changes: 2 additions & 1 deletion scripts/check-filter-alias-parity.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -87,6 +87,7 @@ import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
import { parseSourceFile } from './ts-parse.mjs';

const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..');

Expand All@@ -108,7 +109,7 @@ const FILTER_SLOT = 'where';
class UnreadableShape extends Error {}

function parse(path, text) {
return ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true);
return parseSourceFile(path, text);
}

/** Every node in a subtree, depth-first. */
Expand Down
5 changes: 3 additions & 2 deletions scripts/check-init-service-contract.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,6 +82,7 @@ import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join, relative, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
import { parseSourceFile } from './ts-parse.mjs';

const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..');

Expand DownExpand Up@@ -393,7 +394,7 @@ function scan(files = discoverFiles()) {
// would be filtered out here before the AST ever saw it, which is the same
// silent-hole failure this file's #4772 note is about.
if (!PREFILTER_TOKENS.some((token) => text.includes(token))) continue;
const src = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
const src = parseSourceFile(file, text);
for (const unit of collectPluginUnits(file, src)) {
units.push({ ...unit, initCalls: initServiceCalls(unit, src) });
}
Expand DownExpand Up@@ -501,7 +502,7 @@ function selfTest() {
const assert = (cond, msg) => { if (!cond) { console.error('✗ self-test: ' + msg); process.exit(1); } };

const auditSource = (code) => {
const src = ts.createSourceFile('fixture.ts', code, ts.ScriptTarget.Latest, true);
const src = parseSourceFile('fixture.ts', code);
const units = collectPluginUnits('fixture.ts', src).map((u) => ({ ...u, initCalls: initServiceCalls(u, src) }));
return auditUnits(units);
};
Expand Down
3 changes: 2 additions & 1 deletion scripts/check-kernel-hook-pairs.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@ import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join, relative, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
import { parseSourceFile } from './ts-parse.mjs';
import { isEntrypoint } from './invoked-as.mjs';

const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..');
Expand DownExpand Up@@ -104,7 +105,7 @@ const HOOK_NAME = /^kernel:[A-Za-z][A-Za-z0-9_:-]*$/;
// ── Scanning ─────────────────────────────────────────────────────────────────

function parse(fileName, source) {
return ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
return parseSourceFile(fileName, source, ts.ScriptKind.TS);
}

/** The identifier a call expression ends in: `a.b.c(x)` → `c`, `c(x)` → `c`. */
Expand Down
5 changes: 3 additions & 2 deletions scripts/check-meta-type-normalized.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,6 +82,7 @@ import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join, relative, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
import { parseSourceFile } from './ts-parse.mjs';

const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..');

Expand DownExpand Up@@ -145,7 +146,7 @@ function walkFiles(dir, out) {
/** Every raw-param decision site in one file. */
function findViolations(file) {
const text = readFileSync(file, 'utf8');
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
const source = parseSourceFile(file, text);
const found = [];

const record = (node, kind) => {
Expand DownExpand Up@@ -198,7 +199,7 @@ function selfTest() {
const ok2 = RestServer.metaTypeSingular(req.params.type) === 'book';
const ok3 = metaType === 'doc';
`;
const source = ts.createSourceFile('fixture.ts', fixture, ts.ScriptTarget.Latest, true);
const source = parseSourceFile('fixture.ts', fixture);
const hits = [];
const visit = (node) => {
if (ts.isBinaryExpression(node) && COMPARISON_OPS.has(node.operatorToken.kind)
Expand Down
3 changes: 2 additions & 1 deletion scripts/check-org-identifier.mjs
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,6 +269,7 @@ import { execFileSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import ts from 'typescript';
import { parseSourceFile } from './ts-parse.mjs';
import { maskComments } from './js-comment-mask.mjs';

const ROOTS = ['examples', 'apps', 'packages'];
Expand DownExpand Up@@ -499,7 +500,7 @@ function parse(text, file) {
// `scriptKind` left to the parser so `.tsx` / `.jsx` / `.mjs` are inferred
// from the name. The parser is error-tolerant: a file it cannot fully parse
// still yields the nodes around the failure rather than throwing.
return ts.createSourceFile(file, text, ts.ScriptTarget.Latest, /* setParentNodes */ true);
return parseSourceFile(file, text);
}

// ── the gate ──────────────────────────────────────────────────────────────
Expand Down
Loading
Loading