test-inventory 0.12.1 → 0.12.3

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +141 -0
  2. package/README.md +74 -49
  3. package/dist/ast.d.ts +7 -2
  4. package/dist/ast.js +43 -3
  5. package/dist/case-titles.d.ts +5 -11
  6. package/dist/case-titles.js +69 -55
  7. package/dist/config-runs.d.ts +19 -2
  8. package/dist/config-runs.js +379 -90
  9. package/dist/config.d.ts +0 -5
  10. package/dist/config.js +0 -7
  11. package/dist/dependency-hash.js +1 -32
  12. package/dist/diagnostics.js +17 -2
  13. package/dist/diff.d.ts +2 -45
  14. package/dist/extract.d.ts +13 -3
  15. package/dist/extract.js +837 -89
  16. package/dist/frameworks/bun.js +47 -24
  17. package/dist/frameworks/common.d.ts +4 -2
  18. package/dist/frameworks/common.js +10 -11
  19. package/dist/frameworks/jasmine-registration.d.ts +47 -0
  20. package/dist/frameworks/jasmine-registration.js +632 -0
  21. package/dist/frameworks/jasmine.d.ts +7 -1
  22. package/dist/frameworks/jasmine.js +65 -70
  23. package/dist/frameworks/jest.d.ts +2 -2
  24. package/dist/frameworks/jest.js +126 -51
  25. package/dist/frameworks/vitest.d.ts +2 -3
  26. package/dist/frameworks/vitest.js +80 -16
  27. package/dist/generator-steps.d.ts +56 -0
  28. package/dist/generator-steps.js +254 -0
  29. package/dist/model.d.ts +37 -5
  30. package/dist/mutation-arrays.d.ts +25 -0
  31. package/dist/mutation-arrays.js +229 -0
  32. package/dist/mutation-calls.d.ts +33 -0
  33. package/dist/mutation-calls.js +774 -0
  34. package/dist/mutation-order.d.ts +19 -0
  35. package/dist/mutation-order.js +55 -0
  36. package/dist/mutation-references.d.ts +109 -0
  37. package/dist/mutation-references.js +462 -0
  38. package/dist/mutation-returns.d.ts +13 -0
  39. package/dist/mutation-returns.js +71 -0
  40. package/dist/node-scripts.d.ts +4 -1
  41. package/dist/node-scripts.js +77 -11
  42. package/dist/options.d.ts +2 -0
  43. package/dist/options.js +6 -1
  44. package/dist/records.d.ts +5 -3
  45. package/dist/records.js +81 -28
  46. package/dist/scan-file.d.ts +18 -4
  47. package/dist/scan-file.js +44 -5
  48. package/dist/scan-source.js +2 -1
  49. package/dist/scan.js +30 -13
  50. package/dist/types.d.ts +45 -1
  51. package/dist/values.d.ts +72 -18
  52. package/dist/values.js +651 -172
  53. package/dist/vitest-concurrency.d.ts +16 -0
  54. package/dist/vitest-concurrency.js +55 -0
  55. package/package.json +2 -2
  56. package/schema/v1.json +1 -0
package/dist/scan-file.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { DependencyGraph, fileDependencies } from "./dependency-hash.js";
2
2
  import { fileDiagnostic, toDiagnostic } from "./diagnostics.js";
3
- import { extract, noHooks } from "./extract.js";
4
- import { parseModule } from "./frameworks/bindings.js";
3
+ import { extract, initializesLocalModule, noHooks } from "./extract.js";
4
+ import { importsFrom, parseModule } from "./frameworks/bindings.js";
5
5
  import { ExportedValues } from "./imported-values.js";
6
6
  import { atLeast, problem } from "./frameworks/common.js";
7
7
  import { PlaywrightAdapter } from "./frameworks/playwright.js";
8
8
  import { VitestAdapter } from "./frameworks/vitest.js";
9
+ import { concurrencyRules } from "./vitest-concurrency.js";
9
10
  import { JestAdapter } from "./frameworks/jest.js";
10
11
  import { MochaAdapter } from "./frameworks/mocha.js";
