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
@@ -0,0 +1,632 @@
1
+ import { childNodes, isFunctionNode, unwrap } from "../ast.js";
2
+ import { literalArguments } from "../mutation-references.js";
3
+ import { isValueOperation, operationValue, } from "../values.js";
4
+ import { atLeast } from "./common.js";
5
+ function completesWithoutThrowing(node) {
6
+ if (node.type === 'ClassExpression')
7
+ return !node.superClass && !node.decorators.length && !node.body.body.length;
8
+ if (node.type === 'AwaitExpression') {
9
+ // Await reads "then" from objects, including regex literals. A primitive literal always fulfills.
10
+ const operand = unwrap(node.argument);
11
+ return operand.type === 'Literal' && !('regex' in operand);
12
+ }
13
+ return node.type === 'Literal' || isFunctionNode(node);
14
+ }
15
+ /** Runtime function length excludes a TypeScript this parameter and ends at the first default or rest parameter. */
16
+ export function functionLength(fn) {
17
+ const params = fn.params.filter((param) => param.type !== 'Identifier' || param.name !== 'this');
18
+ const end = params.findIndex((param) => param.type === 'AssignmentPattern' || param.type === 'RestElement');
19
+ return end === -1 ? params.length : end;
20
+ }
21
+ const omitted = { ok: true, value: undefined };
22
+ const objectResult = { ok: false, importedFrom: null, defined: true, truthy: true };
23
+ const nonIterableObject = { ...objectResult, nonIterable: true };
24
+ /** Format descriptions whose conversion uses only standard methods, including each element in a nested array. */
25
+ function descriptionText(value) {
26
+ if (value === null || typeof value !== 'object')
27
+ return String(value ?? '');
28
+ if (!Array.isArray(value))
29
+ return value.toString === Object.prototype.toString ? '[object Object]' : undefined;
30
+ const parts = [];
31
+ for (const element of value) {
32
+ const text = descriptionText(element);
33
+ if (text === undefined)
34
+ return undefined;
35
+ parts.push(text);
36
+ }
37
+ return parts.join(',');
38
+ }
39
+ const owner = (scopes) => scopes.findLast((n) => n.type === 'FunctionDeclaration' || isFunctionNode(n));
40
+ export const isRuntimeFunction = (node) => node?.type === 'FunctionDeclaration' || isFunctionNode(node);
41
+ /** A hole supplies undefined. A spread of unknown width obscures this and all subsequent positions. */
42
+ function* spreadArguments(args, scopes, file, count, arrays = new Map()) {
43
+ for (const item of literalArguments(args)) {
44
+ if (item?.type !== 'SpreadElement') {
45
+ yield item ? { node: unwrap(item), scopes } : null;
46
+ continue;
47
+ }
48
+ const spread = unwrap(item.argument);
49
+ const source = spread.type === 'Identifier' && file.values.constantOf(spread.name, scopes, true);
50
+ const init = source && unwrap(source.init);
51
+ if (init && init.type === 'ArrayExpression') {
52
+ let positions = arrays.get(init);
53
+ if (!positions) {
54
+ // A circular initializer has unknown width. Cache just the positions the runner consumes.
55
+ arrays.set(init, [{ node: item, scopes }]);
56
+ positions = [];
57
+ for (const arg of spreadArguments(init.elements, source.scopes, file, count, arrays)) {
58
+ positions.push(arg);
59
+ if (positions.length === count)
60
+ break;
61
+ }
62
+ arrays.set(init, positions);
63
+ }
64
+ yield* positions;
65
+ continue;
66
+ }
67
+ const result = file.values.resolve(spread, scopes);
68
+ if (result.ok && (Array.isArray(result.value) || typeof result.value === 'string')) {
69
+ for (const value of result.value)
70
+ yield { node: spread, scopes, resolved: { ok: true, value } };
71
+ continue;
72
+ }
73
+ yield { node: item, scopes };
74
+ return;
75
+ }
76
+ }
77
+ export function jasmineArguments(args, scopes, file, count) {
78
+ const reader = spreadArguments(args, scopes, file, count);
79
+ const positions = [];
80
+ let current;
81
+ for (let index = 0; index < count; index++) {
82
+ if (current?.node.type !== 'SpreadElement')
83
+ current = reader.next().value;
84
+ positions.push(current);
85
+ }
86
+ return positions;
87
+ }
88
+ export function jasmineCallback(body, file) {
89
+ if (!body)
90
+ return { status: 'missing', binding: null };
91
+ const { node, scopes } = body;
92
+ if (node.type === 'SpreadElement')
93
+ return { status: 'unknown', binding: null };
94
+ const resolved = body.resolved ?? file.values.resolve(node, scopes);
95
+ if (resolved.ok)
96
+ return { status: resolved.value === undefined ? 'missing' : 'callback', binding: null };
97
+ const assigned = file.values.assignedIn(scopes[0], false);
98
+ const binding = isFunctionNode(node)
99
+ ? { fn: node, scopes }
100
+ : node.type === 'Identifier' && !assigned.has(node.name)
101
+ ? file.values.functionWithScopes(node.name, scopes)
102
+ : null;
103
+ if (binding || node.type === 'ClassExpression')
104
+ return { status: 'valid', binding };
105
+ // Jasmine's spec and suite declarations return objects which cannot serve as callbacks.
106
+ const callee = node.type === 'CallExpression' && unwrap(node.callee);
107
+ const registration = callee &&
108
+ callee.type === 'Identifier' &&
109
+ ['it', 'fit', 'xit', 'describe', 'fdescribe', 'xdescribe'].includes(callee.name) &&
110
+ !assigned.has(callee.name) &&
111
+ !file.values.declarationOf(callee.name, scopes);
112
+ const nonfunction = registration || ['Literal', 'ArrayExpression', 'ObjectExpression', 'TemplateLiteral'].includes(node.type);
113
+ return { status: nonfunction ? 'callback' : 'unknown', binding: null };
114
+ }
115
+ export function jasmineRegistration(read, limit, file, allowsPending) {
116
+ const missing = read.status === 'missing';
117
+ const fn = read.binding?.fn ?? null;
118
+ if (fn?.generator)
119
+ return { status: 'callback', fn: null, missing };
120
+ if (read.status === 'callback' || (missing && !allowsPending))
121
+ return { status: 'callback', fn, missing };
122
+ if (limit && atLeast(file.version, 3, 10)) {
123
+ if (limit.node.type === 'SpreadElement')
124
+ return { status: 'unknown', fn, missing };
125
+ const resolved = limit.resolved ?? file.values.resolve(limit.node, limit.scopes);
126
+ if (!resolved.ok)
127
+ return { status: 'unknown', fn, missing };
128
+ const value = resolved.value;
129
+ if (value !== null &&
130
+ typeof value === 'object' &&
131
+ !(Array.isArray(value) && value.every((item) => item === null || typeof item !== 'object')))
132
+ return { status: 'unknown', fn, missing };
133
+ if (Number(value) > 2147483647)
134
+ return { status: 'timeout', fn, missing };
135
+ }
136
+ return { status: read.status === 'unknown' ? 'unknown' : 'valid', fn, missing };
137
+ }
138
+ /** Evaluate the registration path and keep helper return values in their invocation's bindings. */
139
+ function registrationFlow(start, outer, file) {
140
+ const results = new Map();
141
+ function valueOf(expr, scopes) {
142
+ const node = unwrap(expr);
143
+ const result = results.get(node) ?? file.values.resolve(node, scopes);
144
+ if (!result.ok &&
145
+ (node.type === 'ObjectExpression' ||
146
+ node.type === 'ArrayExpression' ||
147
+ node.type === 'ClassExpression' ||
148
+ isFunctionNode(node) ||
149
+ (node.type === 'Literal' && 'regex' in node))) {
150
+ return objectResult;
151
+ }
152
+ return result;
153
+ }
154
+ // Helpers may recurse or call each other repeatedly. Exhausting this proof budget keeps the catch in the inventory.
155
+ let remaining = 256;
156
+ const active = [];
157
+ const parameters = [];
158
+ let collected = { values: [], complete: true };
159
+ const assigned = file.values.assignedIn(outer[0], false);
160
+ function argument(arg, scopes) {
161
+ const node = unwrap(arg);
162
+ if (node.type !== 'Identifier')
163
+ return { node, scopes };
164
+ const declaration = file.values.declarationOf(node.name, scopes);
165
+ if (declaration?.type === 'FunctionDeclaration' && !assigned.has(node.name)) {
166
+ const binding = file.values.functionWithScopes(node.name, scopes);
167
+ if (binding)
168
+ return { node: binding.fn, scopes: binding.scopes };
169
+ }
170
+ const constant = file.values.constantOf(node.name, scopes);
171
+ if (constant && declaration?.type === 'VariableDeclarator' && declaration.id.type === 'Identifier') {
172
+ // A helper can be called before a constant in its enclosing scope has been initialized.
173
+ const scope = constant.scopes[constant.scopes.length - 1];
174
+ const beforeUse = owner(scopes) === owner(constant.scopes) && constant.init.end < node.start;
175
+ const beforeTry = outer.includes(scope) && owner(outer) === owner(constant.scopes) && constant.init.end < start;
176
+ // An inline enclosing function could only be created after earlier statements in its block ran.
177
+ const inner = outer
178
+ .slice(outer.indexOf(scope) + 1)
179
+ .find((n) => n.type === 'FunctionDeclaration' || isFunctionNode(n));
180
+ const beforeClosure = outer.includes(scope) && isFunctionNode(inner) && constant.init.end < inner.start;
181
+ const beforeCall = constant.init.end <= (active.findLast((entry) => entry.block === scope)?.at ?? -1);
182
+ if ((scope.type === 'Program' || scope.type === 'BlockStatement') &&
183
+ (beforeUse || beforeTry || beforeClosure || beforeCall))
184
+ return { node: unwrap(constant.init), scopes: constant.scopes };
185
+ }
186
+ return undefined;
187
+ }
188
+ function invoke(fn, definition, children, args = [], complete = true, site, yielded) {
189
+ const body = fn.body;
190
+ const steps = new Map();
191
+ const initialized = new Set();
192
+ const inside = [...definition, fn];
193
+ function bind(node) {
194
+ const step = steps.get(node);
195
+ if (step === 'throw')
196
+ return 'throw';
197
+ if (step === null)
198
+ return 'unknown';
199
+ if (node.type === 'Identifier') {
200
+ initialized.add(node.name);
201
+ return 'next';
202
+ }
203
+ if (node.type === 'AssignmentPattern') {
204
+ const outcome = step ? expression(node.right, inside, children) : 'next';
205
+ return outcome === 'next' ? bind(node.left) : outcome;
206
+ }
207
+ if (node.type === 'Property') {
208
+ if (node.computed) {
209
+ const computed = node.key;
210
+ const outcome = expression(computed, inside, children);
211
+ if (outcome !== 'next')
212
+ return outcome;
213
+ const key = file.values.resolve(computed, inside);
214
+ if (!key.ok || (key.value !== null && typeof key.value === 'object'))
215
+ return 'unknown';
216
+ }
217
+ return bind(node.value);
218
+ }
219
+ const parts = node.type === 'ObjectPattern'
220
+ ? node.properties
221
+ : node.type === 'ArrayPattern'
222
+ ? node.elements
223
+ : childNodes(node);
224
+ for (const part of parts) {
225
+ if (!part)
226
+ continue;
227
+ const result = bind(part);
228
+ if (result !== 'next')
229
+ return result;
230
+ }
231
+ return 'next';
232
+ }
233
+ return file.values.withArguments(fn, args, definition, () => {
234
+ parameters.push({ fn, initialized });
235
+ const previous = collected;
236
+ collected = yielded ?? previous;
237
+ let result = 'next';
238
+ for (const param of fn.params) {
239
+ result = bind(param);
240
+ if (result !== 'next')
241
+ break;
242
+ }
243
+ if (result === 'next' && (!fn.generator || yielded)) {
244
+ const end = body.type === 'BlockStatement' ? statement(body, inside, children) : expression(body, inside, children);
245
+ result = typeof end === 'object' ? 'next' : end;
246
+ if (site && result === 'next') {
247
+ const value = typeof end === 'object' ? end.returned : body.type === 'BlockStatement' ? omitted : valueOf(body, inside);
248
+ results.set(site, value);
249
+ }
250
+ }
251
+ collected = previous;
252
+ parameters.pop();
253
+ return result;
254
+ }, complete, steps);
255
+ }
256
+ function suite(fn, definition, plain) {
257
+ const children = { registered: false };
258
+ const result = invoke(fn, definition, children);
259
+ if (result === 'unknown')
260
+ return result;
261
+ if (children.registered !== true &&
262
+ atLeast(file.version, 4, plain ? 0 : 5) &&
263
+ !(result === 'throw' && atLeast(file.version, 4, 5)))
264
+ return children.registered === 'possible' ? 'unknown' : 'throw';
265
+ return 'next';
266
+ }
267
+ function call(node, scopes, children, iteration) {
268
+ const callee = unwrap(node.callee);
269
+ if (--remaining < 0)
270
+ return 'unknown';
271
+ const method = file.values.iteratorMethods.get(node);
272
+ if (method) {
273
+ const evaluated = elements(node.arguments, scopes, children);
274
+ if (evaluated !== 'next')
275
+ return evaluated;
276
+ if (method.registered === true)
277
+ children.registered = true;
278
+ else
279
+ children.registered ||= method.registered;
280
+ results.set(node, method.result);
281
+ return method.outcome;
282
+ }
283
+ if (callee.type === 'MemberExpression' ||
284
+ (callee.type === 'Identifier' &&
285
+ callee.name === 'String' &&
286
+ !assigned.has('String') &&
287
+ !file.values.declarationOf('String', scopes))) {
288
+ return evaluate(node, scopes, children, (read) => file.values.builtinCall(node, scopes, read));
289
+ }
290
+ const inline = isFunctionNode(callee);
291
+ if (!inline && (callee.type !== 'Identifier' || assigned.has(callee.name)))
292
+ return 'unknown';
293
+ const args = node.arguments;
294
+ if (inline || file.values.declarationOf(callee.name, scopes)) {
295
+ const helper = inline ? { node: callee, scopes } : argument(callee, scopes);
296
+ if (!helper || !isRuntimeFunction(helper.node))
297
+ return 'unknown';
298
+ const actual = { values: [], complete: true };
299
+ const evaluated = elements(args, scopes, children, actual);
300
+ if (evaluated !== 'next')
301
+ return evaluated;
302
+ if (helper.node.async && !helper.node.generator) {
303
+ // Its synchronous prefix may register a child. Errors in its parameters or body reject the returned promise.
304
+ children.registered ||= 'possible';
305
+ results.set(node, nonIterableObject);
306
+ return 'next';
307
+ }
308
+ if (iteration && helper.node.generator && !helper.node.async)
309
+ iteration.yielded = { values: [], complete: true };
310
+ const result = invoke(helper.node, helper.scopes, children, actual.values, actual.complete, node, iteration?.yielded);
311
+ if (helper.node.generator && result === 'next')
312
+ results.set(node, helper.node.async ? nonIterableObject : objectResult);
313
+ return result;
314
+ }
315
+ const name = callee.name;
316
+ const spec = ['it', 'xit', 'fit'].includes(name);
317
+ if (spec || ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].includes(name)) {
318
+ const evaluated = elements(args, scopes, children);
319
+ if (evaluated !== 'next')
320
+ return evaluated;
321
+ const positions = jasmineArguments(args, scopes, file, spec ? 3 : 2);
322
+ const index = spec ? 1 : 0;
323
+ const read = jasmineCallback(positions[index], file);
324
+ const { status } = jasmineRegistration(read, positions[index + 1], file, spec && name !== 'fit');
325
+ if (status === 'unknown')
326
+ return 'unknown';
327
+ if (status !== 'valid')
328
+ return 'throw';
329
+ if (spec)
330
+ children.registered = true;
331
+ results.set(node, spec ? nonIterableObject : omitted);
332
+ return 'next';
333
+ }
334
+ if (!['describe', 'xdescribe', 'fdescribe'].includes(name))
335
+ return 'unknown';
336
+ const evaluated = elements(args, scopes, children);
337
+ if (evaluated !== 'next')
338
+ return evaluated;
339
+ const [title, body] = jasmineArguments(args, scopes, file, 2);
340
+ const { status, binding: callback } = jasmineCallback(body, file);
341
+ if (status === 'missing' || status === 'callback')
342
+ return 'throw';
343
+ if (!callback || !isRuntimeFunction(callback.fn))
344
+ return 'unknown';
345
+ const fn = callback.fn;
346
+ const plain = name === 'describe';
347
+ if (fn.async || fn.generator || (plain && functionLength(fn) > 0))
348
+ return 'throw';
349
+ // An unresolved description may run user code when Jasmine formats it.
350
+ // Resolving the callback position has already established the width of preceding spreads.
351
+ if (title) {
352
+ const value = title.resolved ?? valueOf(title.node, title.scopes);
353
+ if (!value.ok || descriptionText(value.value) === undefined)
354
+ return 'unknown';
355
+ }
356
+ // Jasmine attaches the suite before running its callback and checking its children.
357
+ children.registered = true;
358
+ const result = suite(fn, callback.scopes, plain);
359
+ if (result === 'next')
360
+ results.set(node, nonIterableObject);
361
+ return result;
362
+ }
363
+ function spread(operand, scopes, children, out) {
364
+ const saved = file.values.iteratorSpreads.get(operand);
365
+ if (saved) {
366
+ if (saved.registered === true)
367
+ children.registered = true;
368
+ else
369
+ children.registered ||= saved.registered;
370
+ if (out.complete) {
371
+ for (const value of saved.values)
372
+ out.values.push(value);
373
+ out.complete = saved.complete;
374
+ }
375
+ return saved.outcome;
376
+ }
377
+ const iteration = {};
378
+ const result = expression(operand, scopes, children, iteration);
379
+ if (result !== 'next')
380
+ return result;
381
+ if (iteration.yielded) {
382
+ if (out.complete) {
383
+ for (const item of iteration.yielded.values)
384
+ out.values.push(item);
385
+ out.complete = iteration.yielded.complete;
386
+ }
387
+ return 'next';
388
+ }
389
+ const source = valueOf(operand, scopes);
390
+ if (source.ok) {
391
+ if (!Array.isArray(source.value) && typeof source.value !== 'string')
392
+ return 'throw';
393
+ if (out.complete)
394
+ for (const item of source.value)
395
+ out.values.push({ ok: true, value: item });
396
+ }
397
+ else {
398
+ if (source.nonIterable)
399
+ return 'throw';
400
+ if (unwrap(operand).type !== 'ArrayExpression' && file.values.lengthOf(operand, scopes) === null)
401
+ return 'unknown';
402
+ out.complete = false;
403
+ }
404
+ return 'next';
405
+ }
406
+ function elements(list, scopes, children, out = { values: [], complete: true }) {
407
+ const array = 'elements' in list;
408
+ for (const item of array ? list.elements : list) {
409
+ if (!item) {
410
+ if (out.complete)
411
+ out.values.push(omitted);
412
+ }
413
+ else if (item.type === 'SpreadElement') {
414
+ const result = spread(item.argument, scopes, children, out);
415
+ if (result !== 'next')
416
+ return result;
417
+ }
418
+ else {
419
+ const result = expression(item, scopes, children);
420
+ if (result !== 'next')
421
+ return result;
422
+ if (out.complete)
423
+ out.values.push(valueOf(item, scopes));
424
+ }
425
+ }
426
+ if (array)
427
+ results.set(list, out.complete && out.values.every((v) => v.ok)
428
+ ? { ok: true, value: out.values.map((v) => v.value) }
429
+ : objectResult);
430
+ return 'next';
431
+ }
432
+ function evaluate(node, scopes, children, compute) {
433
+ let failure = 'unknown';
434
+ const computed = compute((operand) => {
435
+ const outcome = expression(operand, scopes, children);
436
+ if (outcome === 'next')
437
+ return valueOf(operand, scopes);
438
+ failure = outcome;
439
+ return { ok: false, importedFrom: null };
440
+ });
441
+ results.set(node, computed);
442
+ return computed.ok || computed.truthy ? 'next' : failure;
443
+ }
444
+ function expression(node, scopes, children, iteration) {
445
+ const value = unwrap(node);
446
+ if (file.values.completedOperand(value, scopes))
447
+ return 'next';
448
+ if (value.type === 'ArrayExpression')
449
+ return elements(value, scopes, children);
450
+ if (value.type === 'ObjectExpression') {
451
+ for (const property of value.properties) {
452
+ if (property.type === 'SpreadElement') {
453
+ const outcome = expression(property.argument, scopes, children);
454
+ if (outcome !== 'next')
455
+ return outcome;
456
+ // Copying a property may invoke a getter on a source whose contents are unknown.
457
+ if (!valueOf(property.argument, scopes).ok)
458
+ return 'unknown';
459
+ }
460
+ else {
461
+ if (property.computed) {
462
+ const key = property.key;
463
+ const outcome = expression(key, scopes, children);
464
+ if (outcome !== 'next')
465
+ return outcome;
466
+ const resolved = valueOf(key, scopes);
467
+ if (!resolved.ok || (resolved.value !== null && typeof resolved.value === 'object'))
468
+ return 'unknown';
469
+ }
470
+ const outcome = expression(property.value, scopes, children);
471
+ if (outcome !== 'next')
472
+ return outcome;
473
+ }
474
+ }
475
+ return 'next';
476
+ }
477
+ if (value.type === 'MemberExpression' && file.values.resolve(value, scopes).ok) {
478
+ const object = expression(value.object, scopes, children);
479
+ return object === 'next' && value.computed ? expression(value.property, scopes, children) : object;
480
+ }
481
+ if (value.type === 'CallExpression')
482
+ return call(value, scopes, children, iteration);
483
+ if (value.type === 'YieldExpression') {
484
+ if (value.delegate)
485
+ return spread(value.argument, scopes, children, collected);
486
+ const result = value.argument ? expression(value.argument, scopes, children) : 'next';
487
+ if (result === 'next') {
488
+ if (collected.complete)
489
+ collected.values.push(value.argument ? valueOf(value.argument, scopes) : omitted);
490
+ // A synchronous spread advances the iterator without sending a value to the suspended yield.
491
+ results.set(value, omitted);
492
+ }
493
+ return result;
494
+ }
495
+ if (value.type === 'UnaryExpression' && value.operator === 'void')
496
+ return expression(value.argument, scopes, children);
497
+ if (isValueOperation(value))
498
+ return evaluate(value, scopes, children, (read) => operationValue(value, read));
499
+ if (value.type === 'Identifier') {
500
+ const declaration = file.values.declarationOf(value.name, scopes);
501
+ const binding = parameters.findLast((entry) => entry.fn === declaration);
502
+ if (binding)
503
+ return binding.initialized.has(value.name) ? 'next' : 'throw';
504
+ if (declaration &&
505
+ (declaration.type === 'FunctionDeclaration' || isFunctionNode(declaration)) &&
506
+ file.values.resolve(value, scopes).ok)
507
+ return 'next';
508
+ if ((!declaration && value.name === 'undefined') || argument(value, scopes))
509
+ return 'next';
510
+ }
511
+ return completesWithoutThrowing(value) ? 'next' : 'unknown';
512
+ }
513
+ function statement(node, scopes, children) {
514
+ if (--remaining < 0)
515
+ return 'unknown';
516
+ switch (node.type) {
517
+ case 'BlockStatement': {
518
+ const inside = [...scopes, node];
519
+ const entry = { block: node, at: node.start };
520
+ active.push(entry);
521
+ let result = 'next';
522
+ for (const child of node.body) {
523
+ entry.at = child.start;
524
+ result = statement(child, inside, children);
525
+ if (result !== 'next')
526
+ break;
527
+ }
528
+ active.pop();
529
+ return result;
530
+ }
531
+ case 'FunctionDeclaration':
532
+ case 'EmptyStatement':
533
+ return 'next';
534
+ case 'VariableDeclaration':
535
+ if (node.kind.endsWith('using'))
536
+ return 'unknown';
537
+ for (const { id, init } of node.declarations) {
538
+ if (id.type !== 'Identifier')
539
+ return 'unknown';
540
+ if (init) {
541
+ const outcome = expression(init, scopes, children);
542
+ if (outcome !== 'next')
543
+ return outcome;
544
+ }
545
+ }
546
+ return 'next';
547
+ case 'ExpressionStatement':
548
+ return expression(node.expression, scopes, children);
549
+ case 'ReturnStatement': {
550
+ const result = node.argument ? expression(node.argument, scopes, children) : 'next';
551
+ return result === 'next' ? { returned: node.argument ? valueOf(node.argument, scopes) : omitted } : result;
552
+ }
553
+ case 'ThrowStatement':
554
+ if (expression(node.argument, scopes, children) === 'unknown')
555
+ children.registered ||= 'possible';
556
+ return 'throw';
557
+ case 'IfStatement': {
558
+ const test = unwrap(node.test);
559
+ const declaration = test.type === 'Identifier' && file.values.declarationOf(test.name, scopes);
560
+ const bound = test.type === 'Identifier' &&
561
+ parameters.some((entry) => entry.fn === declaration && entry.initialized.has(test.name));
562
+ const literal = argument(test, scopes)?.node;
563
+ const guard = bound
564
+ ? file.values.resolve(test, scopes)
565
+ : literal?.type === 'Literal' && { ok: true, value: literal.value };
566
+ if (!guard || !guard.ok)
567
+ return 'unknown';
568
+ const arm = guard.value ? node.consequent : node.alternate;
569
+ return arm ? statement(arm, scopes, children) : 'next';
570
+ }
571
+ case 'TryStatement': {
572
+ let result = statement(node.block, scopes, children);
573
+ if (result === 'throw' && node.handler) {
574
+ if (node.handler.param && node.handler.param.type !== 'Identifier')
575
+ return 'unknown';
576
+ result = statement(node.handler.body, [...scopes, node.handler], children);
577
+ }
578
+ if (node.finalizer) {
579
+ if (result === 'unknown')
580
+ children.registered ||= 'possible';
581
+ const end = statement(node.finalizer, scopes, children);
582
+ if (end !== 'next')
583
+ return end;
584
+ }
585
+ return result;
586
+ }
587
+ default:
588
+ return 'unknown';
589
+ }
590
+ }
591
+ return { expression, statement, suite, valueOf, spread };
592
+ }
593
+ export function jasmineSpread(operand, scopes, file) {
594
+ const yielded = { values: [], complete: true };
595
+ const children = { registered: false };
596
+ const outcome = registrationFlow(operand.start, scopes, file).spread(operand, scopes, children, yielded);
597
+ return { ...yielded, registered: children.registered, outcome };
598
+ }
599
+ export function registrationExit(root, outer, file) {
600
+ const flow = registrationFlow('call' in root ? root.call.start : root.start, outer, file);
601
+ const end = 'call' in root
602
+ ? flow.suite(root.fn, root.definition, root.plain)
603
+ : flow.statement(root, outer, { registered: false });
604
+ return typeof end === 'object' ? 'return' : end;
605
+ }
606
+ /** Read a value at registration time, including the result of a synchronous local helper. */
607
+ export function jasmineValue(expression, scopes, file) {
608
+ const node = unwrap(expression);
609
+ const resolved = file.values.resolve(node, scopes);
610
+ if (!resolved.ok && (node.type === 'ArrayExpression' || node.type === 'CallExpression' || isValueOperation(node))) {
611
+ const flow = registrationFlow(node.start, scopes, file);
612
+ if (flow.expression(node, scopes, { registered: false }) === 'next')
613
+ return flow.valueOf(node, scopes);
614
+ }
615
+ return resolved;
616
+ }
617
+ /** Specs replace falsy descriptions with an empty string. Suite paths keep false and zero. */
618
+ export function jasmineTitleValue(title, file, spec) {
619
+ const node = title.node;
620
+ if (node.type === 'SpreadElement')
621
+ return undefined;
622
+ const resolved = title.resolved ?? jasmineValue(node, title.scopes, file);
623
+ const literal = node.type === 'UnaryExpression' && node.operator === '-' ? unwrap(node.argument) : node;
624
+ if (literal.type === 'Literal' && typeof literal.value === 'bigint') {
625
+ const value = node === literal ? literal.value : -literal.value;
626
+ return { ok: true, value: spec && !value ? '' : String(value) };
627
+ }
628
+ if (!resolved.ok)
629
+ return resolved;
630
+ const text = spec && !resolved.value ? '' : descriptionText(resolved.value);
631
+ return text === undefined ? resolved : { ok: true, value: text };
632
+ }
@@ -1,10 +1,16 @@
1
- import type { CallExpression } from 'oxc-parser';
1
+ import type { CallExpression, Expression, Node } from 'oxc-parser';
2
2
  import type { ApiCall, CallContext, ModuleReader } from '../model.ts';
3
3
  import type { ParsedFile } from '../parse.ts';
4
4
  import type { HookCounts } from '../types.ts';
5
5
  import { type FileContext, type Link } from './common.ts';
6
6
  import { SuiteAdapter, type Kind } from './test-functions.ts';
7
7
  export declare class JasmineAdapter extends SuiteAdapter {
8
+ readonly catchesSuiteErrors = true;
9
+ registrationSpread(operand: Expression, scopes: readonly Node[]): import("../values.ts").IteratorSpread;
10
+ registrationValue(operand: Expression, scopes: readonly Node[]): import("../values.ts").Resolved;
11
+ registrationExit(block: Extract<Node, {
12
+ type: 'BlockStatement';
13
+ }>, scopes: readonly Node[]): "return" | ("unknown" | "throw" | "next");
8
14
  /** What the runner does with a call it refuses at the top level of a file, as the end of a sentence. */
9
15
  protected readonly refusedEffect: string;
10
16
  /** Whether a number after a spec's timeout is a retry count, as WebdriverIO reads it. */