docattest 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/agents/claude.json +30 -0
- package/dist/agents/cursor.json +19 -0
- package/dist/agents/gemini.json +27 -0
- package/dist/agents/index.json +3 -0
- package/dist/api/adapter.d.ts +231 -0
- package/dist/api/adapter.js +2 -0
- package/dist/api/attestation.d.ts +76 -0
- package/dist/api/attestation.js +2 -0
- package/dist/api/audit.d.ts +56 -0
- package/dist/api/audit.js +2 -0
- package/dist/api/config.d.ts +44 -0
- package/dist/api/config.js +2 -0
- package/dist/api/constants.d.ts +35 -0
- package/dist/api/constants.js +56 -0
- package/dist/api/errors.d.ts +15 -0
- package/dist/api/errors.js +22 -0
- package/dist/api/impact.d.ts +49 -0
- package/dist/api/impact.js +2 -0
- package/dist/api/project.d.ts +64 -0
- package/dist/api/project.js +2 -0
- package/dist/api/report.d.ts +107 -0
- package/dist/api/report.js +2 -0
- package/dist/client/answers.d.ts +17 -0
- package/dist/client/answers.js +23 -0
- package/dist/client/core.d.ts +18 -0
- package/dist/client/core.js +58 -0
- package/dist/client/place.d.ts +14 -0
- package/dist/client/place.js +37 -0
- package/dist/client/project.d.ts +3 -0
- package/dist/client/project.js +98 -0
- package/dist/client/workspace.d.ts +12 -0
- package/dist/client/workspace.js +72 -0
- package/dist/compare-strings.d.ts +2 -0
- package/dist/compare-strings.js +5 -0
- package/dist/core-binary/locate.js +113 -0
- package/dist/core-binary/package.js +70 -0
- package/dist/core.json +4 -0
- package/dist/files/disk.d.ts +4 -0
- package/dist/files/disk.js +67 -0
- package/dist/files/glob.d.ts +10 -0
- package/dist/files/glob.js +21 -0
- package/dist/files/ignored.d.ts +14 -0
- package/dist/files/ignored.js +14 -0
- package/dist/files/memory.d.ts +5 -0
- package/dist/files/memory.js +26 -0
- package/dist/files/source.d.ts +22 -0
- package/dist/files/source.js +17 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +6 -0
- package/dist/json.d.ts +16 -0
- package/dist/json.js +43 -0
- package/dist/language/cache.js +18 -0
- package/dist/language/citations/listing.js +64 -0
- package/dist/language/citations/match.js +14 -0
- package/dist/language/citations/tests-in-file.js +101 -0
- package/dist/language/compiler.js +73 -0
- package/dist/language/description.js +24 -0
- package/dist/language/impact/affected.js +50 -0
- package/dist/language/impact/fingerprint.js +123 -0
- package/dist/language/impact/graph.js +72 -0
- package/dist/language/impact/lookup.js +100 -0
- package/dist/language/impact/program.js +87 -0
- package/dist/language/impact/renames.js +57 -0
- package/dist/language/impact/revision.js +62 -0
- package/dist/language/impact/units.js +80 -0
- package/dist/language/index.js +10 -0
- package/dist/language/inventory/observables.js +56 -0
- package/dist/language/inventory/plan.js +72 -0
- package/dist/language/inventory/probe.js +150 -0
- package/dist/language/languages.js +43 -0
- package/dist/language/node/dependency.js +34 -0
- package/dist/language/node/exports-map.js +92 -0
- package/dist/language/program/exports.js +29 -0
- package/dist/language/program/file-names.js +13 -0
- package/dist/language/program/globals.js +38 -0
- package/dist/language/program/host.js +91 -0
- package/dist/language/program/options.js +48 -0
- package/dist/language/program/program.js +41 -0
- package/dist/language/run/attempt.js +100 -0
- package/dist/language/run/facts.js +109 -0
- package/dist/language/run/host.js +73 -0
- package/dist/language/run/jobs.js +37 -0
- package/dist/language/run/pool.js +75 -0
- package/dist/language/run/protocol.js +37 -0
- package/dist/language/run/result.js +18 -0
- package/dist/language/run/runner.js +115 -0
- package/dist/language/run/sourcemap.js +43 -0
- package/dist/language/run/spawn.js +40 -0
- package/dist/language/run/transpile.js +50 -0
- package/dist/language/session.js +42 -0
- package/dist/language/surfaces/packages.js +71 -0
- package/dist/language/surfaces/resolve.js +48 -0
- package/dist/language/surfaces/specs.js +32 -0
- package/dist/language/surfaces/stale.js +23 -0
- package/dist/language/symbols.js +95 -0
- package/dist/language/syntax/doc-comments.js +90 -0
- package/dist/language/syntax/doc-prose.js +23 -0
- package/dist/language/syntax/expression.js +52 -0
- package/dist/language/syntax/imports.js +83 -0
- package/dist/language/syntax/lexical.js +41 -0
- package/dist/language/syntax/parse.js +11 -0
- package/dist/language/syntax/prose.js +11 -0
- package/dist/language/syntax/setup-module.js +88 -0
- package/dist/language/ts.cjs +9 -0
- package/dist/language/worker/cases.js +73 -0
- package/dist/language/worker/compile.js +15 -0
- package/dist/language/worker/console.js +10 -0
- package/dist/language/worker/context.js +16 -0
- package/dist/language/worker/describe.js +107 -0
- package/dist/language/worker/example.js +27 -0
- package/dist/language/worker/facts.js +69 -0
- package/dist/language/worker/host-client.js +55 -0
- package/dist/language/worker/main.js +71 -0
- package/dist/language/worker/network.js +35 -0
- package/dist/language/worker/observe.js +39 -0
- package/dist/language/worker/registry.js +78 -0
- package/dist/language/worker/setup-facts.js +50 -0
- package/dist/language/worker/strays.js +37 -0
- package/dist/launcher/main.js +38 -0
- package/dist/platforms.json +40 -0
- package/dist/protocol/context.js +48 -0
- package/dist/protocol/main.js +22 -0
- package/dist/protocol/methods.js +178 -0
- package/dist/protocol/output.js +40 -0
- package/dist/protocol/overlay.js +31 -0
- package/dist/protocol/serve.js +24 -0
- package/dist/protocol/server.js +108 -0
- package/dist/protocol/wire.js +117 -0
- package/dist/schema/agent.json +162 -0
- package/dist/schema/attestations.json +307 -0
- package/dist/schema/kit.json +190 -0
- package/dist/schema/language.json +162 -0
- package/dist/schema/messages.json +68 -0
- package/dist/schema/methods.json +412 -0
- package/dist/schema/project.json +113 -0
- package/dist/schema/results.json +249 -0
- package/package.json +73 -4
package/dist/json.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { messageOf, UserError } from './api/errors.js';
|
|
2
|
+
/** Whether a value is a plain object: not an array, not null. */
|
|
3
|
+
export function isObject(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/** Whether a value is an array of strings. */
|
|
7
|
+
export function isStringArray(value) {
|
|
8
|
+
return Array.isArray(value) && value.every((v) => typeof v === 'string');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The object `text` holds, or undefined when there is no text, it is not JSON or it is not an
|
|
12
|
+
* object. Only for files that are not the user's to fix: a dependency's manifest, a map.
|
|
13
|
+
*/
|
|
14
|
+
export function objectOrNothing(text) {
|
|
15
|
+
if (text === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(text);
|
|
19
|
+
return isObject(parsed) ? parsed : undefined;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The object one of the project's own files holds (`text`, read from `file`), or undefined
|
|
27
|
+
* when there is no such file. A file that is not an object in its format is the user's to fix.
|
|
28
|
+
*/
|
|
29
|
+
export function projectObject(text, file, parse = JSON.parse) {
|
|
30
|
+
if (text === undefined)
|
|
31
|
+
return undefined;
|
|
32
|
+
let parsed;
|
|
33
|
+
try {
|
|
34
|
+
parsed = parse(text);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw new UserError(`${file} cannot be read: ${messageOf(err)}`);
|
|
38
|
+
}
|
|
39
|
+
if (!isObject(parsed))
|
|
40
|
+
throw new UserError(`${file} does not hold an object`);
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A map shared by every copy of docattest loaded in this thread. Checking docattest's own
|
|
3
|
+
* docs loads fresh copies of docattest per example, and parsing TypeScript's lib files or
|
|
4
|
+
* transpiling the same module again for each copy would dominate the run. Values must be
|
|
5
|
+
* pure functions of their key.
|
|
6
|
+
*/
|
|
7
|
+
export function threadCache(name) {
|
|
8
|
+
const key = Symbol.for(`docattest.${name}`);
|
|
9
|
+
// The one untyped boundary: every copy stores the same shape under the same key.
|
|
10
|
+
const holder = globalThis;
|
|
11
|
+
const existing = holder[key];
|
|
12
|
+
if (existing)
|
|
13
|
+
return existing;
|
|
14
|
+
const created = new Map();
|
|
15
|
+
holder[key] = created;
|
|
16
|
+
return created;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import ts from '../ts.cjs';
|
|
2
|
+
import { matchesCitation } from './match.js';
|
|
3
|
+
import { isSourceFile, pagePath } from '../languages.js';
|
|
4
|
+
import { dedupe, surfaceImports } from '../syntax/imports.js';
|
|
5
|
+
import { parseSource } from '../syntax/parse.js';
|
|
6
|
+
import { findTests } from './tests-in-file.js';
|
|
7
|
+
/** What a suite is called in a TypeScript test file, as a message names it. */
|
|
8
|
+
const SUITE = 'a describe block';
|
|
9
|
+
/** The tests a project-relative file declares, read from its syntax; nothing is run. */
|
|
10
|
+
export function listTests(files, file) {
|
|
11
|
+
if (!isSourceFile(file)) {
|
|
12
|
+
const message = `${file} is not a TypeScript or JavaScript file, so its tests cannot be read`;
|
|
13
|
+
return { ok: false, message };
|
|
14
|
+
}
|
|
15
|
+
const code = files.read(file);
|
|
16
|
+
if (code === undefined)
|
|
17
|
+
return { ok: false, message: `${file} does not exist` };
|
|
18
|
+
const found = findTests(pagePath(files, file), code);
|
|
19
|
+
const plain = ({ title, describes, line }) => ({
|
|
20
|
+
title,
|
|
21
|
+
describes,
|
|
22
|
+
line,
|
|
23
|
+
});
|
|
24
|
+
const suites = found.suites.map((suite) => ({ ...plain(suite), kind: SUITE }));
|
|
25
|
+
return { ok: true, tests: found.tests.map(plain), suites };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Surface symbols a cited test exercises: identifiers imported from a surface that appear
|
|
29
|
+
* in the body of every test the citation matches. Setup in hooks or helpers is not followed.
|
|
30
|
+
*/
|
|
31
|
+
export function citedSymbols(fileName, code, cited, surfaceOf) {
|
|
32
|
+
const tests = findTests(fileName, code).tests.filter((t) => matchesCitation(t, cited));
|
|
33
|
+
if (!tests.length)
|
|
34
|
+
return [];
|
|
35
|
+
const { named, namespaces } = importsOf(parseSource(fileName, code), surfaceOf);
|
|
36
|
+
const refs = [];
|
|
37
|
+
const visit = (node) => {
|
|
38
|
+
if (ts.isIdentifier(node)) {
|
|
39
|
+
const ref = named.get(node.text);
|
|
40
|
+
if (ref)
|
|
41
|
+
refs.push(ref);
|
|
42
|
+
}
|
|
43
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)) {
|
|
44
|
+
const surface = namespaces.get(node.expression.text);
|
|
45
|
+
if (surface)
|
|
46
|
+
refs.push({ name: node.name.text, surface });
|
|
47
|
+
}
|
|
48
|
+
ts.forEachChild(node, visit);
|
|
49
|
+
};
|
|
50
|
+
for (const { call } of tests)
|
|
51
|
+
call.arguments.slice(1).forEach(visit);
|
|
52
|
+
return dedupe(refs);
|
|
53
|
+
}
|
|
54
|
+
function importsOf(source, surfaceOf) {
|
|
55
|
+
const imports = { named: new Map(), namespaces: new Map() };
|
|
56
|
+
for (const bound of surfaceImports(source, surfaceOf)) {
|
|
57
|
+
if (bound.kind === 'namespace')
|
|
58
|
+
imports.namespaces.set(bound.local, bound.surface);
|
|
59
|
+
else
|
|
60
|
+
imports.named.set(bound.local, { name: bound.name, surface: bound.surface });
|
|
61
|
+
}
|
|
62
|
+
return imports;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=listing.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a declared test or describe block is the one cited: same title and, when the
|
|
3
|
+
* citation names describe blocks, exactly the same enclosing describe titles.
|
|
4
|
+
*/
|
|
5
|
+
export function matchesCitation(declared, cited) {
|
|
6
|
+
if (declared.title !== cited.title)
|
|
7
|
+
return false;
|
|
8
|
+
if (!cited.describes.length)
|
|
9
|
+
return true;
|
|
10
|
+
const { describes } = declared;
|
|
11
|
+
return (describes.length === cited.describes.length &&
|
|
12
|
+
describes.every((d, k) => d === cited.describes[k]));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=match.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import ts from '../ts.cjs';
|
|
2
|
+
import { parseSource } from '../syntax/parse.js';
|
|
3
|
+
// Vitest, Jest, Mocha, node:test and Playwright spellings. `todo` is not a test: it has no body.
|
|
4
|
+
const TESTS = new Set(['it', 'test', 'fit', 'xit', 'xtest', 'specify']);
|
|
5
|
+
const SUITES = new Set(['describe', 'suite', 'context', 'fdescribe', 'xdescribe']);
|
|
6
|
+
const MODIFIERS = new Set([
|
|
7
|
+
'only',
|
|
8
|
+
'skip',
|
|
9
|
+
'concurrent',
|
|
10
|
+
'sequential',
|
|
11
|
+
'fails',
|
|
12
|
+
'failing',
|
|
13
|
+
'shuffle',
|
|
14
|
+
'serial',
|
|
15
|
+
'parallel',
|
|
16
|
+
'fixme',
|
|
17
|
+
]);
|
|
18
|
+
/** Modifiers that take arguments and return the function that declares the test. */
|
|
19
|
+
const FACTORIES = new Set(['each', 'for', 'skipIf', 'runIf']);
|
|
20
|
+
/**
|
|
21
|
+
* Calls to `it` and `test` (and their `.only`, `.skip`, `.each`, `.concurrent` forms) with
|
|
22
|
+
* a string-literal title, each with the titles of the describe blocks around it. Titles in
|
|
23
|
+
* comments, strings or computed expressions are not declarations.
|
|
24
|
+
*/
|
|
25
|
+
export function findTests(fileName, code) {
|
|
26
|
+
const source = parseSource(fileName, code);
|
|
27
|
+
const found = { tests: [], suites: [] };
|
|
28
|
+
const lineOf = (node) => source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
|
|
29
|
+
const visit = (node, describes) => {
|
|
30
|
+
const role = ts.isCallExpression(node) ? roleOf(node.expression) : undefined;
|
|
31
|
+
if (role && ts.isCallExpression(node)) {
|
|
32
|
+
const title = literalTitle(node.arguments[0]);
|
|
33
|
+
const entry = { title: title ?? '', describes, line: lineOf(node), call: node };
|
|
34
|
+
if (title !== undefined)
|
|
35
|
+
found[role === 'suite' ? 'suites' : 'tests'].push(entry);
|
|
36
|
+
if (role === 'suite') {
|
|
37
|
+
const inner = [...describes, title ?? null];
|
|
38
|
+
for (const arg of node.arguments)
|
|
39
|
+
visit(arg, inner);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
ts.forEachChild(node, (child) => {
|
|
44
|
+
visit(child, describes);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
visit(source, []);
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
/** Whether a callee declares a test or a suite: `it`, `describe.only`, `it.each(rows)`... */
|
|
51
|
+
function roleOf(callee) {
|
|
52
|
+
if (ts.isPropertyAccessExpression(callee) && FACTORIES.has(callee.name.text))
|
|
53
|
+
return undefined;
|
|
54
|
+
const declaring = declaringName(callee);
|
|
55
|
+
if (!declaring)
|
|
56
|
+
return undefined;
|
|
57
|
+
if (declaring.viaDescribe)
|
|
58
|
+
return declaring.name === 'test' ? 'suite' : undefined;
|
|
59
|
+
if (TESTS.has(declaring.name))
|
|
60
|
+
return 'test';
|
|
61
|
+
return SUITES.has(declaring.name) ? 'suite' : undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The name a callee declares through, past modifiers (`.only`) and factories (`.each(rows)`),
|
|
65
|
+
* and whether a `.describe` was on the way (`test.describe`); undefined when anything else is.
|
|
66
|
+
*/
|
|
67
|
+
function declaringName(callee) {
|
|
68
|
+
let current = callee;
|
|
69
|
+
let viaDescribe = false;
|
|
70
|
+
while (current !== undefined && !ts.isIdentifier(current)) {
|
|
71
|
+
viaDescribe ||= ts.isPropertyAccessExpression(current) && current.name.text === 'describe';
|
|
72
|
+
current = innerCallee(current);
|
|
73
|
+
}
|
|
74
|
+
return current === undefined ? undefined : { name: current.text, viaDescribe };
|
|
75
|
+
}
|
|
76
|
+
/** One step into a callee: what a factory's call, a tagged template or a modifier applies to. */
|
|
77
|
+
function innerCallee(callee) {
|
|
78
|
+
if (ts.isCallExpression(callee))
|
|
79
|
+
return factoryOf(callee.expression);
|
|
80
|
+
if (ts.isTaggedTemplateExpression(callee))
|
|
81
|
+
return factoryOf(callee.tag);
|
|
82
|
+
if (!ts.isPropertyAccessExpression(callee))
|
|
83
|
+
return undefined;
|
|
84
|
+
const name = callee.name.text;
|
|
85
|
+
return name === 'describe' || MODIFIERS.has(name) ? callee.expression : undefined;
|
|
86
|
+
}
|
|
87
|
+
// `it.each(rows)` and `it.skipIf(cond)` return the declaring function; any other call in
|
|
88
|
+
// callee position is not a test API.
|
|
89
|
+
function factoryOf(expression) {
|
|
90
|
+
return ts.isPropertyAccessExpression(expression) && FACTORIES.has(expression.name.text)
|
|
91
|
+
? expression.expression
|
|
92
|
+
: undefined;
|
|
93
|
+
}
|
|
94
|
+
function literalTitle(node) {
|
|
95
|
+
if (!node)
|
|
96
|
+
return undefined;
|
|
97
|
+
return ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)
|
|
98
|
+
? node.text
|
|
99
|
+
: undefined;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=tests-in-file.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { blockFile } from './languages.js';
|
|
2
|
+
import { exportOrigins, exportsOf } from './program/exports.js';
|
|
3
|
+
import { createProgram, diagnosticsFor, resolveTypes, } from './program/program.js';
|
|
4
|
+
/**
|
|
5
|
+
* The checker's view of a project for the session: a program that type-checks examples and
|
|
6
|
+
* a lighter one that lists exports, each built on first use and parsing the project once.
|
|
7
|
+
*/
|
|
8
|
+
export class Compiler {
|
|
9
|
+
files;
|
|
10
|
+
surfaces;
|
|
11
|
+
examples;
|
|
12
|
+
programs = new Map();
|
|
13
|
+
parsed = new Map();
|
|
14
|
+
exportCache = new Map();
|
|
15
|
+
originCache = new Map();
|
|
16
|
+
constructor(files, surfaces, examples) {
|
|
17
|
+
this.files = files;
|
|
18
|
+
this.surfaces = surfaces;
|
|
19
|
+
this.examples = examples;
|
|
20
|
+
}
|
|
21
|
+
/** Diagnostics for examples; each must be one the session was created with. */
|
|
22
|
+
compile(examples) {
|
|
23
|
+
// The core asks even when a check has no examples; the program would cost its lib files.
|
|
24
|
+
if (examples.length === 0)
|
|
25
|
+
return [];
|
|
26
|
+
const program = this.getProgram('check');
|
|
27
|
+
return examples.flatMap((e) => diagnosticsFor(program, blockFile(this.files.root, e)).map((d) => ({ id: e.id, ...d })));
|
|
28
|
+
}
|
|
29
|
+
/** Exported names of a surface, or undefined when it cannot be resolved. */
|
|
30
|
+
exports(name) {
|
|
31
|
+
if (!this.exportCache.has(name)) {
|
|
32
|
+
const file = this.typesFile(name);
|
|
33
|
+
this.exportCache.set(name, file ? exportsOf(this.getProgram('exports'), file) : undefined);
|
|
34
|
+
}
|
|
35
|
+
return this.exportCache.get(name);
|
|
36
|
+
}
|
|
37
|
+
/** For each export of a surface, the files declaring what it refers to. */
|
|
38
|
+
origins(name) {
|
|
39
|
+
let origins = this.originCache.get(name);
|
|
40
|
+
if (!origins) {
|
|
41
|
+
const file = this.typesFile(name);
|
|
42
|
+
origins = file
|
|
43
|
+
? exportOrigins(this.getProgram('exports'), file)
|
|
44
|
+
: new Map();
|
|
45
|
+
this.originCache.set(name, origins);
|
|
46
|
+
}
|
|
47
|
+
return origins;
|
|
48
|
+
}
|
|
49
|
+
typesFile(name) {
|
|
50
|
+
const surface = this.surfaces.find((s) => s.spec.name === name);
|
|
51
|
+
if (!surface)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (surface.spec.path !== undefined)
|
|
54
|
+
return surface.types;
|
|
55
|
+
return this.files.memory
|
|
56
|
+
? undefined
|
|
57
|
+
: resolveTypes(this.getProgram('exports'), surface.spec.import, this.files.root);
|
|
58
|
+
}
|
|
59
|
+
getProgram(purpose) {
|
|
60
|
+
const built = this.programs.get(purpose);
|
|
61
|
+
if (built)
|
|
62
|
+
return built;
|
|
63
|
+
const program = createProgram({
|
|
64
|
+
files: this.files,
|
|
65
|
+
examples: new Map(this.examples.map((e) => [blockFile(this.files.root, e), e.code])),
|
|
66
|
+
surfaces: new Map(this.surfaces.flatMap((s) => s.types === undefined ? [] : [[s.spec.import, s.types]])),
|
|
67
|
+
parsed: this.parsed,
|
|
68
|
+
}, purpose);
|
|
69
|
+
this.programs.set(purpose, program);
|
|
70
|
+
return program;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BLOCK_LANGUAGES, IGNORED_NAMES, isSourceFile, SOURCE_FILES } from './languages.js';
|
|
2
|
+
import { docCommentProse } from './syntax/doc-prose.js';
|
|
3
|
+
import { asserts, expressionShape, mentioned } from './syntax/lexical.js';
|
|
4
|
+
/**
|
|
5
|
+
* What TypeScript and JavaScript say of themselves without the compiler: this module and
|
|
6
|
+
* everything it imports load in a few milliseconds, so `hello` is answered at once.
|
|
7
|
+
*/
|
|
8
|
+
export const description = {
|
|
9
|
+
blockLanguages: BLOCK_LANGUAGES,
|
|
10
|
+
sourceFiles: SOURCE_FILES,
|
|
11
|
+
ignoredNames: IGNORED_NAMES,
|
|
12
|
+
vocabulary: {
|
|
13
|
+
untitled: '(computed title)',
|
|
14
|
+
noTests: 'it declares no test with a literal title',
|
|
15
|
+
},
|
|
16
|
+
assertions: (examples) => Promise.resolve(examples.map((e) => asserts(e.code))),
|
|
17
|
+
docProse: (files) => Promise.resolve(files.map((f) => (isSourceFile(f.page) ? docCommentProse(f.text) : []))),
|
|
18
|
+
mentions: (spans, symbols) => {
|
|
19
|
+
const wanted = new Set(symbols);
|
|
20
|
+
return Promise.resolve(spans.map((span) => mentioned(span, wanted)));
|
|
21
|
+
},
|
|
22
|
+
expressions: (expressions) => Promise.resolve(expressions.map(expressionShape)),
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=description.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { compareStrings } from '../../compare-strings.js';
|
|
2
|
+
import { Revision } from './revision.js';
|
|
3
|
+
import { renames } from './renames.js';
|
|
4
|
+
const CODE = /\.(d\.)?[mc]?[jt]sx?$/;
|
|
5
|
+
/**
|
|
6
|
+
* Surface exports a change affects: those whose own declaration changed, those that reach
|
|
7
|
+
* a changed declaration through the code they use (in the working tree or at the base,
|
|
8
|
+
* so a dependency the change removed still counts), and those that appeared, disappeared
|
|
9
|
+
* or now stand for a different declaration. Nothing is built when no code changed.
|
|
10
|
+
*/
|
|
11
|
+
export function affectedExports(files, specs, change) {
|
|
12
|
+
const code = change.changed.filter((f) => CODE.test(f) && !/(^|\/)node_modules\//.test(f));
|
|
13
|
+
if (!code.length)
|
|
14
|
+
return [];
|
|
15
|
+
const now = new Revision(files, specs);
|
|
16
|
+
const then = new Revision(change.base, specs);
|
|
17
|
+
const before = then.fingerprints(code);
|
|
18
|
+
const renamed = renames(now, now.fingerprints(code), before);
|
|
19
|
+
const changed = changedUnits(now.fingerprints(code, renamed), before);
|
|
20
|
+
const [nowExports, thenExports] = [now.exports(), then.exports()];
|
|
21
|
+
const hit = new Set(remapped(nowExports, thenExports, renamed));
|
|
22
|
+
if (changed.size) {
|
|
23
|
+
for (const id of now.affected(nowExports, asNow(changed, renamed)))
|
|
24
|
+
hit.add(id);
|
|
25
|
+
for (const id of then.affected(thenExports, changed))
|
|
26
|
+
hit.add(id);
|
|
27
|
+
}
|
|
28
|
+
return [...hit].sort(compareStrings).map((id) => {
|
|
29
|
+
const [surface = '', name = ''] = id.split('\0');
|
|
30
|
+
return { name, surface };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Changed units are named as at the base; the working tree's graph knows them by now.
|
|
34
|
+
function asNow(changed, renamed) {
|
|
35
|
+
const out = new Set(changed);
|
|
36
|
+
for (const [key, was] of renamed)
|
|
37
|
+
if (changed.has(was))
|
|
38
|
+
out.add(key);
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
function changedUnits(now, then) {
|
|
42
|
+
const keys = new Set([...now.keys(), ...then.keys()]);
|
|
43
|
+
return new Set([...keys].filter((k) => now.get(k) !== then.get(k)));
|
|
44
|
+
}
|
|
45
|
+
function remapped(now, then, renamed) {
|
|
46
|
+
const ids = new Set([...now.keys(), ...then.keys()]);
|
|
47
|
+
const same = (a = new Set(), b = new Set()) => a.size === b.size && [...a].every((k) => b.has(renamed.get(k) ?? k));
|
|
48
|
+
return [...ids].filter((id) => !same(now.get(id), then.get(id)));
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=affected.js.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import ts from '../ts.cjs';
|
|
2
|
+
import { isReference } from './lookup.js';
|
|
3
|
+
/**
|
|
4
|
+
* A unit's tokens as the compiler reads them, so that only a change of meaning changes
|
|
5
|
+
* it: comments, whitespace, statement semicolons, trailing commas, redundant parentheses
|
|
6
|
+
* and quote style are not in it, string and number literals count by value, every name
|
|
7
|
+
* carries the units it resolves to (pointing an import elsewhere is a change), and local
|
|
8
|
+
* names are numbered by binding, so renaming a parameter or a local variable is not. A
|
|
9
|
+
* top-level name prints as its unit's key alone, read through `renamed` (a unit's key now
|
|
10
|
+
* → its key at the base), so a helper renamed or moved along with its callers is the same.
|
|
11
|
+
*/
|
|
12
|
+
export function fingerprint(unit, lookup, renamed = new Map()) {
|
|
13
|
+
const printer = new Printer(unit.file, lookup, renamed);
|
|
14
|
+
printer.out.push(unit.prefix);
|
|
15
|
+
for (const node of unit.nodes)
|
|
16
|
+
printer.emit(node);
|
|
17
|
+
return printer.out.join(' ');
|
|
18
|
+
}
|
|
19
|
+
class Printer {
|
|
20
|
+
file;
|
|
21
|
+
lookup;
|
|
22
|
+
renamed;
|
|
23
|
+
out = [];
|
|
24
|
+
locals = new Map();
|
|
25
|
+
constructor(file, lookup, renamed) {
|
|
26
|
+
this.file = file;
|
|
27
|
+
this.lookup = lookup;
|
|
28
|
+
this.renamed = renamed;
|
|
29
|
+
}
|
|
30
|
+
emit(node) {
|
|
31
|
+
if (node.kind >= ts.SyntaxKind.FirstJSDocNode && node.kind <= ts.SyntaxKind.LastJSDocNode) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (ts.isParenthesizedExpression(node) || ts.isParenthesizedTypeNode(node)) {
|
|
35
|
+
this.emit(ts.isParenthesizedExpression(node) ? node.expression : node.type);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const children = node.getChildren(this.file);
|
|
39
|
+
if (children.length === 0) {
|
|
40
|
+
this.out.push(this.token(node));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.out.push(`(${ts.SyntaxKind[node.kind]}`);
|
|
44
|
+
children.forEach((child, k) => {
|
|
45
|
+
if (!isTerminator(child, k === children.length - 1))
|
|
46
|
+
this.emit(child);
|
|
47
|
+
});
|
|
48
|
+
this.out.push(')');
|
|
49
|
+
}
|
|
50
|
+
token(node) {
|
|
51
|
+
if (ts.isIdentifier(node))
|
|
52
|
+
return this.local(node) ?? this.name(node);
|
|
53
|
+
if (ts.isPrivateIdentifier(node))
|
|
54
|
+
return node.text;
|
|
55
|
+
if (ts.isStringLiteral(node))
|
|
56
|
+
return `str:${JSON.stringify(node.text)}${this.targets(node)}`;
|
|
57
|
+
return literal(node) ?? ts.tokenToString(node.kind) ?? ts.SyntaxKind[node.kind];
|
|
58
|
+
}
|
|
59
|
+
// A name bound inside the unit and invisible outside it: the same binding prints the same
|
|
60
|
+
// number whatever it is called. Shadowing still shows, because binding is the checker's.
|
|
61
|
+
local(node) {
|
|
62
|
+
const symbol = this.lookup.checker.getSymbolAtLocation(node);
|
|
63
|
+
const declaration = symbol?.declarations?.[0];
|
|
64
|
+
if (!symbol || !declaration || !isLocal(declaration))
|
|
65
|
+
return undefined;
|
|
66
|
+
let id = this.locals.get(symbol);
|
|
67
|
+
if (id === undefined)
|
|
68
|
+
this.locals.set(symbol, (id = `$${this.locals.size}`));
|
|
69
|
+
return id;
|
|
70
|
+
}
|
|
71
|
+
// `{ helper }` is also the key `helper`, so its text stays even for a top-level name.
|
|
72
|
+
name(node) {
|
|
73
|
+
const targets = this.targets(node);
|
|
74
|
+
const keyed = ts.isShorthandPropertyAssignment(node.parent);
|
|
75
|
+
const bare = targets && !keyed && this.lookup.isTopLevelName(node);
|
|
76
|
+
return bare ? targets : `${node.text}${targets}`;
|
|
77
|
+
}
|
|
78
|
+
targets(node) {
|
|
79
|
+
if (!isReference(node))
|
|
80
|
+
return '';
|
|
81
|
+
const keys = this.lookup.keysAt(node).map((k) => this.renamed.get(k) ?? k);
|
|
82
|
+
return keys.length ? `@${keys.sort().join('|')}` : '';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Any other literal, by value: numbers whatever their spelling, JSX text whatever its
|
|
86
|
+
// whitespace, and templates and regular expressions as written.
|
|
87
|
+
function literal(node) {
|
|
88
|
+
if (ts.isNumericLiteral(node) || ts.isBigIntLiteral(node))
|
|
89
|
+
return `num:${node.text}`;
|
|
90
|
+
if (ts.isJsxText(node))
|
|
91
|
+
return `jsx:${JSON.stringify(node.text.replace(/\s+/g, ' '))}`;
|
|
92
|
+
if (ts.isLiteralExpression(node) || ts.isTemplateLiteralToken(node)) {
|
|
93
|
+
return `${ts.SyntaxKind[node.kind]}:${JSON.stringify(node.text)}`;
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
// A `;` or `,` that ends its parent separates nothing: a statement's optional semicolon,
|
|
98
|
+
// a trailing comma, a type member's separator.
|
|
99
|
+
function isTerminator(node, last) {
|
|
100
|
+
return (last && (node.kind === ts.SyntaxKind.SemicolonToken || node.kind === ts.SyntaxKind.CommaToken));
|
|
101
|
+
}
|
|
102
|
+
function isLocal(declaration) {
|
|
103
|
+
if (ts.isParameter(declaration) || ts.isTypeParameterDeclaration(declaration))
|
|
104
|
+
return true;
|
|
105
|
+
if (ts.isBindingElement(declaration)) {
|
|
106
|
+
// `{ a }` names a property as well as a variable; `{ a: b }` and `[a]` name variables.
|
|
107
|
+
const keyed = !declaration.propertyName && ts.isObjectBindingPattern(declaration.parent);
|
|
108
|
+
return !keyed && inScope(declaration);
|
|
109
|
+
}
|
|
110
|
+
const named = ts.isVariableDeclaration(declaration) || ts.isFunctionDeclaration(declaration);
|
|
111
|
+
return (named || ts.isClassDeclaration(declaration)) && inScope(declaration.parent);
|
|
112
|
+
}
|
|
113
|
+
// Inside a function, a block or a loop: somewhere a name cannot be seen from outside.
|
|
114
|
+
function inScope(node) {
|
|
115
|
+
for (let n = node; !ts.isSourceFile(n) && !ts.isModuleBlock(n); n = n.parent) {
|
|
116
|
+
if (ts.isFunctionLike(n) || ts.isBlock(n) || ts.isCatchClause(n))
|
|
117
|
+
return true;
|
|
118
|
+
if (ts.isForStatement(n) || ts.isForInStatement(n) || ts.isForOfStatement(n))
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=fingerprint.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import ts from '../ts.cjs';
|
|
2
|
+
import { isReference } from './lookup.js';
|
|
3
|
+
import { TOP_LEVEL } from './units.js';
|
|
4
|
+
/**
|
|
5
|
+
* Which units depend on which, in one program: a unit depends on every unit its code names
|
|
6
|
+
* (calls, members, constants, types, base classes), resolved by the checker through imports
|
|
7
|
+
* and re-exports. A module's top-level statements are its side effects at import: they
|
|
8
|
+
* depend on what they name, and whatever they name depends on them in turn, because they
|
|
9
|
+
* may change it (`registry.set(…)`).
|
|
10
|
+
*/
|
|
11
|
+
export class DependencyGraph {
|
|
12
|
+
lookup;
|
|
13
|
+
dependents = new Map();
|
|
14
|
+
seen = new Set();
|
|
15
|
+
constructor(lookup) {
|
|
16
|
+
this.lookup = lookup;
|
|
17
|
+
}
|
|
18
|
+
/** Follow every dependency from these units, and from every module's side effects. */
|
|
19
|
+
build(roots) {
|
|
20
|
+
const queue = [...roots];
|
|
21
|
+
for (const file of this.lookup.projectFiles()) {
|
|
22
|
+
for (const unit of this.lookup.units(file).units.values()) {
|
|
23
|
+
if (unit.key.endsWith(`#${TOP_LEVEL}`))
|
|
24
|
+
queue.push(unit.key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (let key = queue.pop(); key !== undefined; key = queue.pop()) {
|
|
28
|
+
if (this.seen.has(key))
|
|
29
|
+
continue;
|
|
30
|
+
this.seen.add(key);
|
|
31
|
+
const unit = this.lookup.unit(key);
|
|
32
|
+
if (unit)
|
|
33
|
+
queue.push(...this.follow(unit));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Units that are, or depend at any depth on, one of the changed units. */
|
|
37
|
+
tainted(changed) {
|
|
38
|
+
const out = new Set();
|
|
39
|
+
const queue = [...changed];
|
|
40
|
+
for (let key = queue.pop(); key !== undefined; key = queue.pop()) {
|
|
41
|
+
if (out.has(key))
|
|
42
|
+
continue;
|
|
43
|
+
out.add(key);
|
|
44
|
+
queue.push(...(this.dependents.get(key) ?? []));
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
follow(unit) {
|
|
49
|
+
const targets = new Set();
|
|
50
|
+
const visit = (node) => {
|
|
51
|
+
if (isReference(node))
|
|
52
|
+
for (const k of this.lookup.keysAt(node))
|
|
53
|
+
targets.add(k);
|
|
54
|
+
ts.forEachChild(node, visit);
|
|
55
|
+
};
|
|
56
|
+
unit.nodes.forEach(visit);
|
|
57
|
+
targets.delete(unit.key);
|
|
58
|
+
const sideEffects = unit.key.endsWith(`#${TOP_LEVEL}`);
|
|
59
|
+
for (const target of targets) {
|
|
60
|
+
this.depend(unit.key, target);
|
|
61
|
+
if (sideEffects)
|
|
62
|
+
this.depend(target, unit.key);
|
|
63
|
+
}
|
|
64
|
+
return [...targets];
|
|
65
|
+
}
|
|
66
|
+
depend(from, on) {
|
|
67
|
+
const set = this.dependents.get(on) ?? new Set();
|
|
68
|
+
set.add(from);
|
|
69
|
+
this.dependents.set(on, set);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=graph.js.map
|