11
12
  import { BunAdapter } from "./frameworks/bun.js";
@@ -21,7 +22,7 @@ const TYPE_TEST = /\.(test|spec)-d\.[cm]?[jt]sx?$/;
21
22
  const BENCHMARK = /\.(bench|benchmark)\.[cm]?[jt]sx?$/;
22
23
  const ADAPTERS = {
23
24
  playwright: (parsed, file, readModule) => new PlaywrightAdapter(parsed.program, file, readModule),
24
- vitest: (parsed, file, readModule, settings) => new VitestAdapter(parsed, file, readModule, settings.titleTruncate),
25
+ vitest: (parsed, file, readModule, settings) => new VitestAdapter(parsed, file, readModule, settings.titleThresholds),
25
26
  jest: (parsed, file, readModule) => new JestAdapter(parsed, file, readModule),
26
27
  mocha: (parsed, file, readModule, settings) => new MochaAdapter(parsed, file, readModule, settings.mochaInterface),
27
28
  jasmine: (parsed, file, readModule) => new JasmineAdapter(parsed, file, readModule),
@@ -43,10 +44,39 @@ function frame(parsed, relativeFilePath, settings, readModule, exports) {
43
44
  export function noRecords(relativeFilePath) {
44
45
  return { file: fileRecord(relativeFilePath, noHooks(), { suites: [], tests: [] }), suites: [], tests: [] };
45
46
  }
47
+ /** Record module initialization in collection order. A spec that imports only Playwright needs its records only
48
+ * when script filters or project dependencies select among its tests. */
49
+ export function playwrightSelection(module, version, preloaded) {
50
+ const imports = new Set();
51
+ if ('reason' in module)
52
+ return { imports, parsed: null, records: () => null };
53
+ const parsed = parseModule(module);
54
+ let cached;
55
+ const records = () => {
56
+ if (cached === undefined) {
57
+ const result = scanFile(parsed, module.relativeFilePath, {
58
+ framework: 'playwright',
59
+ version,
60
+ readModule: module.readModule,
61
+ comments: 'none',
62
+ root: null,
63
+ initializeModule: (name) => {
64
+ imports.add(name);
65
+ return !preloaded?.has(name);
66
+ },
67
+ });
68
+ cached = result.diagnostics.length || result.unknownRegistration ? null : result;
69
+ }
70
+ return cached;
71
+ };
72
+ if (importsFrom(parsed.program, initializesLocalModule))
73
+ records();
74
+ return { imports, records, parsed };
75
+ }
46
76
  /** Reads one file: parse, extract, build records, and drop the AST. Never throws. */
47
77
  export function scanFile(code, relativeFilePath, settings) {
48
78
  try {
49
- const parsed = parseFile(relativeFilePath, code);
79
+ const parsed = typeof code === 'string' ? parseFile(relativeFilePath, code) : code;
50
80
  const diagnostics = [];
51
81
  if (parsed.error) {
52
82
  const { message, start, end } = parsed.error;
@@ -60,7 +90,12 @@ export function scanFile(code, relativeFilePath, settings) {
60
90
  const extraction = extract(main, (module) => {
61
91
  const helper = parseModule(module);
62
92
  return helper.error ? null : frame(helper, module.relativeFilePath, settings, module.readModule, exports);
63
- }, { expandCases: settings.expandCases ?? false, version: settings.version });
93
+ }, {
94
+ expandCases: settings.expandCases ?? false,
95
+ version: settings.version,
96
+ collectImports: settings.framework === 'playwright' && settings.readModule !== null,
97
+ initializeModule: settings.initializeModule,
98
+ });
64
99
  const isTypeTest = settings.framework === 'vitest' && TYPE_TEST.test(relativeFilePath);
65
100
  const unfollowed = [];
66
101
  const dependencies = fileDependencies(settings.graph ?? new DependencyGraph(), main, extraction, isTypeTest, (place) => unfollowed.push(place), settings.runsWith, settings.snapshotFiles);
@@ -69,6 +104,9 @@ export function scanFile(code, relativeFilePath, settings) {
69
104
  framework: settings.framework,
70
105
  focusesLikeJasmine: settings.framework === 'jasmine' ||
71
106
  (settings.framework === 'webdriverio' && settings.webdriverioFramework === 'jasmine'),
107
+ vitestConcurrency: settings.framework === 'vitest' ? concurrencyRules(settings.version, settings.patch) : null,
108
+ narrowsVitestFocus: settings.framework === 'vitest' &&
109
+ (atLeast(settings.version, 4, 1) || (settings.version?.[0] === 4 && (settings.patch ?? 0) >= 17)),
72
110
  comments: settings.comments,
73
111
  isTypeTest,
74
112
  // Vitest 5's default `benchmark.include`, when no config says.
@@ -86,6 +124,7 @@ export function scanFile(code, relativeFilePath, settings) {
86
124
  ...unfollowed.map((place) => toDiagnostic(place.problem, place.relativeFilePath, place.source)),
87
125
  ],
88
126
  usesGlobals: extraction.usesGlobals,
127
+ unknownRegistration: extraction.unknownRegistration,
89
128
  };
90
129
  }
91
130
  catch (error) {
@@ -1,5 +1,5 @@
1
1
  import { createInventory } from "./inventory.js";
2
- import { checkComments, checkFlag, checkFramework, checkObject, checkString, checkVersion, invalid, majorMinor, toPosixPath, } from "./options.js";
2
+ import { checkComments, checkFlag, checkFramework, checkObject, checkString, checkVersion, invalid, majorMinor, patchVersion, toPosixPath, } from "./options.js";
3
3
  import { scanFile } from "./scan-file.js";
4
4
  /**
5
5
  * Scans the code of one test file, without reading anything from disk.
@@ -19,6 +19,7 @@ export function scanSource(options) {
19
19
  const result = scanFile(checked.code, relativeFilePath, {
20
20
  framework,
21
21
  version: majorMinor(frameworkVersion),
22
+ patch: patchVersion(frameworkVersion),
22
23
  comments,
23
24
  expandCases,
24
25
  readModule: null,
package/dist/scan.js CHANGED
@@ -12,9 +12,9 @@ import { fileDiagnostic } from "./diagnostics.js";
12
12
  import { findFiles, normalizePattern, readFailure } from "./files.js";
13
13
  import { configFolderBelow, detectFramework, detectFrameworkVersion, FRAMEWORK_NAMES, OLDEST, } from "./framework-version.js";
14
14
  import { createInventory } from "./inventory.js";
15
- import { checkComments, checkFlag, checkFramework, checkObject, checkSignal, checkStrings, checkVersion, invalid, majorMinor, toPosixPath, } from "./options.js";
15
+ import { checkComments, checkFlag, checkFramework, checkObject, checkSignal, checkStrings, checkVersion, invalid, majorMinor, patchVersion, toPosixPath, } from "./options.js";
16
16
  import { moduleResolver } from "./resolve.js";
17
- import { noRecords, scanFile } from "./scan-file.js";
17
+ import { noRecords, playwrightSelection, scanFile } from "./scan-file.js";
18
18
  import { globalsCheck } from "./vitest-config.js";
19
19
  function versionDiagnostics(framework, version, source, range) {
20
20
  const name = FRAMEWORK_NAMES[framework];
@@ -43,17 +43,21 @@ function versionDiagnostics(framework, version, source, range) {
43
43
  fileDiagnostic('approximate-framework-version', source, `Only the range "${range}" was found for ${name}, so the rules of the newest ${major}.x release apply.`),
44
44
  ];
45
45
  }
46
- /**
47
- * The length Vitest shortens a value in a case title to: `test.taskTitleValueFormatTruncate` from Vitest 5,
48
- * `test.chaiConfig.truncateThreshold` before, from the project that runs the file; 40, Vitest's default, when it sets
49
- * none or the scan can't read it.
50
- */
51
- function titleTruncate(placement, version) {
46
+ /** The distinct case-title lengths used by the Vitest projects collecting the file. */
47
+ function titleThresholds(placement, version) {
52
48
  const key = atLeast(version, 5, 0)
53
49
  ? ['test', 'taskTitleValueFormatTruncate']
54
50
  : ['test', 'chaiConfig', 'truncateThreshold'];
55
- const setting = placement.settings && settingAt(placement.settings, key);
56
- return setting?.kind === 'value' && typeof setting.value === 'number' ? setting.value : 40;
51
+ const settings = placement.projects?.length
52
+ ? placement.projects.map((project) => project.settings)
53
+ : [placement.settings];
54
+ const lengths = settings.map((config) => {
55
+ const setting = config && settingAt(config, key);
56
+ if (setting?.kind === 'unknown')
57
+ return null;
58
+ return setting?.kind === 'value' && typeof setting.value === 'number' ? setting.value : 40;
59
+ });
60
+ return [...new Set(lengths)];
57
61
  }
58
62
  /** Why Jest gives a file that uses its globals none: a project that runs it sets `injectGlobals` to false. */
59
63
  function jestGlobals(placement) {
@@ -176,13 +180,23 @@ export async function scan(options) {
176
180
  ? [majorMinor(frameworkVersion)[0], Number.MAX_SAFE_INTEGER]
177
181
  : majorMinor(frameworkVersion);
178
182
  const source = override === null ? (detected?.source ?? 'package.json') : '.';
183
+ const patch = patchVersion(frameworkVersion);
179
184
  const projectDiagnostics = versionDiagnostics(framework, frameworkVersion, source, range);
180
185
  projectDiagnostics.push(...found.diagnostics);
181
186
  const readerFor = moduleResolver(root);
182
187
  const graph = new DependencyGraph(root, framework);
183
188
  const exports = new ExportedValues();
184
189
  const configs = new Configs(root, framework, readerFor, rules);
185
- const runs = new ConfigRuns(configs, framework, rules, patterns === null);
190
+ const registering = new Map();
191
+ const runs = new ConfigRuns(configs, framework, rules, patterns === null ? found.files.map((file) => file.absolutePath) : null, (file, preloaded) => {
192
+ const cached = registering.get(file);
193
+ if (cached && !preloaded)
194
+ return cached;
195
+ const selection = playwrightSelection(readerFor(file)(file), rules, preloaded);
196
+ if (!preloaded)
197
+ registering.set(file, selection);
198
+ return selection;
199
+ });
186
200
  const placements = new Map(found.files.map((file) => [file.absolutePath, runs.placementOf(file.absolutePath)]));
187
201
  const files = patterns
188
202
  ? found.files
@@ -229,7 +243,7 @@ export async function scan(options) {
229
243
  const config = placement.config?.record.relativeFilePath ?? null;
230
244
  let code;
231
245
  try {
232
- code = await readFile(absolutePath, 'utf8');
246
+ code = registering.get(absolutePath)?.parsed ?? (await readFile(absolutePath, 'utf8'));
233
247
  }
234
248
  catch (error) {
235
249
  const records = noRecords(relativeFilePath);
@@ -243,12 +257,15 @@ export async function scan(options) {
243
257
  continue;
244
258
  }
245
259
  const runsWith = configDependencies.of(placement);
260
+ const { preloaded } = placement;
246
261
  const result = scanFile(code, relativeFilePath, {
247
262
  framework,
248
263
  version: rules,
264
+ patch,
249
265
  comments,
250
266
  expandCases,
251
267
  readModule: readerFor(absolutePath, importMap(placement, framework)),
268
+ initializeModule: preloaded ? (name) => !preloaded.has(name) : undefined,
252
269
  root,
253
270
  isBenchmarkFile: placement.runs === null ? null : placement.runs === 'benchmark',
254
271
  config: fileConfig(placement, framework, rules, absolutePath),
@@ -258,7 +275,7 @@ export async function scan(options) {
258
275
  ? webdriverioInterface(placement, configs)
259
276
  : undefined,
260
277
  webdriverioFramework: framework === 'webdriverio' ? webdriverioFramework(placement, configs) : undefined,
261
- titleTruncate: framework === 'vitest' ? titleTruncate(placement, rules) : undefined,
278
+ titleThresholds: framework === 'vitest' ? titleThresholds(placement, rules) : undefined,
262
279
  graph,
263
280
  exports,
264
281
  runsWith,
package/dist/types.d.ts CHANGED
@@ -38,7 +38,7 @@ export type SettingSource = 'test' | 'suite' | 'file' | 'config';
38
38
  * @inline
39
39
  */
40
40
  export type DiagnosticLevel = 'error' | 'warning';
41
- export type DiagnosticCode = 'unresolved-test-import' | 'parse-error' | 'read-error' | 'framework-mismatch' | 'unresolved-tag' | 'unresolved-annotation' | 'unresolved-cases' | 'cases-not-expanded' | 'test-in-loop' | 'dynamic-title' | 'duplicate-title' | 'duplicate-id' | 'internal-error' | 'invalid-chain' | 'skip-without-body' | 'test-without-body' | 'describe-not-called' | 'async-describe' | 'describe-throws' | 'nested-test' | 'tag-without-at' | 'removed-api' | 'invalid-fixture-argument' | 'only-in-skipped-describe' | 'config-may-change-state' | 'undefined-tag' | 'symlink-ignored' | 'invalid-import' | 'globals-not-enabled' | 'unknown-framework-version' | 'unsupported-framework-version' | 'local-test-object' | 'state-in-helper' | 'unresolved-option' | 'dynamic-reason' | 'no-files-matched' | 'unsupported-file' | 'approximate-framework-version' | 'test-in-function' | 'empty-title' | 'bench-outside-benchmark-file' | 'config-value-unknown' | 'file-not-run' | 'forbidden-only' | 'dependency-not-followed';
41
+ export type DiagnosticCode = 'unresolved-test-import' | 'parse-error' | 'read-error' | 'framework-mismatch' | 'unresolved-tag' | 'unresolved-annotation' | 'unresolved-cases' | 'cases-not-expanded' | 'test-in-loop' | 'dynamic-title' | 'duplicate-title' | 'duplicate-id' | 'internal-error' | 'invalid-hook' | 'invalid-chain' | 'skip-without-body' | 'test-without-body' | 'describe-not-called' | 'async-describe' | 'describe-throws' | 'nested-test' | 'tag-without-at' | 'removed-api' | 'invalid-fixture-argument' | 'only-in-skipped-describe' | 'config-may-change-state' | 'undefined-tag' | 'symlink-ignored' | 'invalid-import' | 'globals-not-enabled' | 'unknown-framework-version' | 'unsupported-framework-version' | 'local-test-object' | 'state-in-helper' | 'unresolved-option' | 'dynamic-reason' | 'no-files-matched' | 'unsupported-file' | 'approximate-framework-version' | 'test-in-function' | 'empty-title' | 'bench-outside-benchmark-file' | 'config-value-unknown' | 'file-not-run' | 'forbidden-only' | 'dependency-not-followed';
42
42
  export type MetaValue = string | number | boolean | null | MetaValue[] | {
43
43
  [key: string]: MetaValue;
44
44
  };
@@ -476,4 +476,48 @@ export interface Diagnostic {
476
476
  /** Source text involved, shortened when long; null when none. */
477
477
  source: string | null;
478
478
  }
479
+ /** Changes a comparison can report; one matched test can have several. */
480
+ export type ChangeKind = 'added' | 'removed' | 'moved' | 'renamed' | 'bodyChanged' | 'dependenciesChanged' | 'newlySkipped' | 'reEnabled' | 'stateChanged' | 'tagsChanged' | 'metadataChanged';
481
+ /** The evidence that two records identify the same test; null for an addition or removal. */
482
+ export type MatchMethod = 'id' | 'bodyHash' | 'bodyHashAndFile' | 'bodyHashAndSuite' | 'bodyHashAndDependencies';
483
+ /** One addition, removal or changed test. Locations and records come from the saved scans unchanged. */
484
+ export type TestChange = {
485
+ kinds: ChangeKind[];
486
+ /** Changed record keys, excluding locations and ids. Hashes are included only when comparable. */
487
+ changedFields: (keyof TestRecord)[];
488
+ } & ({
489
+ match: MatchMethod;
490
+ before: TestRecord;
491
+ after: TestRecord;
492
+ } | {
493
+ match: null;
494
+ before: TestRecord;
495
+ after: null;
496
+ } | {
497
+ match: null;
498
+ before: null;
499
+ after: TestRecord;
500
+ });
501
+ /** Tests with identical syntax-tree bodies, including trivial bodies; this does not prove they test the same thing. */
502
+ export interface CloneGroup {
503
+ bodyHash: string;
504
+ testIds: string[];
505
+ }
506
+ /** The deterministic comparison of two saved inventories. */
507
+ export interface InventoryDiff {
508
+ schemaVersion: 1;
509
+ tool: Tool;
510
+ framework: Framework;
511
+ beforeToolVersion: string;
512
+ afterToolVersion: string;
513
+ hashesComparable: boolean;
514
+ /** Category counts overlap; changed counts matched tests, while unchanged counts matches with no changes. */
515
+ summary: Record<ChangeKind | 'changed' | 'unchanged', number>;
516
+ changes: TestChange[];
517
+ clones: {
518
+ before: CloneGroup[];
519
+ after: CloneGroup[];
520
+ };
521
+ warnings: string[];
522
+ }
479
523
  export {};
package/dist/values.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { Expression, Node } from 'oxc-parser';
1
+ import type { CallExpression, Expression, Node } from 'oxc-parser';
2
2
  import { type FunctionNode } from './ast.ts';
3
3
  export type Value = string | number | boolean | null | undefined | Value[] | {
4
4
  [key: string]: Value;
5
5
  };
6
- /** A resolved value or a failed lookup. `arrayLength` can record the size of an imported array with unknown items. */
6
+ /** An unknown value can still have a known array length, be defined, or be a truthy object. */
7
7
  export type Resolved = {
8
8
  ok: true;
9
9
  value: Value;
@@ -11,39 +11,91 @@ export type Resolved = {
11
11
  ok: false;
12
12
  importedFrom: string | null;
13
13
  arrayLength?: number;
14
+ defined?: true;
15
+ truthy?: true;
16
+ nonIterable?: true;
17
+ iterator?: true;
14
18
  };
19
+ /** What a synchronous iterator produced at one registration-time spread. */
20
+ export interface IteratorSpread {
21
+ values: Resolved[];
22
+ complete: boolean;
23
+ outcome: 'next' | 'throw' | 'unknown';
24
+ registered: boolean | 'possible';
25
+ }
26
+ /** Whether a default runs, a pattern throws or a parameter name becomes initialized. Null denotes uncertainty. */
27
+ export type ParameterStep = boolean | null | 'throw' | 'initialize';
28
+ export interface GeneratorLocals {
29
+ operands: Map<Node, Resolved>;
30
+ catches: Map<Node, Map<string, () => Resolved>>;
31
+ }
32
+ /** Only strings and values with an iterator can be spread into a call or bound to an array pattern. */
33
+ export declare function nonIterable(value: Value): boolean;
15
34
  /** What another module exports under a name, `default` included, for an import of the file. */
16
35
  export type ImportReader = (source: string, name: string) => Resolved;
17
36
  /** Whether a value can be used as a property name. */
18
37
  export declare function isKey(value: Value): value is string | number;
38
+ type Operation = Extract<Expression, {
39
+ type: 'TemplateLiteral' | 'BinaryExpression' | 'LogicalExpression' | 'ConditionalExpression' | 'UnaryExpression';
40
+ }>;
41
+ export declare function isValueOperation(node: Expression): node is Operation;
42
+ export declare function usesRightOperand(operator: '&&' | '||' | '??', left: Value): boolean;
43
+ /** Read operands in evaluation order, including only the selected side of a short-circuit expression. */
44
+ export declare function operationValue(expression: Operation, read: (node: Expression) => Resolved): Resolved;
19
45
  export declare function isScopeNode(node: Node): boolean;
20
46
  export declare function bindingNames(pattern: Node | null, names?: string[]): string[];
21
47
  /** Works out values written in the same file: literals, constants, enums, and arrays and objects built from them. */
22
48
  export declare class Values {
23
49
  private readonly bindingsByScope;
24
50
  private readonly cache;
51
+ private readonly fileIterators;
52
+ readonly iteratorMethods: WeakMap<CallExpression, {
53
+ outcome: IteratorSpread["outcome"];
54
+ result: Resolved;
55
+ registered: boolean | "possible";
56
+ }>;
57
+ readonly iteratorSpreads: WeakMap<Expression, IteratorSpread>;
25
58
  private readonly pending;
26
59
  /** The functions being read at one of their calls, innermost last. */
27
- private readonly calls;
60
+ private calls;
28
61
  private readonly imports;
29
62
  private readonly assigned;
63
+ private readonly rebound;
30
64
  private readonly changed;
31
65
  /** Without `imports`, a value imported from another module is not worked out. */
32
66
  constructor(imports?: ImportReader | null);
67
+ /** Saved instances belong to the invocation that evaluated their initializer. */
68
+ recordIterator(node: Expression, scopes: readonly Node[], value: Resolved | undefined): void;
69
+ /** Follow only bindings that preserve the iterator object itself. A copy of its elements is reusable. */
70
+ iteratorOf(node: Expression, scopes: readonly Node[]): Resolved | undefined;
71
+ /** A suspended helper still sees its own arguments and the parameters of the enclosing calls that created it. */
72
+ captureBindings<T, R = void>(read: (value: T) => R): (value: T) => R;
73
+ /** Branches may resume the same suspension with different values. Keep their constant caches independent. */
74
+ withGeneratorLocals<T>(locals: GeneratorLocals, read: () => T): T;
75
+ completedOperand(node: Node, scopes: readonly Node[]): Resolved | undefined;
76
+ bindCatch(clause: Extract<Node, {
77
+ type: 'CatchClause';
78
+ }>, value: Resolved, scopes: readonly Node[], locals: GeneratorLocals): ReadonlyMap<Node, ParameterStep>;
79
+ /** Read arguments in the calling scope, up to the first spread whose length is unknown. */
80
+ callArguments(call: CallExpression, scopes: readonly Node[], expandSpread: boolean, read: (operand: Expression) => Resolved): {
81
+ args: Resolved[];
82
+ complete: boolean;
83
+ };
33
84
  /**
34
85
  * Runs `read` with a function's parameters bound to the arguments of one call, worked out where the call is, so that
35
86
  * titles and values built from them resolve, as in `test(\`${side} rejects a zero quantity\`)` inside
36
87
  * `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known, and `complete` is
37
88
  * false then. A missing argument takes the parameter's default value, worked out in `scopes`, the scopes around the
38
- * function. A rest parameter, as `...cycles`, holds the arguments left.
89
+ * function. A rest parameter, as `...cycles`, holds the arguments left. When collecting parameter side effects,
90
+ * `steps` records conditional defaults and destructuring failures in the order the caller visits the parameters.
39
91
  */
40
- withArguments<T>(fn: FunctionNode, args: readonly Resolved[], scopes: readonly Node[], read: () => T, complete?: boolean): T;
92
+ withArguments<T>(fn: FunctionNode, args: readonly Resolved[], scopes: readonly Node[], read: () => T, complete?: boolean, steps?: Map<Node, ParameterStep>): T;
41
93
  /**
42
94
  * Runs `read` with the names a loop declares bound to one of the values it goes over, as in
43
95
  * `for (const [tier, bps] of Object.entries(FEES))`. `declarator` is the loop's variable declarator.
44
96
  */
45
97
  withLoopValue<T>(declarator: Node, pattern: Node, value: Resolved, body: Node, scopes: readonly Node[], read: () => T): T;
46
- private assignedIn;
98
+ assignedIn(body: Node, includeMemberWrites?: boolean): ReadonlySet<string>;
47
99
  private withBound;
48
100
  /**
49
101
  * Binds the names of a parameter or a loop variable to the parts of `value` they take, as destructuring does. A
@@ -58,7 +110,7 @@ export declare class Values {
58
110
  */
59
111
  declarationOf(name: string, scopes: readonly Node[]): Node | null;
60
112
  /**
61
- * The function a name is declared as, with `function name() {}` or a variable holding one; null for any other name.
113
+ * The local function a name refers to, including one reached through a constant alias.
62
114
  * A parameter is not its function, though the function declares it.
63
115
  */
64
116
  functionOf(name: string, scopes: readonly Node[]): FunctionNode | null;
@@ -68,7 +120,7 @@ export declare class Values {
68
120
  scopes: readonly Node[];
69
121
  } | null;
70
122
  /** The value a `const` name is declared with, and the scopes around that declaration; null for any other name. */
71
- constantOf(name: string, scopes: readonly Node[]): {
123
+ constantOf(name: string, scopes: readonly Node[], unchanged?: boolean): {
72
124
  init: Expression;
73
125
  scopes: readonly Node[];
74
126
  } | null;
@@ -81,25 +133,25 @@ export declare class Values {
81
133
  * call being walked, or a value of the case or pass of an expansion.
82
134
  */
83
135
  isBound(name: string, scopes: readonly Node[]): boolean;
84
- /** Whether a name refers to a function or class declared in the file. */
85
- isFunction(name: string, scopes: readonly Node[]): boolean;
136
+ /** A local function's name. Bun reads the declared name and receives undefined for an unnamed function. */
137
+ functionName(expression: Expression, scopes: readonly Node[], bun?: {
138
+ inferStaticFieldNames: boolean;
139
+ }): Resolved | null;
86
140
  private propertyKey;
87
141
  /**
88
142
  * The calls titles are often built with, all of them pure: `Object.keys()`, `Object.values()`, `Object.entries()`,
89
143
  * `JSON.stringify()` with one argument, `String()`, and a string's `toUpperCase()`, `toLowerCase()` and `trim()` and
90
144
  * an array's `join()`.
91
145
  */
92
- private call;
146
+ builtinCall(expression: CallExpression, scopes: readonly Node[], read: (operand: Expression) => Resolved): Resolved;
93
147
  /** Whether a name refers to a global, as no scope around the use declares it. */
94
148
  private isGlobal;
95
149
  /** `data.name` where `data` is `import * as data`: what the module exports as `name`; null for any other member. */
96
150
  private namespaceMember;
97
- /**
98
- * A property of an object written out in a constant the module keeps, worked out alone, as `TITLES.fill` in
99
- * `const TITLES = { fill: 'fills a limit order', format: (venue) => venue }`, whatever its other values are. Null when
100
- * a spread, a key the scan can't work out, or a getter or method of that name may hold it.
101
- */
102
- private ownProperty;
151
+ /** A local data property, in the scope where its value was defined. */
152
+ private dataProperty;
153
+ /** Methods are installed first. Static fields and blocks can then replace them, in source order. */
154
+ private classProperty;
103
155
  private imported;
104
156
  /**
105
157
  * How many items a list has when not all its values are known, as `[NaN, Infinity]`: a list written out, its spreads
@@ -115,6 +167,7 @@ export declare class Values {
115
167
  resolveName(name: string, scopes: readonly Node[]): Resolved;
116
168
  /** A parameter of a function read at one of its calls: the argument given there. */
117
169
  private resolveParameter;
170
+ private boundValue;
118
171
  /** Names the module changes while it loads, as in `WATCHED.push('MSFT')`, whose declared value isn't the one used. */
119
172
  private changedAtLoad;
120
173
  private resolveConstant;
@@ -127,4 +180,5 @@ export declare class Values {
127
180
  * Names assigned to or changed anywhere in `body`, its functions included: `x = ...`, `x++`, `[x] = ...`,
128
181
  * `for (x of ...)`, `x.push(...)`.
129
182
  */
130
- export declare function assignedNames(body: Node): Set<string>;
183
+ export declare function assignedNames(body: Node, includeMemberWrites?: boolean): Set<string>;
184
+ export {};