test-inventory 0.10.4 → 0.11.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +6 -4
  3. package/dist/cli.d.ts +7 -4
  4. package/dist/cli.js +18 -6
  5. package/dist/config-runs.d.ts +30 -4
  6. package/dist/config-runs.js +193 -38
  7. package/dist/config.d.ts +7 -6
  8. package/dist/config.js +260 -26
  9. package/dist/dependency-hash.d.ts +9 -1
  10. package/dist/dependency-hash.js +128 -13
  11. package/dist/diff.js +7 -2
  12. package/dist/extract.js +75 -17
  13. package/dist/files.js +2 -1
  14. package/dist/filter.js +1 -0
  15. package/dist/framework-version.d.ts +6 -0
  16. package/dist/framework-version.js +37 -9
  17. package/dist/frameworks/bindings.d.ts +9 -0
  18. package/dist/frameworks/bindings.js +28 -5
  19. package/dist/frameworks/bun.js +2 -2
  20. package/dist/frameworks/common.d.ts +12 -3
  21. package/dist/frameworks/common.js +30 -12
  22. package/dist/frameworks/jasmine.js +11 -3
  23. package/dist/frameworks/jest.js +11 -7
  24. package/dist/frameworks/mocha.js +3 -3
  25. package/dist/frameworks/node.js +6 -4
  26. package/dist/frameworks/playwright.d.ts +11 -3
  27. package/dist/frameworks/playwright.js +101 -32
  28. package/dist/frameworks/test-functions.d.ts +13 -7
  29. package/dist/frameworks/test-functions.js +41 -27
  30. package/dist/frameworks/vitest.js +11 -6
  31. package/dist/imported-values.js +12 -3
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +1 -0
  34. package/dist/model.d.ts +4 -1
  35. package/dist/node-scripts.d.ts +15 -1
  36. package/dist/node-scripts.js +140 -13
  37. package/dist/parse.d.ts +3 -0
  38. package/dist/parse.js +33 -0
  39. package/dist/records.js +7 -4
  40. package/dist/resolve.d.ts +3 -1
  41. package/dist/resolve.js +48 -15
  42. package/dist/run-commands.d.ts +20 -0
  43. package/dist/run-commands.js +107 -0
  44. package/dist/scan.js +15 -5
  45. package/dist/types.d.ts +9 -1
  46. package/dist/values.d.ts +25 -4
  47. package/dist/values.js +131 -22
  48. package/package.json +15 -7
  49. package/schema/diff-v1.json +12 -1
  50. package/schema/v1.json +9 -1
package/dist/resolve.js CHANGED
@@ -4,11 +4,12 @@ import path from 'node:path';
4
4
  import { globSync } from 'tinyglobby';
5
5
  const EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs'];
6
6
  const TYPESCRIPT_SOURCE = /(?<!\.d)\.[cm]?tsx?$/;
7
+ const JAVASCRIPT = /\.[cm]?jsx?$/;
7
8
  function isFile(file) {
8
9
  return existsSync(file) && statSync(file).isFile();
9
10
  }
10
11
  /** The file a path refers to, found the way TypeScript and Node do: as is, with an extension, or a folder's index. */
