test-inventory 0.9.0 → 0.9.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/CHANGELOG.md +100 -0
- package/dist/config-runs.d.ts +3 -3
- package/dist/config-runs.js +64 -32
- package/dist/files.d.ts +3 -2
- package/dist/files.js +52 -9
- package/dist/frameworks/bun.d.ts +2 -0
- package/dist/frameworks/bun.js +10 -2
- package/dist/frameworks/jasmine.d.ts +4 -3
- package/dist/frameworks/jasmine.js +13 -3
- package/dist/frameworks/mocha.js +3 -2
- package/dist/frameworks/node.js +11 -8
- package/dist/frameworks/playwright.d.ts +5 -0
- package/dist/frameworks/playwright.js +27 -0
- package/dist/frameworks/test-functions.js +9 -0
- package/dist/node-scripts.d.ts +5 -0
- package/dist/node-scripts.js +53 -2
- package/dist/records.d.ts +2 -0
- package/dist/records.js +45 -15
- package/dist/resolve.d.ts +7 -1
- package/dist/resolve.js +16 -4
- package/dist/scan-file.js +2 -0
- package/dist/toml.js +10 -3
- package/dist/yaml.d.ts +2 -1
- package/dist/yaml.js +174 -35
- package/package.json +8 -2
|
@@ -562,6 +562,12 @@ export class PlaywrightAdapter {
|
|
|
562
562
|
const [condition, description] = [call.arguments.at(0), call.arguments.at(1)];
|
|
563
563
|
if (isFunctionNode(condition))
|
|
564
564
|
this.checkFixtureArguments(condition);
|
|
565
|
+
if (call.arguments.length === 1 && condition?.type !== 'SpreadElement' && atLeast(this.file.version, 1, 65)) {
|
|
566
|
+
const resolved = this.file.values.resolve(condition, context.scopes);
|
|
567
|
+
if (isTitleLiteral(condition) || (resolved.ok && typeof resolved.value === 'string')) {
|
|
568
|
+
return this.describedModifier(condition, state, context);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
565
571
|
const problems = [];
|
|
566
572
|
if (isTitleLiteral(condition)) {
|
|
567
573
|
const callee = snippet(text(this.file, call.callee));
|
|
@@ -579,6 +585,27 @@ export class PlaywrightAdapter {
|
|
|
579
585
|
problems,
|
|
580
586
|
};
|
|
581
587
|
}
|
|
588
|
+
/**
|
|
589
|
+
* From Playwright 1.65, `test.skip(description)` with a string: the string is the reason, and still a condition, so
|
|
590
|
+
* an empty one applies nothing. A template literal with text of its own is never empty.
|
|
591
|
+
*/
|
|
592
|
+
describedModifier(node, state, context) {
|
|
593
|
+
const hasText = node.type === 'TemplateLiteral' && node.quasis.some((quasi) => quasi.value.cooked !== '');
|
|
594
|
+
const condition = hasText
|
|
595
|
+
? { applies: 'always', text: null }
|
|
596
|
+
: readCondition(this.file, context.scopes, node);
|
|
597
|
+
const reason = condition.applies === 'never'
|
|
598
|
+
? { reason: null, isDynamic: false, problem: null }
|
|
599
|
+
: readReason(this.file, context.scopes, node);
|
|
600
|
+
return {
|
|
601
|
+
kind: 'modifier',
|
|
602
|
+
state,
|
|
603
|
+
condition,
|
|
604
|
+
reason: reason.reason,
|
|
605
|
+
hasDynamicReason: reason.isDynamic,
|
|
606
|
+
problems: reason.problem ? [reason.problem] : [],
|
|
607
|
+
};
|
|
608
|
+
}
|
|
582
609
|
describeCall(call, kind, context) {
|
|
583
610
|
const args = call.arguments;
|
|
584
611
|
if (args.length === 0)
|
|
@@ -306,6 +306,11 @@ export class SuiteAdapter {
|
|
|
306
306
|
const returned = this.returned(base, chainLinks, args, lookup);
|
|
307
307
|
return returned && { kind: returned.kind, index: 0, modifiers: returned.links };
|
|
308
308
|
}
|
|
309
|
+
// `(process.env.CI ? it.skip : it)(...)`: a choice written in place, read as one kept in a variable.
|
|
310
|
+
if (base.type === 'ConditionalExpression' || base.type === 'LogicalExpression') {
|
|
311
|
+
const chosen = this.aliasOf(base, lookup);
|
|
312
|
+
return chosen && { kind: chosen.kind, index: 0, modifiers: chosen.links };
|
|
313
|
+
}
|
|
309
314
|
if (base.type !== 'Identifier')
|
|
310
315
|
return null;
|
|
311
316
|
// A name the file doesn't declare is one of the framework's globals; a local variable or parameter with the same
|
|
@@ -417,6 +422,10 @@ export class SuiteAdapter {
|
|
|
417
422
|
};
|
|
418
423
|
}
|
|
419
424
|
const chain = readChain(node);
|
|
425
|
+
// A runner without modifiers, as Jasmine, has no members to hold: `it.only` is undefined there, while `fit` keeps
|
|
426
|
+
// the `only` it carries.
|
|
427
|
+
if (chain && chain.links.length > 0 && this.dialect.modifiers.size === 0)
|
|
428
|
+
return null;
|
|
420
429
|
const resolved = chain ? this.resolve(chain, [], lookup) : null;
|
|
421
430
|
const isAlias = resolved?.links.every((link) => this.isAliasLink(resolved.kind, link));
|
|
422
431
|
return resolved && isAlias ? { functions: [resolved], mayBeOther: false } : null;
|
package/dist/node-scripts.d.ts
CHANGED
|
@@ -4,3 +4,8 @@
|
|
|
4
4
|
* to the script.
|
|
5
5
|
*/
|
|
6
6
|
export declare function nodeTestCommands(script: string): string[][];
|
|
7
|
+
/**
|
|
8
|
+
* A package.json script and those it runs in turn, each once: through `npm run`, `npm test`, `pnpm`, `yarn`,
|
|
9
|
+
* `bun run`, or `npm-run-all`, `run-s` and `run-p`, whose names may be globs where `*` stops at a `:`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function scriptsRunBy(scripts: Record<string, unknown>, name: string): string[];
|
package/dist/node-scripts.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import picomatch from 'picomatch';
|
|
1
2
|
/** Node.js options that take their value as the next argument, so it is not a file to test. */
|
|
2
3
|
const VALUE_OPTIONS = new Set([
|
|
3
4
|
'--allow-fs-read',
|
|
@@ -59,8 +60,7 @@ const VALUE_OPTIONS = new Set([
|
|
|
59
60
|
*/
|
|
60
61
|
export function nodeTestCommands(script) {
|
|
61
62
|
const commands = [];
|
|
62
|
-
for (const
|
|
63
|
-
const words = [...command.matchAll(/'([^']*)'|"([^"]*)"|(\S+)/g)].map((match) => match[1] ?? match[2] ?? match[3]);
|
|
63
|
+
for (const words of commandsOf(script)) {
|
|
64
64
|
const node = words.findIndex((word) => /(^|[/\\])node(\.exe)?$/.test(word));
|
|
65
65
|
if (node === -1)
|
|
66
66
|
continue;
|
|
@@ -83,3 +83,54 @@ export function nodeTestCommands(script) {
|
|
|
83
83
|
}
|
|
84
84
|
return commands;
|
|
85
85
|
}
|
|
86
|
+
/** The commands of a script, each as its words, without quotes. */
|
|
87
|
+
function commandsOf(script) {
|
|
88
|
+
return script
|
|
89
|
+
.split(/&&|\|\||[;|]/)
|
|
90
|
+
.map((command) => [...command.matchAll(/'([^']*)'|"([^"]*)"|(\S+)/g)].map((match) => match[1] ?? match[2] ?? match[3]));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A package.json script and those it runs in turn, each once: through `npm run`, `npm test`, `pnpm`, `yarn`,
|
|
94
|
+
* `bun run`, or `npm-run-all`, `run-s` and `run-p`, whose names may be globs where `*` stops at a `:`.
|
|
95
|
+
*/
|
|
96
|
+
export function scriptsRunBy(scripts, name) {
|
|
97
|
+
const names = Object.keys(scripts).filter((key) => typeof scripts[key] === 'string');
|
|
98
|
+
const run = [];
|
|
99
|
+
const visit = (current) => {
|
|
100
|
+
if (run.includes(current) || !names.includes(current))
|
|
101
|
+
return;
|
|
102
|
+
run.push(current);
|
|
103
|
+
for (const words of commandsOf(scripts[current])) {
|
|
104
|
+
for (const called of calledScripts(words, names))
|
|
105
|
+
visit(called);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
visit(name);
|
|
109
|
+
return run.map((key) => scripts[key]);
|
|
110
|
+
}
|
|
111
|
+
const NPM_RUN = new Set(['run', 'run-script', 'rum', 'urn']);
|
|
112
|
+
const NPM_TEST = new Set(['test', 't', 'tst']);
|
|
113
|
+
/** The scripts a command runs; a word that names no script, as `pnpm install`, runs none. */
|
|
114
|
+
function calledScripts(words, names) {
|
|
115
|
+
// Variables set before the command, as in `TZ=UTC npm test` or `cross-env TZ=UTC npm test`, don't change it.
|
|
116
|
+
let start = 0;
|
|
117
|
+
while (start < words.length && (/^\w+=/.test(words[start]) || words[start] === 'cross-env'))
|
|
118
|
+
start++;
|
|
119
|
+
const [tool = '', ...rest] = words.slice(start);
|
|
120
|
+
const end = rest.indexOf('--');
|
|
121
|
+
const args = (end === -1 ? rest : rest.slice(0, end)).filter((word) => !word.startsWith('-'));
|
|
122
|
+
const [first = '', second = ''] = args;
|
|
123
|
+
if (['npm-run-all', 'run-s', 'run-p'].includes(tool)) {
|
|
124
|
+
// As npm-run-all 4 and npm-run-all2 9 match names: `:` and `/` swapped, no `!` negation, no dot names for `*`.
|
|
125
|
+
const swap = (text) => text.replaceAll(/[:/]/g, (char) => (char === ':' ? '/' : ':'));
|
|
126
|
+
const matches = picomatch(args.map(swap), { nonegate: true });
|
|
127
|
+
return names.filter((key) => matches(swap(key)));
|
|
128
|
+
}
|
|
129
|
+
if (tool === 'npm')
|
|
130
|
+
return NPM_RUN.has(first) ? [second] : NPM_TEST.has(first) ? ['test'] : [];
|
|
131
|
+
if (tool === 'bun')
|
|
132
|
+
return first === 'run' ? [second] : [];
|
|
133
|
+
if (tool === 'pnpm' || tool === 'yarn')
|
|
134
|
+
return first === 'run' ? [second] : [first];
|
|
135
|
+
return [];
|
|
136
|
+
}
|
package/dist/records.d.ts
CHANGED
|
@@ -73,6 +73,8 @@ export interface FileConfig {
|
|
|
73
73
|
interface RecordOptions {
|
|
74
74
|
relativeFilePath: string;
|
|
75
75
|
framework: Framework;
|
|
76
|
+
/** Jasmine's focus rules apply: for Jasmine, and for WebdriverIO on Jasmine. */
|
|
77
|
+
focusesLikeJasmine: boolean;
|
|
76
78
|
comments: CommentsMode;
|
|
77
79
|
isTypeTest: boolean;
|
|
78
80
|
/** A Vitest 5 benchmark file, such as `*.bench.ts`. */
|
package/dist/records.js
CHANGED
|
@@ -3,6 +3,22 @@ import { anySlow, eitherCondition, noHooks, } from "./extract.js";
|
|
|
3
3
|
import { problem } from "./frameworks/common.js";
|
|
4
4
|
import { hashNodes, shortHash } from "./hash.js";
|
|
5
5
|
import { snippet } from "./source.js";
|
|
6
|
+
/**
|
|
7
|
+
* The states of a describe that win over those of the describes inside it and of the test itself: node:test creates
|
|
8
|
+
* nothing inside a skipped describe, and in Bun the outermost skipped or todo describe decides (checked with Node.js
|
|
9
|
+
* 26.12.1 and Bun 1.2.23, 1.3.14 and 1.4.4). Elsewhere the state nearest the test wins.
|
|
10
|
+
*/
|
|
11
|
+
const OVERRIDING_DESCRIBES = {
|
|
12
|
+
playwright: [],
|
|
13
|
+
vitest: [],
|
|
14
|
+
jest: [],
|
|
15
|
+
mocha: [],
|
|
16
|
+
jasmine: [],
|
|
17
|
+
cypress: [],
|
|
18
|
+
webdriverio: [],
|
|
19
|
+
node: ['skip'],
|
|
20
|
+
bun: ['skip', 'todo'],
|
|
21
|
+
};
|
|
6
22
|
/**
|
|
7
23
|
* The state the runner applies, from the candidates nearest the test first. An unconditional skip, fixme or todo wins
|
|
8
24
|
* over an unconditional expected failure, since the test doesn't run, and one set while the file loads wins over one
|
|
@@ -376,14 +392,15 @@ class RecordBuilder {
|
|
|
376
392
|
return { chosen: setting ? { setting, source: 'test' } : null, isOnly: declaration.isOnly || passesOnly };
|
|
377
393
|
}
|
|
378
394
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
395
|
+
* Where Jasmine's focus on a spec sits, as an index into its `scopes`, from the innermost: -1 for a `fit`, the
|
|
396
|
+
* `fdescribe` around it with no focused spec or describe below, as Jasmine runs only the innermost focus, or null
|
|
397
|
+
* when the spec isn't focused (checked with Jasmine 4.6.0 and 7.0.0).
|
|
381
398
|
*/
|
|
382
399
|
jasmineFocus(pending, scopes) {
|
|
383
400
|
if (pending.declaration.isOnly)
|
|
384
|
-
return
|
|
385
|
-
const nearest = scopes.
|
|
386
|
-
return nearest !==
|
|
401
|
+
return -1;
|
|
402
|
+
const nearest = scopes.findIndex((scope) => scope.isOnly);
|
|
403
|
+
return nearest !== -1 && !this.focusedBelow.has(scopes[nearest]) ? nearest : null;
|
|
387
404
|
}
|
|
388
405
|
test(pending, suites) {
|
|
389
406
|
const { declaration } = pending;
|
|
@@ -413,22 +430,33 @@ class RecordBuilder {
|
|
|
413
430
|
const tagsFirst = this.options.config?.tags?.beatsDescribes ?? true;
|
|
414
431
|
const tagged = (own, tag, around) => tagsFirst ? [...own, ...tag, ...around] : [...own, ...around, ...tag];
|
|
415
432
|
const jest = this.options.framework === 'jest' ? this.jestState(pending, scopes) : null;
|
|
416
|
-
const
|
|
417
|
-
// A
|
|
418
|
-
|
|
433
|
+
const focus = this.options.focusesLikeJasmine ? this.jasmineFocus(pending, scopes) : undefined;
|
|
434
|
+
// A focus inside an `xdescribe` runs, as the describe's own skip doesn't reach it; `pending()` still does. An
|
|
435
|
+
// `xdescribe` inside the focus stays skipped.
|
|
436
|
+
const declaredSkip = (scope, index, setting) => typeof focus === 'number' &&
|
|
437
|
+
index > focus &&
|
|
438
|
+
scope.kind === 'describe' &&
|
|
439
|
+
suiteOf(scope).declaration.states.includes(setting);
|
|
440
|
+
const overriding = OVERRIDING_DESCRIBES[this.options.framework];
|
|
441
|
+
const around = scopes.flatMap((scope, index) => scope.states
|
|
442
|
+
.filter((setting) => !declaredSkip(scope, index, setting))
|
|
443
|
+
.map((setting) => ({
|
|
444
|
+
setting,
|
|
445
|
+
source: scope.kind === 'file' ? 'file' : 'suite',
|
|
446
|
+
overrides: overriding.includes(setting.state) &&
|
|
447
|
+
scope.kind === 'describe' &&
|
|
448
|
+
suiteOf(scope).declaration.states.includes(setting),
|
|
449
|
+
})));
|
|
419
450
|
const chosen = jest
|
|
420
451
|
? jest.chosen
|
|
421
452
|
: chooseState([
|
|
453
|
+
// Outermost first, as the outermost of them decides.
|
|
454
|
+
...around.filter((candidate) => candidate.overrides).reverse(),
|
|
422
455
|
...declaredStates(pending.states.slice(0, declaration.states.length), fromTags, declaration),
|
|
423
456
|
...pending.states.slice(declaration.states.length).map((setting) => ({ setting, source: 'test' })),
|
|
424
457
|
// A test the declaration skips never runs its body, so its subtests never run; one its body skips still runs it.
|
|
425
458
|
...parents.flatMap((parent) => parent.declaration.states.map((setting) => ({ setting, source: 'suite' }))),
|
|
426
|
-
...
|
|
427
|
-
.filter((setting) => !declaredSkip(scope, setting))
|
|
428
|
-
.map((setting) => ({
|
|
429
|
-
setting,
|
|
430
|
-
source: scope.kind === 'file' ? 'file' : 'suite',
|
|
431
|
-
}))),
|
|
459
|
+
...around.filter((candidate) => !candidate.overrides),
|
|
432
460
|
]);
|
|
433
461
|
// When the runner refuses the file, no test in it runs, whatever else is written, or none after the refused call.
|
|
434
462
|
const rejected = this.rejectedAt !== null && !(this.keepsEarlierTests && this.parsed.source.line(located.start) < this.rejectedAt);
|
|
@@ -447,7 +475,9 @@ class RecordBuilder {
|
|
|
447
475
|
}
|
|
448
476
|
const isOnly = jest
|
|
449
477
|
? jest.isOnly
|
|
450
|
-
:
|
|
478
|
+
: focus !== undefined
|
|
479
|
+
? focus !== null
|
|
480
|
+
: declaration.isOnly || scopes.some((scope) => scope.isOnly) || fromTags?.only === true;
|
|
451
481
|
const comments = this.options.comments === 'all' || (this.options.comments === 'non-active' && state !== 'active')
|
|
452
482
|
? pending.comments
|
|
453
483
|
: [];
|
package/dist/resolve.d.ts
CHANGED
|
@@ -7,15 +7,21 @@ export declare function parseJsonc(text: string): unknown;
|
|
|
7
7
|
* `moduleDirectories`.
|
|
8
8
|
*/
|
|
9
9
|
export interface ImportMap {
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* A string `find` maps the name itself and the names below it, as `@` maps `@/x`; a regex maps what it matches, as
|
|
12
|
+
* Vite does, or with `replacesName`, as Jest's `moduleNameMapper` does, the whole name, with `$1` for its groups.
|
|
13
|
+
*/
|
|
11
14
|
aliases: {
|
|
12
15
|
find: string | RegExp;
|
|
13
16
|
replacements: string[];
|
|
17
|
+
replacesName: boolean;
|
|
14
18
|
}[];
|
|
15
19
|
/** Folders a bare name is looked for in. */
|
|
16
20
|
paths: string[];
|
|
17
21
|
/** Names of folders a bare name is looked for in, in the importing file's folder and each folder above it. */
|
|
18
22
|
directories: string[];
|
|
23
|
+
/** Vite's root, from which it takes an alias's path that starts with `/` first; null for Jest. */
|
|
24
|
+
root: string | null;
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
27
|
* Returns a reader for the modules a test file imports. It follows the import map of the config the file runs with,
|
package/dist/resolve.js
CHANGED
|
@@ -335,13 +335,19 @@ function searched(specifier, directory, map) {
|
|
|
335
335
|
}
|
|
336
336
|
/** The names an alias maps a specifier to; null when it doesn't match. */
|
|
337
337
|
function mapped(specifier, alias) {
|
|
338
|
-
const { find, replacements } = alias;
|
|
338
|
+
const { find, replacements, replacesName } = alias;
|
|
339
339
|
if (typeof find === 'string') {
|
|
340
340
|
if (specifier !== find && !specifier.startsWith(`${find}/`))
|
|
341
341
|
return null;
|
|
342
342
|
return replacements.map((replacement) => replacement + specifier.slice(find.length));
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
const match = specifier.match(find);
|
|
345
|
+
if (!match)
|
|
346
|
+
return null;
|
|
347
|
+
if (!replacesName)
|
|
348
|
+
return replacements.map((replacement) => specifier.replace(find, replacement));
|
|
349
|
+
// Jest fills in a group that matched nothing with an empty string.
|
|
350
|
+
return replacements.map((replacement) => replacement.replaceAll(/\$(\d+)/g, (_, index) => match[Number(index)] || ''));
|
|
345
351
|
}
|
|
346
352
|
/**
|
|
347
353
|
* Returns a reader for the modules a test file imports. It follows the import map of the config the file runs with,
|
|
@@ -422,15 +428,21 @@ export function moduleResolver(root) {
|
|
|
422
428
|
}
|
|
423
429
|
return candidates.map(findFile).find((file) => file !== null) ?? { reason: 'could not be read' };
|
|
424
430
|
};
|
|
431
|
+
// A path a config gives is absolute, as with `path.resolve()` or `<rootDir>`; output paths are relative to the root.
|
|
432
|
+
const shown = (name) => (path.isAbsolute(name) ? path.relative(root, name).replaceAll('\\', '/') : name);
|
|
425
433
|
const reader = (fromFile, map = null) => (specifier) => {
|
|
426
434
|
const directory = path.dirname(fromFile);
|
|
427
435
|
const aliased = map?.aliases.map((alias) => mapped(specifier, alias)).find((names) => names !== null);
|
|
436
|
+
// Vite takes `/src/x` from its root first, unless it is already a path inside the root.
|
|
437
|
+
const fromRoot = (name) => map?.root && name.startsWith('/') && !name.startsWith(map.root + path.sep)
|
|
438
|
+
? [path.join(map.root, name), name]
|
|
439
|
+
: [name];
|
|
428
440
|
// The config maps the name to others, each a path or a name looked up as written, the first that is found.
|
|
429
|
-
const located = (aliased ?? [specifier]).map((name) => locate(name, directory, map));
|
|
441
|
+
const located = (aliased?.flatMap(fromRoot) ?? [specifier]).map((name) => locate(name, directory, map));
|
|
430
442
|
const found = located.find((item) => typeof item === 'string');
|
|
431
443
|
if (found === undefined) {
|
|
432
444
|
return aliased
|
|
433
|
-
? { reason: `is mapped by the config to ${aliased.join(' or ')}, which could not be read` }
|
|
445
|
+
? { reason: `is mapped by the config to ${aliased.map(shown).join(' or ')}, which could not be read` }
|
|
434
446
|
: located[0];
|
|
435
447
|
}
|
|
436
448
|
let known = modules.get(map);
|
package/dist/scan-file.js
CHANGED
|
@@ -67,6 +67,8 @@ export function scanFile(code, relativeFilePath, settings) {
|
|
|
67
67
|
const records = buildRecords(extraction, parsed, {
|
|
68
68
|
relativeFilePath,
|
|
69
69
|
framework: settings.framework,
|
|
70
|
+
focusesLikeJasmine: settings.framework === 'jasmine' ||
|
|
71
|
+
(settings.framework === 'webdriverio' && settings.webdriverioFramework === 'jasmine'),
|
|
70
72
|
comments: settings.comments,
|
|
71
73
|
isTypeTest,
|
|
72
74
|
// Vitest 5's default `benchmark.include`, when no config says.
|
package/dist/toml.js
CHANGED
|
@@ -6,12 +6,19 @@ export class TomlError extends Error {
|
|
|
6
6
|
this.line = line;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* A table without a prototype, so keys such as `__proto__` and `constructor` are its own, as in Bun, and a project's
|
|
11
|
+
* `bunfig.toml` can't reach `Object.prototype`, which every later scan in the process would see.
|
|
12
|
+
*/
|
|
13
|
+
function newTable() {
|
|
14
|
+
return Object.create(null);
|
|
15
|
+
}
|
|
9
16
|
/**
|
|
10
17
|
* The part of TOML a `bunfig.toml` uses: tables and dotted keys, strings, numbers, booleans, arrays over several lines,
|
|
11
18
|
* inline tables and comments. Dates and arrays of tables are refused with a `TomlError`.
|
|
12
19
|
*/
|
|
13
20
|
export function readToml(text) {
|
|
14
|
-
const root =
|
|
21
|
+
const root = newTable();
|
|
15
22
|
let table = root;
|
|
16
23
|
const reader = { text, at: 0, line: 1 };
|
|
17
24
|
for (;;) {
|
|
@@ -87,7 +94,7 @@ function readKeys(reader, end) {
|
|
|
87
94
|
function tableAt(root, keys, line) {
|
|
88
95
|
let table = root;
|
|
89
96
|
for (const key of keys) {
|
|
90
|
-
table[key] ??=
|
|
97
|
+
table[key] ??= newTable();
|
|
91
98
|
const next = table[key];
|
|
92
99
|
if (typeof next !== 'object' || Array.isArray(next)) {
|
|
93
100
|
throw new TomlError(`${key} is not a table`, line);
|
|
@@ -120,7 +127,7 @@ function readValue(reader) {
|
|
|
120
127
|
}
|
|
121
128
|
if (char === '{') {
|
|
122
129
|
reader.at++;
|
|
123
|
-
const table =
|
|
130
|
+
const table = newTable();
|
|
124
131
|
skipBlank(reader, false);
|
|
125
132
|
while (text[reader.at] !== '}') {
|
|
126
133
|
const keys = readKeys(reader, '=');
|
package/dist/yaml.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class YamlError extends Error {
|
|
|
7
7
|
/**
|
|
8
8
|
* The value of a YAML config as Mocha's `.mocharc.yml` files write it: a map of keys to scalars, to lists written one
|
|
9
9
|
* item per line or in brackets, and to maps of those. Anchors, multi-line strings, flow maps and documents after the
|
|
10
|
-
* first are refused with a `YamlError`, as a guess at them could read the wrong test files
|
|
10
|
+
* first are refused with a `YamlError`, as a guess at them could read the wrong test files, and so is what js-yaml,
|
|
11
|
+
* Mocha's reader, refuses: a key set twice, a tab in the indent, or `: ` in a plain value.
|
|
11
12
|
*/
|
|
12
13
|
export declare function readYaml(text: string): Value;
|