@lousy-agents/cli 5.22.16 → 5.22.18
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/dist/index.js
CHANGED
|
@@ -39466,7 +39466,8 @@ const lockFiles = [
|
|
|
39466
39466
|
"npm-shrinkwrap.json",
|
|
39467
39467
|
"bun.lockb",
|
|
39468
39468
|
"bun.lock",
|
|
39469
|
-
"deno.lock"
|
|
39469
|
+
"deno.lock",
|
|
39470
|
+
"upm.lock"
|
|
39470
39471
|
];
|
|
39471
39472
|
const packageFiles = [
|
|
39472
39473
|
"package.json",
|
|
@@ -39700,11 +39701,27 @@ async function readGitConfig(dir, opts) {
|
|
|
39700
39701
|
async function writeGitConfig(path, config) {
|
|
39701
39702
|
await writeFile(path, stringifyGitConfig(config));
|
|
39702
39703
|
}
|
|
39704
|
+
const _unescapeGitSubsection = (name) => name.replaceAll(/\\(.)/g, "$1");
|
|
39705
|
+
const _escapeGitSubsection = (name) => name.replaceAll(/(["\\])/g, "\\$1");
|
|
39706
|
+
const _escapeINISection = (name) => name.replaceAll("\\", String.raw`\\`).replaceAll(".", String.raw`\.`);
|
|
39707
|
+
const _encodeINISection = (name) => encodeURIComponent(name).replaceAll(".", "%2E");
|
|
39708
|
+
const _decodeINISection = (name) => decodeURIComponent(name);
|
|
39709
|
+
const _isSubsection = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
39703
39710
|
function parseGitConfig(ini) {
|
|
39704
|
-
return parseINI(ini.replaceAll(/^\[(\w+) "(
|
|
39711
|
+
return parseINI(ini.replaceAll(/^\[(\w+) "(.*)"\]$/gm, (_, section, subsection) => `[${section}.${_escapeINISection(_unescapeGitSubsection(subsection))}]`));
|
|
39705
39712
|
}
|
|
39706
39713
|
function stringifyGitConfig(config) {
|
|
39707
|
-
|
|
39714
|
+
const encoded = {};
|
|
39715
|
+
for (const [section, value] of Object.entries(config)) {
|
|
39716
|
+
if (!_isSubsection(value)) {
|
|
39717
|
+
encoded[section] = value;
|
|
39718
|
+
continue;
|
|
39719
|
+
}
|
|
39720
|
+
const entries = {};
|
|
39721
|
+
for (const [key, subValue] of Object.entries(value)) entries[_isSubsection(subValue) ? _encodeINISection(key) : key] = subValue;
|
|
39722
|
+
encoded[section] = entries;
|
|
39723
|
+
}
|
|
39724
|
+
return stringifyINI(encoded).replaceAll(/^\[(\w+)\.(.*)\]$/gm, (_, section, subsection) => `[${section} "${_escapeGitSubsection(_decodeINISection(subsection))}"]`);
|
|
39708
39725
|
}
|
|
39709
39726
|
|
|
39710
39727
|
|
|
@@ -85192,8 +85209,12 @@ function encodeCharacterReference(code) {
|
|
|
85192
85209
|
|
|
85193
85210
|
;// CONCATENATED MODULE: ../../node_modules/unist-util-visit-parents/lib/color.node.js
|
|
85194
85211
|
/**
|
|
85212
|
+
* Color a string.
|
|
85213
|
+
*
|
|
85195
85214
|
* @param {string} d
|
|
85215
|
+
* Value.
|
|
85196
85216
|
* @returns {string}
|
|
85217
|
+
* Colored value.
|
|
85197
85218
|
*/
|
|
85198
85219
|
function color_node_color(d) {
|
|
85199
85220
|
return '\u001B[33m' + d + '\u001B[39m'
|
|
@@ -85369,44 +85390,96 @@ function color_node_color(d) {
|
|
|
85369
85390
|
* List with one or two values, the first an action, the second an index.
|
|
85370
85391
|
*
|
|
85371
85392
|
* @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult
|
|
85372
|
-
* Any value that can be returned from
|
|
85393
|
+
* Any value that can be returned from an enter visitor.
|
|
85394
|
+
*
|
|
85395
|
+
* Like `VisitorResultExit`,
|
|
85396
|
+
* but `SKIP` can also be returned,
|
|
85397
|
+
* to not walk the children of the node,
|
|
85398
|
+
* and `ActionTuple` can be used to combine an action with an index.
|
|
85399
|
+
*
|
|
85400
|
+
* @typedef {Index | boolean | null | undefined | void} VisitorResultExit
|
|
85401
|
+
* Any value that can be returned from an exit visitor.
|
|
85373
85402
|
*/
|
|
85374
85403
|
|
|
85375
85404
|
/**
|
|
85376
85405
|
* @callback Visitor
|
|
85377
|
-
* Handle a node (matching `test`, if given).
|
|
85378
|
-
*
|
|
85379
|
-
*
|
|
85380
|
-
*
|
|
85381
|
-
*
|
|
85382
|
-
*
|
|
85383
|
-
*
|
|
85384
|
-
*
|
|
85385
|
-
*
|
|
85386
|
-
*
|
|
85387
|
-
* sibling to traverse after `node` is traversed.
|
|
85388
|
-
* Adding or removing next siblings of `node` (or previous siblings, in case
|
|
85389
|
-
* of reverse) is handled as expected without needing to return a new `Index`.
|
|
85390
|
-
*
|
|
85391
|
-
* Removing the children property of an ancestor still results in them being
|
|
85392
|
-
* traversed.
|
|
85406
|
+
* Handle a node (matching `test`, if given) before its children.
|
|
85407
|
+
*
|
|
85408
|
+
* Changes inside `node` are walked next.
|
|
85409
|
+
* Replacing or removing it is easier in `exit`.
|
|
85410
|
+
* When replacing or removing it here,
|
|
85411
|
+
* return `SKIP` (as otherwise its old children are walked),
|
|
85412
|
+
* or `[SKIP, index]` to continue with the node now at `index`.
|
|
85413
|
+
* Changing next siblings (in walk order) is fine;
|
|
85414
|
+
* changing previous siblings needs a new `Index`.
|
|
85415
|
+
* Removing an ancestor or changing its previous siblings is not supported.
|
|
85393
85416
|
* @param {Visited} node
|
|
85394
85417
|
* Found node.
|
|
85395
85418
|
* @param {Array<VisitedParents>} ancestors
|
|
85396
85419
|
* Ancestors of `node`.
|
|
85420
|
+
* @param {number | undefined} index
|
|
85421
|
+
* Index of `node` in its parent (the last of `ancestors`),
|
|
85422
|
+
* or `undefined` for the tree itself.
|
|
85397
85423
|
* @returns {VisitorResult}
|
|
85398
85424
|
* What to do next.
|
|
85399
85425
|
*
|
|
85400
|
-
*
|
|
85401
|
-
*
|
|
85426
|
+
* Like `VisitorExit`,
|
|
85427
|
+
* but `SKIP` can also be returned,
|
|
85428
|
+
* to not walk the children of `node`.
|
|
85429
|
+
* Passing a tuple back (`ActionTuple`) only makes sense as `[SKIP, Index]`.
|
|
85430
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
85431
|
+
* Visited node type.
|
|
85432
|
+
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
85433
|
+
* Ancestor type.
|
|
85434
|
+
*/
|
|
85435
|
+
|
|
85436
|
+
/**
|
|
85437
|
+
* @callback VisitorExit
|
|
85438
|
+
* Handle a node (matching `test`, if given) after its children.
|
|
85439
|
+
*
|
|
85440
|
+
* Changes inside `node` are not walked,
|
|
85441
|
+
* which makes this a good place to change `node` based on its children,
|
|
85442
|
+
* or to replace or remove it.
|
|
85443
|
+
* When removing `node` or changing previous siblings (in walk order),
|
|
85444
|
+
* return a new `Index`.
|
|
85445
|
+
* Removing an ancestor or changing its previous siblings is not supported.
|
|
85446
|
+
* @param {Visited} node
|
|
85447
|
+
* Found node.
|
|
85448
|
+
* @param {Array<VisitedParents>} ancestors
|
|
85449
|
+
* Ancestors of `node`.
|
|
85450
|
+
* @param {number | undefined} index
|
|
85451
|
+
* Index of `node` in its parent (the last of `ancestors`),
|
|
85452
|
+
* or `undefined` for the tree itself.
|
|
85453
|
+
* @returns {VisitorResultExit}
|
|
85454
|
+
* What to do next.
|
|
85402
85455
|
*
|
|
85403
|
-
*
|
|
85404
|
-
*
|
|
85405
|
-
*
|
|
85456
|
+
* `CONTINUE` (`true`, nothing) continues as normal,
|
|
85457
|
+
* `EXIT` (`false`) stops traversing,
|
|
85458
|
+
* and `Index` continues at that sibling.
|
|
85459
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
85460
|
+
* Visited node type.
|
|
85461
|
+
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
85462
|
+
* Ancestor type.
|
|
85463
|
+
*/
|
|
85464
|
+
|
|
85465
|
+
/**
|
|
85406
85466
|
* @template {UnistNode} [Visited=UnistNode]
|
|
85407
85467
|
* Visited node type.
|
|
85408
85468
|
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
85409
85469
|
* Ancestor type.
|
|
85470
|
+
* @typedef Visitors
|
|
85471
|
+
* Handle nodes when entering and exiting them.
|
|
85472
|
+
* The `enter` visitor is optional while `exit` is required.
|
|
85473
|
+
*
|
|
85474
|
+
* Pass an `enter` visitor directly to only handle nodes when entering them.
|
|
85475
|
+
*
|
|
85476
|
+
* `enter` is called before children (if any) are walked and `exit` after that.
|
|
85477
|
+
* `exit` is still called when `enter` returns `SKIP`.
|
|
85478
|
+
* Both `enter` and `exit` are only called for nodes that match an optional `test`.
|
|
85479
|
+
* @property {Visitor<Visited, VisitedParents> | null | undefined} [enter]
|
|
85480
|
+
* Handle a node before its children (optional).
|
|
85481
|
+
* @property {VisitorExit<Visited, VisitedParents>} exit
|
|
85482
|
+
* Handle a node after its children.
|
|
85410
85483
|
*/
|
|
85411
85484
|
|
|
85412
85485
|
/**
|
|
@@ -85420,6 +85493,17 @@ function color_node_color(d) {
|
|
|
85420
85493
|
* Test type.
|
|
85421
85494
|
*/
|
|
85422
85495
|
|
|
85496
|
+
/**
|
|
85497
|
+
* @typedef {Visitors<Matches<InclusiveDescendant<Tree>, Check>, Ancestor<Tree, Matches<InclusiveDescendant<Tree>, Check>>>} BuildVisitors
|
|
85498
|
+
* Build typed `Visitors` from a tree and a test.
|
|
85499
|
+
*
|
|
85500
|
+
* It will infer which values are passed as `node` and which as `parents`.
|
|
85501
|
+
* @template {UnistNode} [Tree=UnistNode]
|
|
85502
|
+
* Tree type.
|
|
85503
|
+
* @template {Test} [Check=Test]
|
|
85504
|
+
* Test type.
|
|
85505
|
+
*/
|
|
85506
|
+
|
|
85423
85507
|
|
|
85424
85508
|
|
|
85425
85509
|
|
|
@@ -85438,6 +85522,7 @@ const EXIT = false
|
|
|
85438
85522
|
|
|
85439
85523
|
/**
|
|
85440
85524
|
* Do not traverse this node’s children.
|
|
85525
|
+
* Only works when entering a node.
|
|
85441
85526
|
*/
|
|
85442
85527
|
const SKIP = 'skip'
|
|
85443
85528
|
|
|
@@ -85445,10 +85530,13 @@ const SKIP = 'skip'
|
|
|
85445
85530
|
* Visit nodes, with ancestral information.
|
|
85446
85531
|
*
|
|
85447
85532
|
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
|
85448
|
-
* (**NLR**) or if `reverse` is given,
|
|
85533
|
+
* (**NLR**) or if `reverse` is given,
|
|
85534
|
+
* in *reverse preorder* (**NRL**).
|
|
85535
|
+
* An `exit` visitor is called in *postorder* (**LRN**)
|
|
85536
|
+
* or if `reverse` is given, in *reverse postorder* (**RLN**).
|
|
85449
85537
|
*
|
|
85450
|
-
* You can choose
|
|
85451
|
-
* For complex tests, you should test yourself in
|
|
85538
|
+
* You can choose which nodes are visited by passing a `test`.
|
|
85539
|
+
* For complex tests, you should test yourself in a visitor, as it will be
|
|
85452
85540
|
* faster and will have improved type information.
|
|
85453
85541
|
*
|
|
85454
85542
|
* Walking the tree is an intensive task.
|
|
@@ -85457,29 +85545,72 @@ const SKIP = 'skip'
|
|
|
85457
85545
|
* to check if a node matches, and then perform different operations.
|
|
85458
85546
|
*
|
|
85459
85547
|
* You can change the tree.
|
|
85460
|
-
*
|
|
85548
|
+
* Changes inside a node made when entering it are walked,
|
|
85549
|
+
* changes made when exiting it are not.
|
|
85550
|
+
* See `Visitor` and `VisitorExit` for more info.
|
|
85551
|
+
*
|
|
85552
|
+
* @overload
|
|
85553
|
+
* @param {Tree} tree
|
|
85554
|
+
* Tree to traverse.
|
|
85555
|
+
* @param {Check} check
|
|
85556
|
+
* `unist-util-is`-compatible test.
|
|
85557
|
+
* @param {BuildVisitor<Tree, Check>} enter
|
|
85558
|
+
* Handle each node when entering it.
|
|
85559
|
+
* @param {boolean | null | undefined} [reverse]
|
|
85560
|
+
* Walk children from last to first;
|
|
85561
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
85562
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
85563
|
+
* @returns {undefined}
|
|
85564
|
+
* Nothing.
|
|
85461
85565
|
*
|
|
85462
85566
|
* @overload
|
|
85463
85567
|
* @param {Tree} tree
|
|
85568
|
+
* Tree to traverse.
|
|
85464
85569
|
* @param {Check} check
|
|
85465
|
-
*
|
|
85570
|
+
* `unist-util-is`-compatible test.
|
|
85571
|
+
* @param {BuildVisitors<Tree, Check>} visitors
|
|
85572
|
+
* Handle each node when exiting it, and optionally when entering it.
|
|
85573
|
+
* @param {boolean | null | undefined} [reverse]
|
|
85574
|
+
* Walk children from last to first;
|
|
85575
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
85576
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
85577
|
+
* @returns {undefined}
|
|
85578
|
+
* Nothing.
|
|
85579
|
+
*
|
|
85580
|
+
* @overload
|
|
85581
|
+
* @param {Tree} tree
|
|
85582
|
+
* Tree to traverse.
|
|
85583
|
+
* @param {BuildVisitor<Tree>} enter
|
|
85584
|
+
* Handle each node when entering it.
|
|
85466
85585
|
* @param {boolean | null | undefined} [reverse]
|
|
85586
|
+
* Walk children from last to first;
|
|
85587
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
85588
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
85467
85589
|
* @returns {undefined}
|
|
85590
|
+
* Nothing.
|
|
85468
85591
|
*
|
|
85469
85592
|
* @overload
|
|
85470
85593
|
* @param {Tree} tree
|
|
85471
|
-
*
|
|
85594
|
+
* Tree to traverse.
|
|
85595
|
+
* @param {BuildVisitors<Tree>} visitors
|
|
85596
|
+
* Handle each node when exiting it, and optionally when entering it.
|
|
85472
85597
|
* @param {boolean | null | undefined} [reverse]
|
|
85598
|
+
* Walk children from last to first;
|
|
85599
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
85600
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
85473
85601
|
* @returns {undefined}
|
|
85602
|
+
* Nothing.
|
|
85474
85603
|
*
|
|
85475
85604
|
* @param {UnistNode} tree
|
|
85476
85605
|
* Tree to traverse.
|
|
85477
|
-
* @param {Visitor | Test}
|
|
85478
|
-
* `unist-util-is`-compatible test
|
|
85479
|
-
* @param {Visitor | boolean | null | undefined} [
|
|
85480
|
-
*
|
|
85606
|
+
* @param {Visitor | Visitors | Test} testOrEnterOrVisitors
|
|
85607
|
+
* `unist-util-is`-compatible test, `enter`, or `visitors`.
|
|
85608
|
+
* @param {Visitor | Visitors | boolean | null | undefined} [enterOrVisitorsOrReverse]
|
|
85609
|
+
* `enter`, `visitors`, or `reverse` after a test.
|
|
85481
85610
|
* @param {boolean | null | undefined} [reverse]
|
|
85482
|
-
*
|
|
85611
|
+
* Walk children from last to first;
|
|
85612
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
85613
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
85483
85614
|
* @returns {undefined}
|
|
85484
85615
|
* Nothing.
|
|
85485
85616
|
*
|
|
@@ -85488,28 +85619,89 @@ const SKIP = 'skip'
|
|
|
85488
85619
|
* @template {Test} Check
|
|
85489
85620
|
* `unist-util-is`-compatible test.
|
|
85490
85621
|
*/
|
|
85491
|
-
function visitParents(
|
|
85622
|
+
function visitParents(
|
|
85623
|
+
tree,
|
|
85624
|
+
testOrEnterOrVisitors,
|
|
85625
|
+
enterOrVisitorsOrReverse,
|
|
85626
|
+
reverse
|
|
85627
|
+
) {
|
|
85628
|
+
if (!tree || typeof tree !== 'object') {
|
|
85629
|
+
throw new Error('Unexpected value `' + tree + '` for `tree`, expected node')
|
|
85630
|
+
}
|
|
85631
|
+
|
|
85632
|
+
let preorder = true
|
|
85492
85633
|
/** @type {Test} */
|
|
85493
85634
|
let check
|
|
85635
|
+
/** @type {Visitors | Visitor} */
|
|
85636
|
+
let visitors
|
|
85637
|
+
/** @type {Visitor | null | undefined} */
|
|
85638
|
+
let enter
|
|
85639
|
+
/** @type {VisitorExit | null | undefined} */
|
|
85640
|
+
let exit
|
|
85641
|
+
|
|
85642
|
+
// Third parameter is an enter visitor or a visitors object, so expect a `test` too.
|
|
85643
|
+
if (
|
|
85644
|
+
typeof enterOrVisitorsOrReverse === 'function' ||
|
|
85645
|
+
(enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === 'object')
|
|
85646
|
+
) {
|
|
85647
|
+
check = /** @type {Test} */ (testOrEnterOrVisitors)
|
|
85648
|
+
visitors = enterOrVisitorsOrReverse
|
|
85649
|
+
if (reverse) preorder = false
|
|
85650
|
+
}
|
|
85651
|
+
// Assume no test.
|
|
85652
|
+
else {
|
|
85653
|
+
visitors = /** @type {Visitors | Visitor} */ (testOrEnterOrVisitors)
|
|
85654
|
+
if (enterOrVisitorsOrReverse) preorder = false
|
|
85655
|
+
}
|
|
85656
|
+
|
|
85657
|
+
if (typeof visitors === 'function') {
|
|
85658
|
+
enter = visitors
|
|
85659
|
+
} else if (visitors && typeof visitors === 'object') {
|
|
85660
|
+
if (visitors.enter === null || visitors.enter === undefined) {
|
|
85661
|
+
// Empty.
|
|
85662
|
+
} else if (typeof visitors.enter === 'function') {
|
|
85663
|
+
enter = visitors.enter
|
|
85664
|
+
} else {
|
|
85665
|
+
throw new Error(
|
|
85666
|
+
'Unexpected value `' +
|
|
85667
|
+
visitors.enter +
|
|
85668
|
+
'` for `visitors.enter`, expected optional visitor'
|
|
85669
|
+
)
|
|
85670
|
+
}
|
|
85494
85671
|
|
|
85495
|
-
|
|
85496
|
-
|
|
85497
|
-
|
|
85498
|
-
|
|
85672
|
+
if (typeof visitors.exit === 'function') {
|
|
85673
|
+
exit = visitors.exit
|
|
85674
|
+
} else {
|
|
85675
|
+
throw new Error(
|
|
85676
|
+
'Unexpected value `' +
|
|
85677
|
+
visitors.exit +
|
|
85678
|
+
'` for `visitors.exit`, expected visitor (pass a visitor directly if you only want an enter visitor)'
|
|
85679
|
+
)
|
|
85680
|
+
}
|
|
85499
85681
|
} else {
|
|
85500
|
-
|
|
85501
|
-
|
|
85682
|
+
throw new Error(
|
|
85683
|
+
'Unexpected value `' +
|
|
85684
|
+
visitors +
|
|
85685
|
+
'` for `enter` or `visitors`, expected visitor or object with visitors'
|
|
85686
|
+
)
|
|
85502
85687
|
}
|
|
85503
85688
|
|
|
85504
85689
|
const is = convert(check)
|
|
85505
|
-
const step =
|
|
85690
|
+
const step = preorder ? 1 : -1
|
|
85506
85691
|
|
|
85507
85692
|
factory(tree, undefined, [])()
|
|
85508
85693
|
|
|
85509
85694
|
/**
|
|
85695
|
+
* Create a function to visit a node.
|
|
85696
|
+
*
|
|
85510
85697
|
* @param {UnistNode} node
|
|
85698
|
+
* Node to visit.
|
|
85511
85699
|
* @param {number | undefined} index
|
|
85700
|
+
* Index of `node` in its parent.
|
|
85512
85701
|
* @param {Array<UnistParent>} parents
|
|
85702
|
+
* Ancestors of `node`.
|
|
85703
|
+
* @returns {() => Readonly<ActionTuple>}
|
|
85704
|
+
* Visit `node`.
|
|
85513
85705
|
*/
|
|
85514
85706
|
function factory(node, index, parents) {
|
|
85515
85707
|
const value = /** @type {Record<string, unknown>} */ (
|
|
@@ -85535,18 +85727,13 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
85535
85727
|
return visit
|
|
85536
85728
|
|
|
85537
85729
|
function visit() {
|
|
85730
|
+
const matches =
|
|
85731
|
+
!check || is(node, index, parents[parents.length - 1] || undefined)
|
|
85538
85732
|
/** @type {Readonly<ActionTuple>} */
|
|
85539
85733
|
let result = lib_empty
|
|
85540
|
-
/** @type {Readonly<ActionTuple>} */
|
|
85541
|
-
let subresult
|
|
85542
|
-
/** @type {number} */
|
|
85543
|
-
let offset
|
|
85544
|
-
/** @type {Array<UnistParent>} */
|
|
85545
|
-
let grandparents
|
|
85546
85734
|
|
|
85547
|
-
if (
|
|
85548
|
-
|
|
85549
|
-
result = lib_toResult(visitor(node, parents))
|
|
85735
|
+
if (enter && matches) {
|
|
85736
|
+
result = lib_toResult(enter(node, parents, index))
|
|
85550
85737
|
|
|
85551
85738
|
if (result[0] === EXIT) {
|
|
85552
85739
|
return result
|
|
@@ -85557,13 +85744,13 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
85557
85744
|
const nodeAsParent = /** @type {UnistParent} */ (node)
|
|
85558
85745
|
|
|
85559
85746
|
if (nodeAsParent.children && result[0] !== SKIP) {
|
|
85560
|
-
offset = (
|
|
85561
|
-
grandparents = parents
|
|
85747
|
+
let offset = (preorder ? -1 : nodeAsParent.children.length) + step
|
|
85748
|
+
const grandparents = [...parents, nodeAsParent]
|
|
85562
85749
|
|
|
85563
85750
|
while (offset > -1 && offset < nodeAsParent.children.length) {
|
|
85564
85751
|
const child = nodeAsParent.children[offset]
|
|
85565
85752
|
|
|
85566
|
-
subresult = factory(child, offset, grandparents)()
|
|
85753
|
+
const subresult = factory(child, offset, grandparents)()
|
|
85567
85754
|
|
|
85568
85755
|
if (subresult[0] === EXIT) {
|
|
85569
85756
|
return subresult
|
|
@@ -85575,6 +85762,23 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
85575
85762
|
}
|
|
85576
85763
|
}
|
|
85577
85764
|
|
|
85765
|
+
if (exit && matches) {
|
|
85766
|
+
const exitResult = lib_toResult(exit(node, parents, index))
|
|
85767
|
+
|
|
85768
|
+
if (exitResult[0] === SKIP) {
|
|
85769
|
+
throw new Error(
|
|
85770
|
+
'Unexpected value `' +
|
|
85771
|
+
exitResult[0] +
|
|
85772
|
+
'` from `exit`, expected `CONTINUE`, `EXIT`, index, or nothing'
|
|
85773
|
+
)
|
|
85774
|
+
}
|
|
85775
|
+
|
|
85776
|
+
// Prefer a result from `exit` over `enter`.
|
|
85777
|
+
if (exitResult[0] === EXIT || typeof exitResult[1] === 'number') {
|
|
85778
|
+
return exitResult
|
|
85779
|
+
}
|
|
85780
|
+
}
|
|
85781
|
+
|
|
85578
85782
|
return result
|
|
85579
85783
|
}
|
|
85580
85784
|
}
|
|
@@ -85603,7 +85807,13 @@ function lib_toResult(value) {
|
|
|
85603
85807
|
;// CONCATENATED MODULE: ../../node_modules/unist-util-visit/lib/index.js
|
|
85604
85808
|
/**
|
|
85605
85809
|
* @import {Node as UnistNode, Parent as UnistParent} from 'unist'
|
|
85606
|
-
* @import {
|
|
85810
|
+
* @import {
|
|
85811
|
+
* InclusiveDescendant,
|
|
85812
|
+
* Matches,
|
|
85813
|
+
* Visitors as ParentsVisitors,
|
|
85814
|
+
* VisitorResult,
|
|
85815
|
+
* VisitorResultExit
|
|
85816
|
+
* } from 'unist-util-visit-parents'
|
|
85607
85817
|
*/
|
|
85608
85818
|
|
|
85609
85819
|
/**
|
|
@@ -85615,67 +85825,6 @@ function lib_toResult(value) {
|
|
|
85615
85825
|
* which doesn’t work when publishing on npm.
|
|
85616
85826
|
*/
|
|
85617
85827
|
|
|
85618
|
-
// To do: use types from `unist-util-visit-parents` when it’s released.
|
|
85619
|
-
|
|
85620
|
-
/**
|
|
85621
|
-
* @typedef {(
|
|
85622
|
-
* Fn extends (value: any) => value is infer Thing
|
|
85623
|
-
* ? Thing
|
|
85624
|
-
* : Fallback
|
|
85625
|
-
* )} Predicate
|
|
85626
|
-
* Get the value of a type guard `Fn`.
|
|
85627
|
-
* @template Fn
|
|
85628
|
-
* Value; typically function that is a type guard (such as `(x): x is Y`).
|
|
85629
|
-
* @template Fallback
|
|
85630
|
-
* Value to yield if `Fn` is not a type guard.
|
|
85631
|
-
*/
|
|
85632
|
-
|
|
85633
|
-
/**
|
|
85634
|
-
* @typedef {(
|
|
85635
|
-
* Check extends null | undefined // No test.
|
|
85636
|
-
* ? Value
|
|
85637
|
-
* : Value extends {type: Check} // String (type) test.
|
|
85638
|
-
* ? Value
|
|
85639
|
-
* : Value extends Check // Partial test.
|
|
85640
|
-
* ? Value
|
|
85641
|
-
* : Check extends Function // Function test.
|
|
85642
|
-
* ? Predicate<Check, Value> extends Value
|
|
85643
|
-
* ? Predicate<Check, Value>
|
|
85644
|
-
* : never
|
|
85645
|
-
* : never // Some other test?
|
|
85646
|
-
* )} MatchesOne
|
|
85647
|
-
* Check whether a node matches a primitive check in the type system.
|
|
85648
|
-
* @template Value
|
|
85649
|
-
* Value; typically unist `Node`.
|
|
85650
|
-
* @template Check
|
|
85651
|
-
* Value; typically `unist-util-is`-compatible test, but not arrays.
|
|
85652
|
-
*/
|
|
85653
|
-
|
|
85654
|
-
/**
|
|
85655
|
-
* @typedef {(
|
|
85656
|
-
* Check extends ReadonlyArray<any>
|
|
85657
|
-
* ? MatchesOne<Value, Check[number]>
|
|
85658
|
-
* : MatchesOne<Value, Check>
|
|
85659
|
-
* )} Matches
|
|
85660
|
-
* Check whether a node matches a check in the type system.
|
|
85661
|
-
* @template Value
|
|
85662
|
-
* Value; typically unist `Node`.
|
|
85663
|
-
* @template Check
|
|
85664
|
-
* Value; typically `unist-util-is`-compatible test.
|
|
85665
|
-
*/
|
|
85666
|
-
|
|
85667
|
-
/**
|
|
85668
|
-
* @typedef {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} Uint
|
|
85669
|
-
* Number; capped reasonably.
|
|
85670
|
-
*/
|
|
85671
|
-
|
|
85672
|
-
/**
|
|
85673
|
-
* @typedef {I extends 0 ? 1 : I extends 1 ? 2 : I extends 2 ? 3 : I extends 3 ? 4 : I extends 4 ? 5 : I extends 5 ? 6 : I extends 6 ? 7 : I extends 7 ? 8 : I extends 8 ? 9 : 10} Increment
|
|
85674
|
-
* Increment a number in the type system.
|
|
85675
|
-
* @template {Uint} [I=0]
|
|
85676
|
-
* Index.
|
|
85677
|
-
*/
|
|
85678
|
-
|
|
85679
85828
|
/**
|
|
85680
85829
|
* @typedef {(
|
|
85681
85830
|
* Node extends UnistParent
|
|
@@ -85701,89 +85850,64 @@ function lib_toResult(value) {
|
|
|
85701
85850
|
*/
|
|
85702
85851
|
|
|
85703
85852
|
/**
|
|
85704
|
-
* @
|
|
85705
|
-
*
|
|
85706
|
-
* ? never
|
|
85707
|
-
* :
|
|
85708
|
-
* | InternalParent<Node, Child>
|
|
85709
|
-
* | InternalAncestor<Node, InternalParent<Node, Child>, Max, Increment<Depth>>
|
|
85710
|
-
* )} InternalAncestor
|
|
85711
|
-
* Collect nodes in `Tree` that can be ancestors of `Child`.
|
|
85712
|
-
* @template {UnistNode} Node
|
|
85713
|
-
* All node types in a tree.
|
|
85714
|
-
* @template {UnistNode} Child
|
|
85715
|
-
* Node to search for.
|
|
85716
|
-
* @template {Uint} [Max=10]
|
|
85717
|
-
* Max; searches up to this depth.
|
|
85718
|
-
* @template {Uint} [Depth=0]
|
|
85719
|
-
* Current depth.
|
|
85720
|
-
*/
|
|
85721
|
-
|
|
85722
|
-
/**
|
|
85723
|
-
* @typedef {(
|
|
85724
|
-
* Tree extends UnistParent
|
|
85725
|
-
* ? Depth extends Max
|
|
85726
|
-
* ? Tree
|
|
85727
|
-
* : Tree | InclusiveDescendant<Tree['children'][number], Max, Increment<Depth>>
|
|
85728
|
-
* : Tree
|
|
85729
|
-
* )} InclusiveDescendant
|
|
85730
|
-
* Collect all (inclusive) descendants of `Tree`.
|
|
85853
|
+
* @callback Visitor
|
|
85854
|
+
* Handle a node (matching `test`, if given) before its children.
|
|
85731
85855
|
*
|
|
85732
|
-
*
|
|
85733
|
-
*
|
|
85734
|
-
*
|
|
85735
|
-
*
|
|
85736
|
-
*
|
|
85737
|
-
*
|
|
85738
|
-
*
|
|
85739
|
-
*
|
|
85740
|
-
*
|
|
85741
|
-
*
|
|
85742
|
-
* @
|
|
85743
|
-
*
|
|
85744
|
-
* @template {
|
|
85745
|
-
*
|
|
85856
|
+
* Like `Visitor` in `unist-util-visit-parents`,
|
|
85857
|
+
* but with `index` and `parent` instead of `parents`.
|
|
85858
|
+
* @param {Visited} node
|
|
85859
|
+
* Found node.
|
|
85860
|
+
* @param {Visited extends UnistNode ? number | undefined : never} index
|
|
85861
|
+
* Index of `node` in `parent`,
|
|
85862
|
+
* or `undefined` for the tree itself.
|
|
85863
|
+
* @param {Ancestor extends UnistParent ? Ancestor | undefined : never} parent
|
|
85864
|
+
* Parent of `node`,
|
|
85865
|
+
* or `undefined` for the tree itself.
|
|
85866
|
+
* @returns {VisitorResult}
|
|
85867
|
+
* What to do next.
|
|
85868
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
85869
|
+
* Visited node type.
|
|
85870
|
+
* @template {UnistParent} [Ancestor=UnistParent]
|
|
85871
|
+
* Ancestor type.
|
|
85746
85872
|
*/
|
|
85747
85873
|
|
|
85748
85874
|
/**
|
|
85749
|
-
* @callback
|
|
85750
|
-
* Handle a node (matching `test`, if given).
|
|
85751
|
-
*
|
|
85752
|
-
* Visitors are free to transform `node`.
|
|
85753
|
-
* They can also transform `parent`.
|
|
85875
|
+
* @callback VisitorExit
|
|
85876
|
+
* Handle a node (matching `test`, if given) after its children.
|
|
85754
85877
|
*
|
|
85755
|
-
*
|
|
85756
|
-
*
|
|
85757
|
-
*
|
|
85758
|
-
* When adding or removing previous siblings of `node` (or next siblings, in
|
|
85759
|
-
* case of reverse), the `Visitor` should return a new `Index` to specify the
|
|
85760
|
-
* sibling to traverse after `node` is traversed.
|
|
85761
|
-
* Adding or removing next siblings of `node` (or previous siblings, in case
|
|
85762
|
-
* of reverse) is handled as expected without needing to return a new `Index`.
|
|
85763
|
-
*
|
|
85764
|
-
* Removing the children property of `parent` still results in them being
|
|
85765
|
-
* traversed.
|
|
85878
|
+
* Like `VisitorExit` in `unist-util-visit-parents`,
|
|
85879
|
+
* but with `index` and `parent` instead of `parents`.
|
|
85766
85880
|
* @param {Visited} node
|
|
85767
85881
|
* Found node.
|
|
85768
85882
|
* @param {Visited extends UnistNode ? number | undefined : never} index
|
|
85769
|
-
* Index of `node` in `parent
|
|
85883
|
+
* Index of `node` in `parent`,
|
|
85884
|
+
* or `undefined` for the tree itself.
|
|
85770
85885
|
* @param {Ancestor extends UnistParent ? Ancestor | undefined : never} parent
|
|
85771
|
-
* Parent of `node
|
|
85772
|
-
*
|
|
85886
|
+
* Parent of `node`,
|
|
85887
|
+
* or `undefined` for the tree itself.
|
|
85888
|
+
* @returns {VisitorResultExit}
|
|
85773
85889
|
* What to do next.
|
|
85774
|
-
*
|
|
85775
|
-
* An `Index` is treated as a tuple of `[CONTINUE, Index]`.
|
|
85776
|
-
* An `Action` is treated as a tuple of `[Action]`.
|
|
85777
|
-
*
|
|
85778
|
-
* Passing a tuple back only makes sense if the `Action` is `SKIP`.
|
|
85779
|
-
* When the `Action` is `EXIT`, that action can be returned.
|
|
85780
|
-
* When the `Action` is `CONTINUE`, `Index` can be returned.
|
|
85781
85890
|
* @template {UnistNode} [Visited=UnistNode]
|
|
85782
85891
|
* Visited node type.
|
|
85783
85892
|
* @template {UnistParent} [Ancestor=UnistParent]
|
|
85784
85893
|
* Ancestor type.
|
|
85785
85894
|
*/
|
|
85786
85895
|
|
|
85896
|
+
/**
|
|
85897
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
85898
|
+
* Visited node type.
|
|
85899
|
+
* @template {UnistParent} [Ancestor=UnistParent]
|
|
85900
|
+
* Ancestor type.
|
|
85901
|
+
* @typedef Visitors
|
|
85902
|
+
* Handle nodes when entering and exiting them.
|
|
85903
|
+
*
|
|
85904
|
+
* Like `Visitors` in `unist-util-visit-parents`.
|
|
85905
|
+
* @property {Visitor<Visited, Ancestor> | null | undefined} [enter]
|
|
85906
|
+
* Handle a node before its children (optional).
|
|
85907
|
+
* @property {VisitorExit<Visited, Ancestor>} exit
|
|
85908
|
+
* Handle a node after its children.
|
|
85909
|
+
*/
|
|
85910
|
+
|
|
85787
85911
|
/**
|
|
85788
85912
|
* @typedef {Visitor<Visited, Parent<Ancestor, Visited>>} BuildVisitorFromMatch
|
|
85789
85913
|
* Build a typed `Visitor` function from a node and all possible parents.
|
|
@@ -85827,6 +85951,25 @@ function lib_toResult(value) {
|
|
|
85827
85951
|
* Test type.
|
|
85828
85952
|
*/
|
|
85829
85953
|
|
|
85954
|
+
/**
|
|
85955
|
+
* @typedef {(
|
|
85956
|
+
* Visitors<
|
|
85957
|
+
* Matches<InclusiveDescendant<Tree>, Check>,
|
|
85958
|
+
* Parent<
|
|
85959
|
+
* Extract<InclusiveDescendant<Tree>, UnistParent>,
|
|
85960
|
+
* Matches<InclusiveDescendant<Tree>, Check>
|
|
85961
|
+
* >
|
|
85962
|
+
* >
|
|
85963
|
+
* )} BuildVisitors
|
|
85964
|
+
* Build typed `Visitors` from a tree and a test.
|
|
85965
|
+
*
|
|
85966
|
+
* It will infer which values are passed as `node` and which as `parent`.
|
|
85967
|
+
* @template {UnistNode} [Tree=UnistNode]
|
|
85968
|
+
* Node type.
|
|
85969
|
+
* @template {Test} [Check=Test]
|
|
85970
|
+
* Test type.
|
|
85971
|
+
*/
|
|
85972
|
+
|
|
85830
85973
|
|
|
85831
85974
|
|
|
85832
85975
|
|
|
@@ -85835,10 +85978,13 @@ function lib_toResult(value) {
|
|
|
85835
85978
|
* Visit nodes.
|
|
85836
85979
|
*
|
|
85837
85980
|
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
|
85838
|
-
* (**NLR**) or if `reverse` is given,
|
|
85981
|
+
* (**NLR**) or if `reverse` is given,
|
|
85982
|
+
* in *reverse preorder* (**NRL**).
|
|
85983
|
+
* An `exit` visitor is called in *postorder* (**LRN**)
|
|
85984
|
+
* or if `reverse` is given, in *reverse postorder* (**RLN**).
|
|
85839
85985
|
*
|
|
85840
|
-
* You can choose
|
|
85841
|
-
* For complex tests, you should test yourself in
|
|
85986
|
+
* You can choose which nodes are visited by passing a `test`.
|
|
85987
|
+
* For complex tests, you should test yourself in a visitor, as it will be
|
|
85842
85988
|
* faster and will have improved type information.
|
|
85843
85989
|
*
|
|
85844
85990
|
* Walking the tree is an intensive task.
|
|
@@ -85847,29 +85993,48 @@ function lib_toResult(value) {
|
|
|
85847
85993
|
* to check if a node matches, and then perform different operations.
|
|
85848
85994
|
*
|
|
85849
85995
|
* You can change the tree.
|
|
85850
|
-
*
|
|
85996
|
+
* Changes inside a node made when entering it are walked,
|
|
85997
|
+
* changes made when exiting it are not.
|
|
85998
|
+
* See `Visitor` and `VisitorExit` for more info.
|
|
85851
85999
|
*
|
|
85852
86000
|
* @overload
|
|
85853
86001
|
* @param {Tree} tree
|
|
86002
|
+
* Tree to traverse.
|
|
85854
86003
|
* @param {Check} check
|
|
85855
|
-
*
|
|
86004
|
+
* `unist-util-is`-compatible test.
|
|
86005
|
+
* @param {BuildVisitor<Tree, Check> | BuildVisitors<Tree, Check>} visitors
|
|
86006
|
+
* Handle each node when entering it,
|
|
86007
|
+
* or `{enter, exit}` to also handle it when exiting it.
|
|
85856
86008
|
* @param {boolean | null | undefined} [reverse]
|
|
86009
|
+
* Walk children from last to first;
|
|
86010
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
86011
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
85857
86012
|
* @returns {undefined}
|
|
86013
|
+
* Nothing.
|
|
85858
86014
|
*
|
|
85859
86015
|
* @overload
|
|
85860
86016
|
* @param {Tree} tree
|
|
85861
|
-
*
|
|
86017
|
+
* Tree to traverse.
|
|
86018
|
+
* @param {BuildVisitor<Tree> | BuildVisitors<Tree>} visitors
|
|
86019
|
+
* Handle each node when entering it,
|
|
86020
|
+
* or `{enter, exit}` to also handle it when exiting it.
|
|
85862
86021
|
* @param {boolean | null | undefined} [reverse]
|
|
86022
|
+
* Walk children from last to first;
|
|
86023
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
86024
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
85863
86025
|
* @returns {undefined}
|
|
86026
|
+
* Nothing.
|
|
85864
86027
|
*
|
|
85865
86028
|
* @param {UnistNode} tree
|
|
85866
86029
|
* Tree to traverse.
|
|
85867
|
-
* @param {Visitor | Test}
|
|
85868
|
-
* `unist-util-is`-compatible test
|
|
85869
|
-
* @param {Visitor | boolean | null | undefined} [
|
|
85870
|
-
*
|
|
85871
|
-
* @param {boolean | null | undefined} [maybeReverse
|
|
85872
|
-
*
|
|
86030
|
+
* @param {Visitor | Visitors | Test} testOrEnterOrVisitors
|
|
86031
|
+
* `unist-util-is`-compatible test, `enter`, or `visitors`.
|
|
86032
|
+
* @param {Visitor | Visitors | boolean | null | undefined} [enterOrVisitorsOrReverse]
|
|
86033
|
+
* `enter`, `visitors`, or `reverse` after a test.
|
|
86034
|
+
* @param {boolean | null | undefined} [maybeReverse]
|
|
86035
|
+
* Walk children from last to first;
|
|
86036
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
86037
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
85873
86038
|
* @returns {undefined}
|
|
85874
86039
|
* Nothing.
|
|
85875
86040
|
*
|
|
@@ -85878,39 +86043,90 @@ function lib_toResult(value) {
|
|
|
85878
86043
|
* @template {Test} Check
|
|
85879
86044
|
* `unist-util-is`-compatible test.
|
|
85880
86045
|
*/
|
|
85881
|
-
function lib_visit(
|
|
86046
|
+
function lib_visit(
|
|
86047
|
+
tree,
|
|
86048
|
+
testOrEnterOrVisitors,
|
|
86049
|
+
enterOrVisitorsOrReverse,
|
|
86050
|
+
maybeReverse
|
|
86051
|
+
) {
|
|
86052
|
+
/** @type {Test} */
|
|
86053
|
+
let check
|
|
86054
|
+
/** @type {Visitor | Visitors} */
|
|
86055
|
+
let visitors
|
|
85882
86056
|
/** @type {boolean | null | undefined} */
|
|
85883
86057
|
let reverse
|
|
85884
|
-
/** @type {Test} */
|
|
85885
|
-
let test
|
|
85886
|
-
/** @type {Visitor} */
|
|
85887
|
-
let visitor
|
|
85888
86058
|
|
|
86059
|
+
// Third parameter is an enter visitor or a visitors object, so expect a `test` too.
|
|
85889
86060
|
if (
|
|
85890
|
-
typeof
|
|
85891
|
-
typeof
|
|
86061
|
+
typeof enterOrVisitorsOrReverse === 'function' ||
|
|
86062
|
+
(enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === 'object')
|
|
85892
86063
|
) {
|
|
85893
|
-
|
|
85894
|
-
|
|
85895
|
-
reverse = visitorOrReverse
|
|
85896
|
-
} else {
|
|
85897
|
-
// @ts-expect-error: assume the overload with test was given.
|
|
85898
|
-
test = testOrVisitor
|
|
85899
|
-
// @ts-expect-error: assume the overload with test was given.
|
|
85900
|
-
visitor = visitorOrReverse
|
|
86064
|
+
check = /** @type {Test} */ (testOrEnterOrVisitors)
|
|
86065
|
+
visitors = enterOrVisitorsOrReverse
|
|
85901
86066
|
reverse = maybeReverse
|
|
85902
86067
|
}
|
|
86068
|
+
// Assume no test.
|
|
86069
|
+
else {
|
|
86070
|
+
visitors = /** @type {Visitor | Visitors} */ (testOrEnterOrVisitors)
|
|
86071
|
+
reverse = enterOrVisitorsOrReverse
|
|
86072
|
+
}
|
|
86073
|
+
|
|
86074
|
+
if (typeof visitors === 'function') {
|
|
86075
|
+
visitParents(tree, check, lib_wrap(visitors), reverse)
|
|
86076
|
+
} else {
|
|
86077
|
+
visitParents(tree, check, wrapVisitors(visitors), reverse)
|
|
86078
|
+
}
|
|
86079
|
+
}
|
|
86080
|
+
|
|
86081
|
+
/**
|
|
86082
|
+
* Turn `visit` visitors into `visitParents` visitors.
|
|
86083
|
+
*
|
|
86084
|
+
* @param {Visitors} visitors
|
|
86085
|
+
* Visitors for `visit`.
|
|
86086
|
+
* @returns {ParentsVisitors}
|
|
86087
|
+
* Visitors for `visitParents`.
|
|
86088
|
+
*/
|
|
86089
|
+
function wrapVisitors(visitors) {
|
|
86090
|
+
// Pass anything else straight to `visitParents` to get its errors.
|
|
86091
|
+
if (!visitors || typeof visitors !== 'object') return visitors
|
|
86092
|
+
|
|
86093
|
+
return {
|
|
86094
|
+
enter:
|
|
86095
|
+
typeof visitors.enter === 'function'
|
|
86096
|
+
? lib_wrap(visitors.enter)
|
|
86097
|
+
: visitors.enter,
|
|
86098
|
+
exit:
|
|
86099
|
+
typeof visitors.exit === 'function' ? lib_wrap(visitors.exit) : visitors.exit
|
|
86100
|
+
}
|
|
86101
|
+
}
|
|
85903
86102
|
|
|
85904
|
-
|
|
86103
|
+
/**
|
|
86104
|
+
* Turn a `visit` visitor into a `visitParents` one.
|
|
86105
|
+
*
|
|
86106
|
+
* @template {VisitorResult} Result
|
|
86107
|
+
* Result type.
|
|
86108
|
+
* @param {(node: UnistNode, index: number | undefined, parent: UnistParent | undefined) => Result} visitor
|
|
86109
|
+
* Visitor for `visit`.
|
|
86110
|
+
* @returns {(node: UnistNode, parents: Array<UnistParent>, index: number | undefined) => Result}
|
|
86111
|
+
* Visitor for `visitParents`.
|
|
86112
|
+
*/
|
|
86113
|
+
function lib_wrap(visitor) {
|
|
86114
|
+
return overload
|
|
85905
86115
|
|
|
85906
86116
|
/**
|
|
86117
|
+
* Call `visitor` with `index` and `parent` instead of `parents`.
|
|
86118
|
+
*
|
|
85907
86119
|
* @param {UnistNode} node
|
|
86120
|
+
* Visited node.
|
|
85908
86121
|
* @param {Array<UnistParent>} parents
|
|
86122
|
+
* Ancestors of `node`.
|
|
86123
|
+
* @param {number | undefined} index
|
|
86124
|
+
* Index of `node` in its parent.
|
|
86125
|
+
* @returns {Result}
|
|
86126
|
+
* What to do next.
|
|
85909
86127
|
*/
|
|
85910
|
-
function overload(node, parents) {
|
|
85911
|
-
|
|
85912
|
-
const index = parent ? parent.children.indexOf(node) : undefined
|
|
85913
|
-
return visitor(node, index, parent)
|
|
86128
|
+
function overload(node, parents, index) {
|
|
86129
|
+
return visitor(node, index, parents[parents.length - 1])
|
|
85914
86130
|
}
|
|
85915
86131
|
}
|
|
85916
86132
|
|
|
@@ -89233,7 +89449,7 @@ function trough() {
|
|
|
89233
89449
|
|
|
89234
89450
|
// Next or done.
|
|
89235
89451
|
if (fn) {
|
|
89236
|
-
|
|
89452
|
+
trough_lib_wrap(fn, next)(...output)
|
|
89237
89453
|
} else {
|
|
89238
89454
|
callback(null, ...output)
|
|
89239
89455
|
}
|
|
@@ -89285,7 +89501,7 @@ function trough() {
|
|
|
89285
89501
|
* @returns {Run}
|
|
89286
89502
|
* Wrapped middleware.
|
|
89287
89503
|
*/
|
|
89288
|
-
function
|
|
89504
|
+
function trough_lib_wrap(middleware, callback) {
|
|
89289
89505
|
/** @type {boolean} */
|
|
89290
89506
|
let called
|
|
89291
89507
|
|