11
- function findFile(base) {
12
+ export function findFile(base) {
12
13
  const stripped = base.replace(/\.(?:[cm]?js|jsx)$/, '');
13
14
  const candidates = [
14
15
  base,
@@ -193,7 +194,10 @@ function aliasFiles(specifier, options) {
193
194
  return null;
194
195
  return targetStrings(options.paths[match.key]).map((target) => path.resolve(options.pathsBase, target.replaceAll('${configDir}', options.configDir).replaceAll('*', match.star)));
195
196
  }
196
- /** Files a `#name` import may stand for, from `imports` in the nearest package.json. */
197
+ /**
198
+ * Files a `#name` import may stand for, from `imports` in the nearest package.json. A target in build output is taken
199
+ * from the source next to it first, as for a workspace package.
200
+ */
197
201
  function subpathImportFiles(specifier, directory) {
198
202
  for (let folder = directory;; folder = path.dirname(folder)) {
199
203
  const manifest = readJson(path.join(folder, 'package.json'));
@@ -202,7 +206,10 @@ function subpathImportFiles(specifier, directory) {
202
206
  const match = imports ? matchPattern(Object.keys(imports), specifier) : null;
203
207
  if (!match || !imports)
204
208
  return [];
205
- return targetStrings(imports[match.key]).map((target) => path.resolve(folder, target.replaceAll('*', match.star)));
209
+ return targetStrings(imports[match.key]).flatMap((target) => {
210
+ const filled = target.replaceAll('*', match.star);
211
+ return [...sourceOf(filled), filled].map((file) => path.resolve(folder, file));
212
+ });
206
213
  }
207
214
  if (path.dirname(folder) === folder)
208
215
  return [];
@@ -212,19 +219,27 @@ const BUILD_FOLDERS = new Set(['dist', 'build', 'lib', 'out']);
212
219
  const FORMAT_FOLDERS = new Set(['esm', 'cjs', 'es', 'mjs', 'umd', 'types']);
213
220
  /**
214
221
  * Where the TypeScript source of a built file usually is, for a workspace package that hasn't been built: both
215
- * `dist/esm/index.js` and `dist/types/index.d.ts` come from `src/index.ts`.
222
+ * `dist/esm/index.js` and `dist/types/index.d.ts` come from `src/index.ts`, or from `index.ts` in a package without a
223
+ * `src` folder.
216
224
  */
217
225
  function sourceOf(target) {
218
226
  const parts = target.replace(/^\.\//, '').split('/');
219
227
  if (parts.length < 2 || !BUILD_FOLDERS.has(parts[0]))
220
228
  return [];
221
229
  const rest = parts.length > 2 && FORMAT_FOLDERS.has(parts[1]) ? parts.slice(2) : parts.slice(1);
222
- const base = ['src', ...rest].join('/').replace(/(\.d)?\.[cm]?[jt]sx?$/, '');
223
- return [`${base}.ts`, `${base}.tsx`];
230
+ const base = rest.join('/').replace(/(\.d)?\.[cm]?[jt]sx?$/, '');
231
+ return [`src/${base}.ts`, `src/${base}.tsx`, `${base}.ts`, `${base}.tsx`];
232
+ }
233
+ /** Whether a path in a package is in a folder builds write to, as `dist/index.js` and `esm/index.js` are. */
234
+ function isBuilt(target) {
235
+ const first = target.replace(/^\.[\\/]/, '').split(/[\\/]/)[0];
236
+ return BUILD_FOLDERS.has(first) || FORMAT_FOLDERS.has(first);
224
237
  }
225
238
  /**
226
- * The TypeScript source a package's exports, types or main point to for a subpath such as `.` or `./fixtures`. When they
227
- * point to build output, the source next to it is used, as in a workspace package that hasn't been built.
239
+ * The source a package's exports, types or main point to for a subpath such as `.` or `./fixtures`: TypeScript first,
240
+ * then JavaScript outside build folders, which a package written in JavaScript runs as it is. When they point to build
241
+ * output, the source next to it is used, as in a workspace package that hasn't been built; built JavaScript itself is
242
+ * not followed, as a change to its source would not reach it until the next build.
228
243
  */
229
244
  function packageEntry(folder, subpath) {
230
245
  const manifest = readJson(path.join(folder, 'package.json'));
@@ -236,17 +251,26 @@ function packageEntry(folder, subpath) {
236
251
  const match = matchPattern(Object.keys(map), subpath);
237
252
  targets = match ? targetStrings(map[match.key]).map((target) => target.replaceAll('*', match.star)) : [];
238
253
  }
254
+ else if (exports === undefined && subpath !== '.') {
255
+ // Without exports, a subpath is a file in the package, as `@trading/test-utils/src/fixtures.ts` is.
256
+ const file = findFile(path.resolve(folder, subpath));
257
+ targets = [file ? path.relative(folder, file) : subpath];
258
+ }
239
259
  else {
240
260
  targets = subpath === '.' ? targetStrings(exports) : [];
241
261
  }
242
262
  if (subpath === '.')
243
263
  targets.push(...targetStrings(manifest?.types), ...targetStrings(manifest?.main));
244
- const file = [...targets.filter((target) => TYPESCRIPT_SOURCE.test(target)), ...targets.flatMap(sourceOf)]
264
+ const file = [
265
+ ...targets.filter((target) => TYPESCRIPT_SOURCE.test(target)),
266
+ ...targets.flatMap(sourceOf),
267
+ ...targets.filter((target) => JAVASCRIPT.test(target) && !isBuilt(target)),
268
+ ]
245
269
  .map((target) => path.resolve(folder, target))
246
270
  .find(isFile);
247
271
  return file
248
272
  ? { file }
249
- : { reason: "is a workspace package whose exports, types and main don't point to TypeScript source" };
273
+ : { reason: "is a workspace package whose exports, types and main don't point to source code" };
250
274
  }
251
275
  /**
252
276
  * The `packages` list of a pnpm-workspace.yaml, as a block list or a flow list. The file holds little more than this
@@ -303,7 +327,7 @@ function workspaceAt(folder) {
303
327
  return packages;
304
328
  }
305
329
  /**
306
- * A workspace package followed to its TypeScript source: through its link in node_modules, or, before an install, from
330
+ * A workspace package followed to its source: through its link in node_modules, or, before an install, from
307
331
  * the packages the workspace lists. A package installed from a registry is not followed.
308
332
  */
309
333
  function workspaceSource(specifier, directory, packagesOf) {
@@ -323,6 +347,8 @@ function workspaceSource(specifier, directory, packagesOf) {
323
347
  const local = packagesOf(directory).get(name);
324
348
  return local ? packageEntry(local, subpath) : null;
325
349
  }
350
+ /** Why a bare name is not followed when it is no local file: it is taken to be an installed package. */
351
+ const NOT_LOCAL = 'is not a local file, a path alias or a workspace package';
326
352
  /** A file a bare name stands for in the folders an import map adds; null when none has it. */
327
353
  function searched(specifier, directory, map) {
328
354
  const folders = [...map.paths];
@@ -352,7 +378,7 @@ function mapped(specifier, alias) {
352
378
  /**
353
379
  * Returns a reader for the modules a test file imports. It follows the import map of the config the file runs with,
354
380
  * relative paths, tsconfig `paths` and `baseUrl` from the tsconfig nearest the importing file, package.json `imports`
355
- * (`#name`), and workspace packages whose entry is TypeScript source. Each module it reads carries a reader for the
381
+ * (`#name`), and workspace packages to their source. Each module it reads carries a reader for the
356
382
  * modules that module imports in turn, with the same import map.
357
383
  */
358
384
  export function moduleResolver(root) {
@@ -422,7 +448,7 @@ export function moduleResolver(root) {
422
448
  return { reason: targets ? 'could not be read' : 'is a path alias that no tsconfig paths or config define' };
423
449
  }
424
450
  if (!file)
425
- return { reason: 'is not a local file, a path alias or a workspace package' };
451
+ return { reason: NOT_LOCAL };
426
452
  candidates = [file];
427
453
  }
428
454
  }
@@ -432,7 +458,8 @@ export function moduleResolver(root) {
432
458
  const shown = (name) => (path.isAbsolute(name) ? path.relative(root, name).replaceAll('\\', '/') : name);
433
459
  const reader = (fromFile, map = null) => (specifier) => {
434
460
  const directory = path.dirname(fromFile);
435
- const aliased = map?.aliases.map((alias) => mapped(specifier, alias)).find((names) => names !== null);
461
+ const alias = map?.aliases.find((item) => mapped(specifier, item) !== null);
462
+ const aliased = alias && mapped(specifier, alias);
436
463
  if (aliased?.length === 0)
437
464
  return { reason: 'has a config alias whose replacement could not be worked out' };
438
465
  // Vite takes `/src/x` from its root first, unless it is already a path inside the root.
@@ -443,9 +470,15 @@ export function moduleResolver(root) {
443
470
  const located = (aliased?.flatMap(fromRoot) ?? [specifier]).map((name) => locate(name, directory, map));
444
471
  const found = located.find((item) => typeof item === 'string');
445
472
  if (found === undefined) {
473
+ const reasons = located;
474
+ // Jest resolves what moduleNameMapper gives as it does an import, so a package there, as next/jest's mocks or
475
+ // `identity-obj-proxy`, is left out as an imported package is.
476
+ const isPackage = alias?.replacesName && reasons.some((item) => item.reason === NOT_LOCAL);
477
+ if (isPackage)
478
+ return { reason: NOT_LOCAL };
446
479
  return aliased
447
480
  ? { reason: `is mapped by the config to ${aliased.map(shown).join(' or ')}, which could not be read` }
448
- : located[0];
481
+ : reasons[0];
449
482
  }
450
483
  let known = modules.get(map);
451
484
  if (!known) {
@@ -0,0 +1,20 @@
1
+ import type { Inventory } from './types.ts';
2
+ /** A command line that runs some test files of an inventory with their runner, config and projects. */
3
+ export interface RunCommand {
4
+ /** The config the files run with, from the project root; null when the scan found none. */
5
+ config: string | null;
6
+ /** The projects of the config that run the files, as the command selects them; `[]` to run every project. */
7
+ projects: string[];
8
+ /** The test files, sorted. */
9
+ files: string[];
10
+ /** The command line, to run from the project root in a POSIX shell. */
11
+ command: string;
12
+ /** What the command runs beyond `files` or why it can't run them as it is; null otherwise. */
13
+ caveat: string | null;
14
+ }
15
+ /**
16
+ * The commands that run the tests an inventory keeps, as after `filterInventory()` with `related`: one for each config,
17
+ * and for Cypress one for each testing type, with the projects that run the tests, sorted by config. A test whose
18
+ * projects are unknown runs in every project of its config.
19
+ */
20
+ export declare function runCommands(inventory: Inventory): RunCommand[];
@@ -0,0 +1,107 @@
1
+ /** An argument as a POSIX shell reads it back: quoted when it holds anything but plain path characters. */
2
+ function quote(argument) {
3
+ return /^[\w./@:+=,-]+$/.test(argument) ? argument : `'${argument.replaceAll("'", "'\\''")}'`;
4
+ }
5
+ /** The arguments of the command for one runner, and its caveat. */
6
+ function commandFor(framework, config, projects, files) {
7
+ const withConfig = (flag) => (config === null ? [] : [flag, config]);
8
+ switch (framework) {
9
+ case 'vitest':
10
+ return {
11
+ args: [
12
+ 'npx',
13
+ 'vitest',
14
+ 'run',
15
+ ...files,
16
+ ...withConfig('--config'),
17
+ ...projects.flatMap((p) => ['--project', p]),
18
+ ],
19
+ caveat: null,
20
+ };
21
+ case 'jest': {
22
+ const selected = projects.length > 0 ? ['--selectProjects', ...projects] : [];
23
+ return {
24
+ args: ['npx', 'jest', ...withConfig('--config'), ...selected, '--runTestsByPath', ...files],
25
+ caveat: null,
26
+ };
27
+ }
28
+ case 'playwright': {
29
+ // `--project` takes every name after it, so the files come first.
30
+ const selected = projects.length > 0 ? ['--project', ...projects] : [];
31
+ return { args: ['npx', 'playwright', 'test', ...files, ...withConfig('--config'), ...selected], caveat: null };
32
+ }
33
+ case 'mocha':
34
+ return {
35
+ args: ['npx', 'mocha', ...withConfig(config?.endsWith('package.json') ? '--package' : '--config'), ...files],
36
+ caveat: config === null
37
+ ? null
38
+ : 'Mocha adds the files to the spec of the config, so every spec the config lists runs too.',
39
+ };
40
+ case 'jasmine':
41
+ return { args: ['npx', 'jasmine', ...(config === null ? [] : [`--config=${config}`]), ...files], caveat: null };
42
+ case 'cypress':
43
+ return {
44
+ args: [
45
+ 'npx',
46
+ 'cypress',
47
+ 'run',
48
+ ...withConfig('--config-file'),
49
+ ...(projects.includes('component') ? ['--component'] : []),
50
+ '--spec',
51
+ files.join(','),
52
+ ],
53
+ caveat: null,
54
+ };
55
+ case 'webdriverio':
56
+ return {
57
+ args: [
58
+ 'npx',
59
+ 'wdio',
60
+ 'run',
61
+ ...(config === null ? [] : [config]),
62
+ ...files.flatMap((file) => ['--spec', file]),
63
+ ],
64
+ caveat: config === null
65
+ ? "No WebdriverIO config was found, and 'wdio run' needs one, as in 'npx wdio run wdio.conf.ts'."
66
+ : null,
67
+ };
68
+ case 'node':
69
+ // node --test reads each argument as a glob; a character in brackets stands for itself.
70
+ return { args: ['node', '--test', ...files.map((file) => file.replace(/[[\]*?{}]/g, '[$&]'))], caveat: null };
71
+ case 'bun':
72
+ // Without `./`, Bun takes an argument as part of a name to look for.
73
+ return { args: ['bun', 'test', ...files.map((file) => `./${file}`)], caveat: null };
74
+ }
75
+ }
76
+ /**
77
+ * The commands that run the tests an inventory keeps, as after `filterInventory()` with `related`: one for each config,
78
+ * and for Cypress one for each testing type, with the projects that run the tests, sorted by config. A test whose
79
+ * projects are unknown runs in every project of its config.
80
+ */
81
+ export function runCommands(inventory) {
82
+ const configs = new Map(inventory.files.map((file) => [file.relativeFilePath, file.config]));
83
+ const groups = new Map();
84
+ for (const test of inventory.tests) {
85
+ const config = configs.get(test.relativeFilePath) ?? null;
86
+ // Cypress runs one testing type at a time.
87
+ const type = inventory.framework === 'cypress' ? (test.projects?.join(',') ?? '') : '';
88
+ const key = `${config ?? ''}\0${type}`;
89
+ const group = groups.get(key) ?? { config, files: new Set(), projects: new Set(), all: false };
90
+ groups.set(key, group);
91
+ group.files.add(test.relativeFilePath);
92
+ if (test.projects === null)
93
+ group.all = true;
94
+ // A config without projects has one with an empty name, which no flag selects.
95
+ for (const name of test.projects ?? [])
96
+ if (name !== '')
97
+ group.projects.add(name);
98
+ }
99
+ return [...groups.entries()]
100
+ .sort(([a], [b]) => (a < b ? -1 : 1))
101
+ .map(([, group]) => {
102
+ const projects = group.all ? [] : [...group.projects].sort();
103
+ const files = [...group.files].sort();
104
+ const { args, caveat } = commandFor(inventory.framework, group.config, projects, files);
105
+ return { config: group.config, projects, files, command: args.map(quote).join(' '), caveat };
106
+ });
107
+ }
package/dist/scan.js CHANGED
@@ -10,7 +10,7 @@ import { DependencyGraph } from "./dependency-hash.js";
10
10
  import { ExportedValues } from "./imported-values.js";
11
11
  import { fileDiagnostic } from "./diagnostics.js";
12
12
  import { findFiles, normalizePattern, readFailure } from "./files.js";
13
- import { detectFramework, detectFrameworkVersion, FRAMEWORK_NAMES, OLDEST } from "./framework-version.js";
13
+ import { configFolderBelow, detectFramework, detectFrameworkVersion, FRAMEWORK_NAMES, OLDEST, } from "./framework-version.js";
14
14
  import { createInventory } from "./inventory.js";
15
15
  import { checkComments, checkFlag, checkFramework, checkObject, checkSignal, checkStrings, checkVersion, invalid, majorMinor, toPosixPath, } from "./options.js";
16
16
  import { moduleResolver } from "./resolve.js";
@@ -121,7 +121,7 @@ function bytesOf(root, file) {
121
121
  }
122
122
  }
123
123
  /** Why a scan found no test files: what the patterns matched, or whether there is a config to find them from. */
124
- function noFiles(root, patterns, framework, placements) {
124
+ function noFiles(root, patterns, framework, placements, ignore) {
125
125
  if (patterns) {
126
126
  const list = patterns.map((pattern) => `"${pattern}"`).join(', ');
127
127
  return `No test files match ${list} in the root.${folderHint(root, patterns, framework)}`;
@@ -133,7 +133,12 @@ function noFiles(root, patterns, framework, placements) {
133
133
  return "No patterns were given, and no file in the root matches what node --test runs: Node.js's default patterns, or the files a package.json script gives it.";
134
134
  }
135
135
  const name = FRAMEWORK_NAMES[framework];
136
- return `No patterns were given, and no ${name} config is in the root or a folder below it, so there are no test files to find.`;
136
+ const below = configFolderBelow(root, framework, ignore);
137
+ if (below === undefined) {
138
+ return `No patterns were given, and no ${name} config is in the root or a folder below it, so there are no test files to find.`;
139
+ }
140
+ const none = `No patterns were given, and no ${name} config is in the root, the only place the scan reads it from, so there are no test files to find.`;
141
+ return below === null ? none : `${none} There is one in ${below}: scan that folder, or give patterns.`;
137
142
  }
138
143
  /**
139
144
  * Scans the test files that match `patterns` under `root`, or without patterns those the configs run, one file at a
@@ -179,7 +184,12 @@ export async function scan(options) {
179
184
  const configs = new Configs(root, framework, readerFor, rules);
180
185
  const runs = new ConfigRuns(configs, framework, rules, patterns === null);
181
186
  const placements = new Map(found.files.map((file) => [file.absolutePath, runs.placementOf(file.absolutePath)]));
182
- const files = patterns ? found.files : found.files.filter((file) => placements.get(file.absolutePath)?.runs);
187
+ const files = patterns
188
+ ? found.files
189
+ : found.files.filter((file) => {
190
+ const placement = placements.get(file.absolutePath);
191
+ return Boolean(placement.runs) || placement.candidate === true;
192
+ });
183
193
  // A setup project's files may be outside the patterns, or ignored for the scan, so they are looked for in its testDir.
184
194
  const setupDirs = new Set();
185
195
  for (const { config, projects } of placements.values()) {
@@ -286,7 +296,7 @@ export async function scan(options) {
286
296
  projectDiagnostics.push(...configs.diagnostics, ...neverRun, ...(globals ? [globals] : []));
287
297
  // After the config warnings, which may say why no file was found.
288
298
  if (files.length === 0) {
289
- projectDiagnostics.push(fileDiagnostic('no-files-matched', '.', noFiles(root, patterns, framework, placements)));
299
+ projectDiagnostics.push(fileDiagnostic('no-files-matched', '.', noFiles(root, patterns, framework, placements, ignore)));
290
300
  }
291
301
  const fileCount = files.length;
292
302
  const records = configs.records((config) => runs.projectsIn(config));
package/dist/types.d.ts CHANGED
@@ -261,7 +261,10 @@ export interface SuiteRecord {
261
261
  export interface TestRecord {
262
262
  /** Derived from the file path, the describe titles, the title and its position among tests with the same title. */
263
263
  id: Hash;
264
- /** Hash of the test body, ignoring whitespace and comments; null when the test has no body. */
264
+ /**
265
+ * Hash of the test body, ignoring whitespace and comments: the test function, one passed by name, or the one a wrapper
266
+ * call receives; null when the test has none of these.
267
+ */
265
268
  bodyHash: Hash | null;
266
269
  /**
267
270
  * Hash of everything the test runs in the project: its call, the hooks, options and code of the file and of every
@@ -273,6 +276,11 @@ export interface TestRecord {
273
276
  dependencies: string[];
274
277
  /** Something the test reaches couldn't be followed, so a change there doesn't change `dependencyHash`. */
275
278
  hasUnfollowedDependencies: boolean;
279
+ /**
280
+ * Where the test reaches what couldn't be followed: the file and line of each place, as `support/venues.ts:2`, sorted;
281
+ * empty when `hasUnfollowedDependencies` is false. A `dependency-not-followed` warning at the place says what it is.
282
+ */
283
+ unfollowedDependencies: string[];
276
284
  /** The nearest describe; null outside any describe. */
277
285
  suiteId: Hash | null;
278
286
  /**
package/dist/values.d.ts CHANGED
@@ -3,13 +3,14 @@ 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 value worked out from the file, or the reason it could not be. `importedFrom` names the module it came from. */
6
+ /** A resolved value or a failed lookup. `arrayLength` can record the size of an imported array with unknown items. */
7
7
  export type Resolved = {
8
8
  ok: true;
9
9
  value: Value;
10
10
  } | {
11
11
  ok: false;
12
12
  importedFrom: string | null;
13
+ arrayLength?: number;
13
14
  };
14
15
  /** What another module exports under a name, `default` included, for an import of the file. */
15
16
  export type ImportReader = (source: string, name: string) => Resolved;
@@ -32,10 +33,11 @@ export declare class Values {
32
33
  /**
33
34
  * Runs `read` with a function's parameters bound to the arguments of one call, worked out where the call is, so that
34
35
  * titles and values built from them resolve, as in `test(\`${side} rejects a zero quantity\`)` inside
35
- * `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known. A missing argument
36
- * takes the parameter's default value, worked out in `scopes`, the scopes around the function.
36
+ * `validatesQuantity('buy')`. `args` stop at a spread argument, after which no position is known, and `complete` is
37
+ * 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.
37
39
  */
38
- withArguments<T>(fn: FunctionNode, args: readonly Resolved[], scopes: readonly Node[], read: () => T): T;
40
+ withArguments<T>(fn: FunctionNode, args: readonly Resolved[], scopes: readonly Node[], read: () => T, complete?: boolean): T;
39
41
  /**
40
42
  * Runs `read` with the names a loop declares bound to one of the values it goes over, as in
41
43
  * `for (const [tier, bps] of Object.entries(FEES))`. `declarator` is the loop's variable declarator.
@@ -60,6 +62,11 @@ export declare class Values {
60
62
  * A parameter is not its function, though the function declares it.
61
63
  */
62
64
  functionOf(name: string, scopes: readonly Node[]): FunctionNode | null;
65
+ /** `functionOf()`, with the scopes around the function's declaration, in which its body is read. */
66
+ functionWithScopes(name: string, scopes: readonly Node[]): {
67
+ fn: FunctionNode;
68
+ scopes: readonly Node[];
69
+ } | null;
63
70
  /** The value a `const` name is declared with, and the scopes around that declaration; null for any other name. */
64
71
  constantOf(name: string, scopes: readonly Node[]): {
65
72
  init: Expression;
@@ -87,6 +94,12 @@ export declare class Values {
87
94
  private isGlobal;
88
95
  /** `data.name` where `data` is `import * as data`: what the module exports as `name`; null for any other member. */
89
96
  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;
90
103
  private imported;
91
104
  /**
92
105
  * How many items a list has when not all its values are known, as `[NaN, Infinity]`: a list written out, its spreads
@@ -94,6 +107,8 @@ export declare class Values {
94
107
  * null otherwise. `seen` stops at a constant defined through itself.
95
108
  */
96
109
  lengthOf(node: Expression, scopes: readonly Node[], seen?: Set<string>): number | null;
110
+ /** How many items a named array holds, including a project import whose values are unknown. */
111
+ lengthOfName(name: string, scopes: readonly Node[], seen?: Set<string>): number | null;
97
112
  /** How many keys an object written out has, held in a constant the module doesn't change; null otherwise. */
98
113
  private keyCount;
99
114
  /** What a name refers to where it is used; `scopes` lists the scope nodes around the use, outermost first. */
@@ -104,6 +119,12 @@ export declare class Values {
104
119
  private changedAtLoad;
105
120
  private resolveConstant;
106
121
  private enumMembers;
122
+ /** A name's binding, and the scopes from the outermost to the one that declares it. */
107
123
  private lookup;
108
124
  private bindings;
109
125
  }
126
+ /**
127
+ * Names assigned to or changed anywhere in `body`, its functions included: `x = ...`, `x++`, `[x] = ...`,
128
+ * `for (x of ...)`, `x.push(...)`.
129
+ */
130
+ export declare function assignedNames(body: Node): Set<string>;