@lousy-agents/mcp 5.22.16 → 5.22.17
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/mcp-server.js +415 -216
- package/package.json +1 -1
package/dist/mcp-server.js
CHANGED
|
@@ -90330,8 +90330,12 @@ function encodeCharacterReference(code) {
|
|
|
90330
90330
|
|
|
90331
90331
|
;// CONCATENATED MODULE: ../../node_modules/unist-util-visit-parents/lib/color.node.js
|
|
90332
90332
|
/**
|
|
90333
|
+
* Color a string.
|
|
90334
|
+
*
|
|
90333
90335
|
* @param {string} d
|
|
90336
|
+
* Value.
|
|
90334
90337
|
* @returns {string}
|
|
90338
|
+
* Colored value.
|
|
90335
90339
|
*/
|
|
90336
90340
|
function color_node_color(d) {
|
|
90337
90341
|
return '\u001B[33m' + d + '\u001B[39m'
|
|
@@ -90507,44 +90511,96 @@ function color_node_color(d) {
|
|
|
90507
90511
|
* List with one or two values, the first an action, the second an index.
|
|
90508
90512
|
*
|
|
90509
90513
|
* @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult
|
|
90510
|
-
* Any value that can be returned from
|
|
90514
|
+
* Any value that can be returned from an enter visitor.
|
|
90515
|
+
*
|
|
90516
|
+
* Like `VisitorResultExit`,
|
|
90517
|
+
* but `SKIP` can also be returned,
|
|
90518
|
+
* to not walk the children of the node,
|
|
90519
|
+
* and `ActionTuple` can be used to combine an action with an index.
|
|
90520
|
+
*
|
|
90521
|
+
* @typedef {Index | boolean | null | undefined | void} VisitorResultExit
|
|
90522
|
+
* Any value that can be returned from an exit visitor.
|
|
90511
90523
|
*/
|
|
90512
90524
|
|
|
90513
90525
|
/**
|
|
90514
90526
|
* @callback Visitor
|
|
90515
|
-
* Handle a node (matching `test`, if given).
|
|
90516
|
-
*
|
|
90517
|
-
*
|
|
90518
|
-
*
|
|
90519
|
-
*
|
|
90520
|
-
*
|
|
90521
|
-
*
|
|
90522
|
-
*
|
|
90523
|
-
*
|
|
90524
|
-
*
|
|
90525
|
-
* sibling to traverse after `node` is traversed.
|
|
90526
|
-
* Adding or removing next siblings of `node` (or previous siblings, in case
|
|
90527
|
-
* of reverse) is handled as expected without needing to return a new `Index`.
|
|
90528
|
-
*
|
|
90529
|
-
* Removing the children property of an ancestor still results in them being
|
|
90530
|
-
* traversed.
|
|
90527
|
+
* Handle a node (matching `test`, if given) before its children.
|
|
90528
|
+
*
|
|
90529
|
+
* Changes inside `node` are walked next.
|
|
90530
|
+
* Replacing or removing it is easier in `exit`.
|
|
90531
|
+
* When replacing or removing it here,
|
|
90532
|
+
* return `SKIP` (as otherwise its old children are walked),
|
|
90533
|
+
* or `[SKIP, index]` to continue with the node now at `index`.
|
|
90534
|
+
* Changing next siblings (in walk order) is fine;
|
|
90535
|
+
* changing previous siblings needs a new `Index`.
|
|
90536
|
+
* Removing an ancestor or changing its previous siblings is not supported.
|
|
90531
90537
|
* @param {Visited} node
|
|
90532
90538
|
* Found node.
|
|
90533
90539
|
* @param {Array<VisitedParents>} ancestors
|
|
90534
90540
|
* Ancestors of `node`.
|
|
90541
|
+
* @param {number | undefined} index
|
|
90542
|
+
* Index of `node` in its parent (the last of `ancestors`),
|
|
90543
|
+
* or `undefined` for the tree itself.
|
|
90535
90544
|
* @returns {VisitorResult}
|
|
90536
90545
|
* What to do next.
|
|
90537
90546
|
*
|
|
90538
|
-
*
|
|
90539
|
-
*
|
|
90547
|
+
* Like `VisitorExit`,
|
|
90548
|
+
* but `SKIP` can also be returned,
|
|
90549
|
+
* to not walk the children of `node`.
|
|
90550
|
+
* Passing a tuple back (`ActionTuple`) only makes sense as `[SKIP, Index]`.
|
|
90551
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
90552
|
+
* Visited node type.
|
|
90553
|
+
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
90554
|
+
* Ancestor type.
|
|
90555
|
+
*/
|
|
90556
|
+
|
|
90557
|
+
/**
|
|
90558
|
+
* @callback VisitorExit
|
|
90559
|
+
* Handle a node (matching `test`, if given) after its children.
|
|
90560
|
+
*
|
|
90561
|
+
* Changes inside `node` are not walked,
|
|
90562
|
+
* which makes this a good place to change `node` based on its children,
|
|
90563
|
+
* or to replace or remove it.
|
|
90564
|
+
* When removing `node` or changing previous siblings (in walk order),
|
|
90565
|
+
* return a new `Index`.
|
|
90566
|
+
* Removing an ancestor or changing its previous siblings is not supported.
|
|
90567
|
+
* @param {Visited} node
|
|
90568
|
+
* Found node.
|
|
90569
|
+
* @param {Array<VisitedParents>} ancestors
|
|
90570
|
+
* Ancestors of `node`.
|
|
90571
|
+
* @param {number | undefined} index
|
|
90572
|
+
* Index of `node` in its parent (the last of `ancestors`),
|
|
90573
|
+
* or `undefined` for the tree itself.
|
|
90574
|
+
* @returns {VisitorResultExit}
|
|
90575
|
+
* What to do next.
|
|
90540
90576
|
*
|
|
90541
|
-
*
|
|
90542
|
-
*
|
|
90543
|
-
*
|
|
90577
|
+
* `CONTINUE` (`true`, nothing) continues as normal,
|
|
90578
|
+
* `EXIT` (`false`) stops traversing,
|
|
90579
|
+
* and `Index` continues at that sibling.
|
|
90580
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
90581
|
+
* Visited node type.
|
|
90582
|
+
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
90583
|
+
* Ancestor type.
|
|
90584
|
+
*/
|
|
90585
|
+
|
|
90586
|
+
/**
|
|
90544
90587
|
* @template {UnistNode} [Visited=UnistNode]
|
|
90545
90588
|
* Visited node type.
|
|
90546
90589
|
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
90547
90590
|
* Ancestor type.
|
|
90591
|
+
* @typedef Visitors
|
|
90592
|
+
* Handle nodes when entering and exiting them.
|
|
90593
|
+
* The `enter` visitor is optional while `exit` is required.
|
|
90594
|
+
*
|
|
90595
|
+
* Pass an `enter` visitor directly to only handle nodes when entering them.
|
|
90596
|
+
*
|
|
90597
|
+
* `enter` is called before children (if any) are walked and `exit` after that.
|
|
90598
|
+
* `exit` is still called when `enter` returns `SKIP`.
|
|
90599
|
+
* Both `enter` and `exit` are only called for nodes that match an optional `test`.
|
|
90600
|
+
* @property {Visitor<Visited, VisitedParents> | null | undefined} [enter]
|
|
90601
|
+
* Handle a node before its children (optional).
|
|
90602
|
+
* @property {VisitorExit<Visited, VisitedParents>} exit
|
|
90603
|
+
* Handle a node after its children.
|
|
90548
90604
|
*/
|
|
90549
90605
|
|
|
90550
90606
|
/**
|
|
@@ -90558,6 +90614,17 @@ function color_node_color(d) {
|
|
|
90558
90614
|
* Test type.
|
|
90559
90615
|
*/
|
|
90560
90616
|
|
|
90617
|
+
/**
|
|
90618
|
+
* @typedef {Visitors<Matches<InclusiveDescendant<Tree>, Check>, Ancestor<Tree, Matches<InclusiveDescendant<Tree>, Check>>>} BuildVisitors
|
|
90619
|
+
* Build typed `Visitors` from a tree and a test.
|
|
90620
|
+
*
|
|
90621
|
+
* It will infer which values are passed as `node` and which as `parents`.
|
|
90622
|
+
* @template {UnistNode} [Tree=UnistNode]
|
|
90623
|
+
* Tree type.
|
|
90624
|
+
* @template {Test} [Check=Test]
|
|
90625
|
+
* Test type.
|
|
90626
|
+
*/
|
|
90627
|
+
|
|
90561
90628
|
|
|
90562
90629
|
|
|
90563
90630
|
|
|
@@ -90576,6 +90643,7 @@ const EXIT = false
|
|
|
90576
90643
|
|
|
90577
90644
|
/**
|
|
90578
90645
|
* Do not traverse this node’s children.
|
|
90646
|
+
* Only works when entering a node.
|
|
90579
90647
|
*/
|
|
90580
90648
|
const SKIP = 'skip'
|
|
90581
90649
|
|
|
@@ -90583,10 +90651,13 @@ const SKIP = 'skip'
|
|
|
90583
90651
|
* Visit nodes, with ancestral information.
|
|
90584
90652
|
*
|
|
90585
90653
|
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
|
90586
|
-
* (**NLR**) or if `reverse` is given,
|
|
90654
|
+
* (**NLR**) or if `reverse` is given,
|
|
90655
|
+
* in *reverse preorder* (**NRL**).
|
|
90656
|
+
* An `exit` visitor is called in *postorder* (**LRN**)
|
|
90657
|
+
* or if `reverse` is given, in *reverse postorder* (**RLN**).
|
|
90587
90658
|
*
|
|
90588
|
-
* You can choose
|
|
90589
|
-
* For complex tests, you should test yourself in
|
|
90659
|
+
* You can choose which nodes are visited by passing a `test`.
|
|
90660
|
+
* For complex tests, you should test yourself in a visitor, as it will be
|
|
90590
90661
|
* faster and will have improved type information.
|
|
90591
90662
|
*
|
|
90592
90663
|
* Walking the tree is an intensive task.
|
|
@@ -90595,29 +90666,72 @@ const SKIP = 'skip'
|
|
|
90595
90666
|
* to check if a node matches, and then perform different operations.
|
|
90596
90667
|
*
|
|
90597
90668
|
* You can change the tree.
|
|
90598
|
-
*
|
|
90669
|
+
* Changes inside a node made when entering it are walked,
|
|
90670
|
+
* changes made when exiting it are not.
|
|
90671
|
+
* See `Visitor` and `VisitorExit` for more info.
|
|
90672
|
+
*
|
|
90673
|
+
* @overload
|
|
90674
|
+
* @param {Tree} tree
|
|
90675
|
+
* Tree to traverse.
|
|
90676
|
+
* @param {Check} check
|
|
90677
|
+
* `unist-util-is`-compatible test.
|
|
90678
|
+
* @param {BuildVisitor<Tree, Check>} enter
|
|
90679
|
+
* Handle each node when entering it.
|
|
90680
|
+
* @param {boolean | null | undefined} [reverse]
|
|
90681
|
+
* Walk children from last to first;
|
|
90682
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
90683
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
90684
|
+
* @returns {undefined}
|
|
90685
|
+
* Nothing.
|
|
90599
90686
|
*
|
|
90600
90687
|
* @overload
|
|
90601
90688
|
* @param {Tree} tree
|
|
90689
|
+
* Tree to traverse.
|
|
90602
90690
|
* @param {Check} check
|
|
90603
|
-
*
|
|
90691
|
+
* `unist-util-is`-compatible test.
|
|
90692
|
+
* @param {BuildVisitors<Tree, Check>} visitors
|
|
90693
|
+
* Handle each node when exiting it, and optionally when entering it.
|
|
90694
|
+
* @param {boolean | null | undefined} [reverse]
|
|
90695
|
+
* Walk children from last to first;
|
|
90696
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
90697
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
90698
|
+
* @returns {undefined}
|
|
90699
|
+
* Nothing.
|
|
90700
|
+
*
|
|
90701
|
+
* @overload
|
|
90702
|
+
* @param {Tree} tree
|
|
90703
|
+
* Tree to traverse.
|
|
90704
|
+
* @param {BuildVisitor<Tree>} enter
|
|
90705
|
+
* Handle each node when entering it.
|
|
90604
90706
|
* @param {boolean | null | undefined} [reverse]
|
|
90707
|
+
* Walk children from last to first;
|
|
90708
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
90709
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
90605
90710
|
* @returns {undefined}
|
|
90711
|
+
* Nothing.
|
|
90606
90712
|
*
|
|
90607
90713
|
* @overload
|
|
90608
90714
|
* @param {Tree} tree
|
|
90609
|
-
*
|
|
90715
|
+
* Tree to traverse.
|
|
90716
|
+
* @param {BuildVisitors<Tree>} visitors
|
|
90717
|
+
* Handle each node when exiting it, and optionally when entering it.
|
|
90610
90718
|
* @param {boolean | null | undefined} [reverse]
|
|
90719
|
+
* Walk children from last to first;
|
|
90720
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
90721
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
90611
90722
|
* @returns {undefined}
|
|
90723
|
+
* Nothing.
|
|
90612
90724
|
*
|
|
90613
90725
|
* @param {UnistNode} tree
|
|
90614
90726
|
* Tree to traverse.
|
|
90615
|
-
* @param {Visitor | Test}
|
|
90616
|
-
* `unist-util-is`-compatible test
|
|
90617
|
-
* @param {Visitor | boolean | null | undefined} [
|
|
90618
|
-
*
|
|
90727
|
+
* @param {Visitor | Visitors | Test} testOrEnterOrVisitors
|
|
90728
|
+
* `unist-util-is`-compatible test, `enter`, or `visitors`.
|
|
90729
|
+
* @param {Visitor | Visitors | boolean | null | undefined} [enterOrVisitorsOrReverse]
|
|
90730
|
+
* `enter`, `visitors`, or `reverse` after a test.
|
|
90619
90731
|
* @param {boolean | null | undefined} [reverse]
|
|
90620
|
-
*
|
|
90732
|
+
* Walk children from last to first;
|
|
90733
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
90734
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
90621
90735
|
* @returns {undefined}
|
|
90622
90736
|
* Nothing.
|
|
90623
90737
|
*
|
|
@@ -90626,28 +90740,89 @@ const SKIP = 'skip'
|
|
|
90626
90740
|
* @template {Test} Check
|
|
90627
90741
|
* `unist-util-is`-compatible test.
|
|
90628
90742
|
*/
|
|
90629
|
-
function visitParents(
|
|
90743
|
+
function visitParents(
|
|
90744
|
+
tree,
|
|
90745
|
+
testOrEnterOrVisitors,
|
|
90746
|
+
enterOrVisitorsOrReverse,
|
|
90747
|
+
reverse
|
|
90748
|
+
) {
|
|
90749
|
+
if (!tree || typeof tree !== 'object') {
|
|
90750
|
+
throw new Error('Unexpected value `' + tree + '` for `tree`, expected node')
|
|
90751
|
+
}
|
|
90752
|
+
|
|
90753
|
+
let preorder = true
|
|
90630
90754
|
/** @type {Test} */
|
|
90631
90755
|
let check
|
|
90756
|
+
/** @type {Visitors | Visitor} */
|
|
90757
|
+
let visitors
|
|
90758
|
+
/** @type {Visitor | null | undefined} */
|
|
90759
|
+
let enter
|
|
90760
|
+
/** @type {VisitorExit | null | undefined} */
|
|
90761
|
+
let exit
|
|
90762
|
+
|
|
90763
|
+
// Third parameter is an enter visitor or a visitors object, so expect a `test` too.
|
|
90764
|
+
if (
|
|
90765
|
+
typeof enterOrVisitorsOrReverse === 'function' ||
|
|
90766
|
+
(enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === 'object')
|
|
90767
|
+
) {
|
|
90768
|
+
check = /** @type {Test} */ (testOrEnterOrVisitors)
|
|
90769
|
+
visitors = enterOrVisitorsOrReverse
|
|
90770
|
+
if (reverse) preorder = false
|
|
90771
|
+
}
|
|
90772
|
+
// Assume no test.
|
|
90773
|
+
else {
|
|
90774
|
+
visitors = /** @type {Visitors | Visitor} */ (testOrEnterOrVisitors)
|
|
90775
|
+
if (enterOrVisitorsOrReverse) preorder = false
|
|
90776
|
+
}
|
|
90777
|
+
|
|
90778
|
+
if (typeof visitors === 'function') {
|
|
90779
|
+
enter = visitors
|
|
90780
|
+
} else if (visitors && typeof visitors === 'object') {
|
|
90781
|
+
if (visitors.enter === null || visitors.enter === undefined) {
|
|
90782
|
+
// Empty.
|
|
90783
|
+
} else if (typeof visitors.enter === 'function') {
|
|
90784
|
+
enter = visitors.enter
|
|
90785
|
+
} else {
|
|
90786
|
+
throw new Error(
|
|
90787
|
+
'Unexpected value `' +
|
|
90788
|
+
visitors.enter +
|
|
90789
|
+
'` for `visitors.enter`, expected optional visitor'
|
|
90790
|
+
)
|
|
90791
|
+
}
|
|
90632
90792
|
|
|
90633
|
-
|
|
90634
|
-
|
|
90635
|
-
|
|
90636
|
-
|
|
90793
|
+
if (typeof visitors.exit === 'function') {
|
|
90794
|
+
exit = visitors.exit
|
|
90795
|
+
} else {
|
|
90796
|
+
throw new Error(
|
|
90797
|
+
'Unexpected value `' +
|
|
90798
|
+
visitors.exit +
|
|
90799
|
+
'` for `visitors.exit`, expected visitor (pass a visitor directly if you only want an enter visitor)'
|
|
90800
|
+
)
|
|
90801
|
+
}
|
|
90637
90802
|
} else {
|
|
90638
|
-
|
|
90639
|
-
|
|
90803
|
+
throw new Error(
|
|
90804
|
+
'Unexpected value `' +
|
|
90805
|
+
visitors +
|
|
90806
|
+
'` for `enter` or `visitors`, expected visitor or object with visitors'
|
|
90807
|
+
)
|
|
90640
90808
|
}
|
|
90641
90809
|
|
|
90642
90810
|
const is = convert(check)
|
|
90643
|
-
const step =
|
|
90811
|
+
const step = preorder ? 1 : -1
|
|
90644
90812
|
|
|
90645
90813
|
factory(tree, undefined, [])()
|
|
90646
90814
|
|
|
90647
90815
|
/**
|
|
90816
|
+
* Create a function to visit a node.
|
|
90817
|
+
*
|
|
90648
90818
|
* @param {UnistNode} node
|
|
90819
|
+
* Node to visit.
|
|
90649
90820
|
* @param {number | undefined} index
|
|
90821
|
+
* Index of `node` in its parent.
|
|
90650
90822
|
* @param {Array<UnistParent>} parents
|
|
90823
|
+
* Ancestors of `node`.
|
|
90824
|
+
* @returns {() => Readonly<ActionTuple>}
|
|
90825
|
+
* Visit `node`.
|
|
90651
90826
|
*/
|
|
90652
90827
|
function factory(node, index, parents) {
|
|
90653
90828
|
const value = /** @type {Record<string, unknown>} */ (
|
|
@@ -90673,18 +90848,13 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
90673
90848
|
return visit
|
|
90674
90849
|
|
|
90675
90850
|
function visit() {
|
|
90851
|
+
const matches =
|
|
90852
|
+
!check || is(node, index, parents[parents.length - 1] || undefined)
|
|
90676
90853
|
/** @type {Readonly<ActionTuple>} */
|
|
90677
90854
|
let result = lib_empty
|
|
90678
|
-
/** @type {Readonly<ActionTuple>} */
|
|
90679
|
-
let subresult
|
|
90680
|
-
/** @type {number} */
|
|
90681
|
-
let offset
|
|
90682
|
-
/** @type {Array<UnistParent>} */
|
|
90683
|
-
let grandparents
|
|
90684
90855
|
|
|
90685
|
-
if (
|
|
90686
|
-
|
|
90687
|
-
result = toResult(visitor(node, parents))
|
|
90856
|
+
if (enter && matches) {
|
|
90857
|
+
result = toResult(enter(node, parents, index))
|
|
90688
90858
|
|
|
90689
90859
|
if (result[0] === EXIT) {
|
|
90690
90860
|
return result
|
|
@@ -90695,13 +90865,13 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
90695
90865
|
const nodeAsParent = /** @type {UnistParent} */ (node)
|
|
90696
90866
|
|
|
90697
90867
|
if (nodeAsParent.children && result[0] !== SKIP) {
|
|
90698
|
-
offset = (
|
|
90699
|
-
grandparents = parents
|
|
90868
|
+
let offset = (preorder ? -1 : nodeAsParent.children.length) + step
|
|
90869
|
+
const grandparents = [...parents, nodeAsParent]
|
|
90700
90870
|
|
|
90701
90871
|
while (offset > -1 && offset < nodeAsParent.children.length) {
|
|
90702
90872
|
const child = nodeAsParent.children[offset]
|
|
90703
90873
|
|
|
90704
|
-
subresult = factory(child, offset, grandparents)()
|
|
90874
|
+
const subresult = factory(child, offset, grandparents)()
|
|
90705
90875
|
|
|
90706
90876
|
if (subresult[0] === EXIT) {
|
|
90707
90877
|
return subresult
|
|
@@ -90713,6 +90883,23 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
90713
90883
|
}
|
|
90714
90884
|
}
|
|
90715
90885
|
|
|
90886
|
+
if (exit && matches) {
|
|
90887
|
+
const exitResult = toResult(exit(node, parents, index))
|
|
90888
|
+
|
|
90889
|
+
if (exitResult[0] === SKIP) {
|
|
90890
|
+
throw new Error(
|
|
90891
|
+
'Unexpected value `' +
|
|
90892
|
+
exitResult[0] +
|
|
90893
|
+
'` from `exit`, expected `CONTINUE`, `EXIT`, index, or nothing'
|
|
90894
|
+
)
|
|
90895
|
+
}
|
|
90896
|
+
|
|
90897
|
+
// Prefer a result from `exit` over `enter`.
|
|
90898
|
+
if (exitResult[0] === EXIT || typeof exitResult[1] === 'number') {
|
|
90899
|
+
return exitResult
|
|
90900
|
+
}
|
|
90901
|
+
}
|
|
90902
|
+
|
|
90716
90903
|
return result
|
|
90717
90904
|
}
|
|
90718
90905
|
}
|
|
@@ -90741,7 +90928,13 @@ function toResult(value) {
|
|
|
90741
90928
|
;// CONCATENATED MODULE: ../../node_modules/unist-util-visit/lib/index.js
|
|
90742
90929
|
/**
|
|
90743
90930
|
* @import {Node as UnistNode, Parent as UnistParent} from 'unist'
|
|
90744
|
-
* @import {
|
|
90931
|
+
* @import {
|
|
90932
|
+
* InclusiveDescendant,
|
|
90933
|
+
* Matches,
|
|
90934
|
+
* Visitors as ParentsVisitors,
|
|
90935
|
+
* VisitorResult,
|
|
90936
|
+
* VisitorResultExit
|
|
90937
|
+
* } from 'unist-util-visit-parents'
|
|
90745
90938
|
*/
|
|
90746
90939
|
|
|
90747
90940
|
/**
|
|
@@ -90753,67 +90946,6 @@ function toResult(value) {
|
|
|
90753
90946
|
* which doesn’t work when publishing on npm.
|
|
90754
90947
|
*/
|
|
90755
90948
|
|
|
90756
|
-
// To do: use types from `unist-util-visit-parents` when it’s released.
|
|
90757
|
-
|
|
90758
|
-
/**
|
|
90759
|
-
* @typedef {(
|
|
90760
|
-
* Fn extends (value: any) => value is infer Thing
|
|
90761
|
-
* ? Thing
|
|
90762
|
-
* : Fallback
|
|
90763
|
-
* )} Predicate
|
|
90764
|
-
* Get the value of a type guard `Fn`.
|
|
90765
|
-
* @template Fn
|
|
90766
|
-
* Value; typically function that is a type guard (such as `(x): x is Y`).
|
|
90767
|
-
* @template Fallback
|
|
90768
|
-
* Value to yield if `Fn` is not a type guard.
|
|
90769
|
-
*/
|
|
90770
|
-
|
|
90771
|
-
/**
|
|
90772
|
-
* @typedef {(
|
|
90773
|
-
* Check extends null | undefined // No test.
|
|
90774
|
-
* ? Value
|
|
90775
|
-
* : Value extends {type: Check} // String (type) test.
|
|
90776
|
-
* ? Value
|
|
90777
|
-
* : Value extends Check // Partial test.
|
|
90778
|
-
* ? Value
|
|
90779
|
-
* : Check extends Function // Function test.
|
|
90780
|
-
* ? Predicate<Check, Value> extends Value
|
|
90781
|
-
* ? Predicate<Check, Value>
|
|
90782
|
-
* : never
|
|
90783
|
-
* : never // Some other test?
|
|
90784
|
-
* )} MatchesOne
|
|
90785
|
-
* Check whether a node matches a primitive check in the type system.
|
|
90786
|
-
* @template Value
|
|
90787
|
-
* Value; typically unist `Node`.
|
|
90788
|
-
* @template Check
|
|
90789
|
-
* Value; typically `unist-util-is`-compatible test, but not arrays.
|
|
90790
|
-
*/
|
|
90791
|
-
|
|
90792
|
-
/**
|
|
90793
|
-
* @typedef {(
|
|
90794
|
-
* Check extends ReadonlyArray<any>
|
|
90795
|
-
* ? MatchesOne<Value, Check[number]>
|
|
90796
|
-
* : MatchesOne<Value, Check>
|
|
90797
|
-
* )} Matches
|
|
90798
|
-
* Check whether a node matches a check in the type system.
|
|
90799
|
-
* @template Value
|
|
90800
|
-
* Value; typically unist `Node`.
|
|
90801
|
-
* @template Check
|
|
90802
|
-
* Value; typically `unist-util-is`-compatible test.
|
|
90803
|
-
*/
|
|
90804
|
-
|
|
90805
|
-
/**
|
|
90806
|
-
* @typedef {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} Uint
|
|
90807
|
-
* Number; capped reasonably.
|
|
90808
|
-
*/
|
|
90809
|
-
|
|
90810
|
-
/**
|
|
90811
|
-
* @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
|
|
90812
|
-
* Increment a number in the type system.
|
|
90813
|
-
* @template {Uint} [I=0]
|
|
90814
|
-
* Index.
|
|
90815
|
-
*/
|
|
90816
|
-
|
|
90817
90949
|
/**
|
|
90818
90950
|
* @typedef {(
|
|
90819
90951
|
* Node extends UnistParent
|
|
@@ -90839,89 +90971,64 @@ function toResult(value) {
|
|
|
90839
90971
|
*/
|
|
90840
90972
|
|
|
90841
90973
|
/**
|
|
90842
|
-
* @
|
|
90843
|
-
*
|
|
90844
|
-
* ? never
|
|
90845
|
-
* :
|
|
90846
|
-
* | InternalParent<Node, Child>
|
|
90847
|
-
* | InternalAncestor<Node, InternalParent<Node, Child>, Max, Increment<Depth>>
|
|
90848
|
-
* )} InternalAncestor
|
|
90849
|
-
* Collect nodes in `Tree` that can be ancestors of `Child`.
|
|
90850
|
-
* @template {UnistNode} Node
|
|
90851
|
-
* All node types in a tree.
|
|
90852
|
-
* @template {UnistNode} Child
|
|
90853
|
-
* Node to search for.
|
|
90854
|
-
* @template {Uint} [Max=10]
|
|
90855
|
-
* Max; searches up to this depth.
|
|
90856
|
-
* @template {Uint} [Depth=0]
|
|
90857
|
-
* Current depth.
|
|
90858
|
-
*/
|
|
90859
|
-
|
|
90860
|
-
/**
|
|
90861
|
-
* @typedef {(
|
|
90862
|
-
* Tree extends UnistParent
|
|
90863
|
-
* ? Depth extends Max
|
|
90864
|
-
* ? Tree
|
|
90865
|
-
* : Tree | InclusiveDescendant<Tree['children'][number], Max, Increment<Depth>>
|
|
90866
|
-
* : Tree
|
|
90867
|
-
* )} InclusiveDescendant
|
|
90868
|
-
* Collect all (inclusive) descendants of `Tree`.
|
|
90974
|
+
* @callback Visitor
|
|
90975
|
+
* Handle a node (matching `test`, if given) before its children.
|
|
90869
90976
|
*
|
|
90870
|
-
*
|
|
90871
|
-
*
|
|
90872
|
-
*
|
|
90873
|
-
*
|
|
90874
|
-
*
|
|
90875
|
-
*
|
|
90876
|
-
*
|
|
90877
|
-
*
|
|
90878
|
-
*
|
|
90879
|
-
*
|
|
90880
|
-
* @
|
|
90881
|
-
*
|
|
90882
|
-
* @template {
|
|
90883
|
-
*
|
|
90977
|
+
* Like `Visitor` in `unist-util-visit-parents`,
|
|
90978
|
+
* but with `index` and `parent` instead of `parents`.
|
|
90979
|
+
* @param {Visited} node
|
|
90980
|
+
* Found node.
|
|
90981
|
+
* @param {Visited extends UnistNode ? number | undefined : never} index
|
|
90982
|
+
* Index of `node` in `parent`,
|
|
90983
|
+
* or `undefined` for the tree itself.
|
|
90984
|
+
* @param {Ancestor extends UnistParent ? Ancestor | undefined : never} parent
|
|
90985
|
+
* Parent of `node`,
|
|
90986
|
+
* or `undefined` for the tree itself.
|
|
90987
|
+
* @returns {VisitorResult}
|
|
90988
|
+
* What to do next.
|
|
90989
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
90990
|
+
* Visited node type.
|
|
90991
|
+
* @template {UnistParent} [Ancestor=UnistParent]
|
|
90992
|
+
* Ancestor type.
|
|
90884
90993
|
*/
|
|
90885
90994
|
|
|
90886
90995
|
/**
|
|
90887
|
-
* @callback
|
|
90888
|
-
* Handle a node (matching `test`, if given).
|
|
90889
|
-
*
|
|
90890
|
-
* Visitors are free to transform `node`.
|
|
90891
|
-
* They can also transform `parent`.
|
|
90892
|
-
*
|
|
90893
|
-
* Replacing `node` itself, if `SKIP` is not returned, still causes its
|
|
90894
|
-
* descendants to be walked (which is a bug).
|
|
90996
|
+
* @callback VisitorExit
|
|
90997
|
+
* Handle a node (matching `test`, if given) after its children.
|
|
90895
90998
|
*
|
|
90896
|
-
*
|
|
90897
|
-
*
|
|
90898
|
-
* sibling to traverse after `node` is traversed.
|
|
90899
|
-
* Adding or removing next siblings of `node` (or previous siblings, in case
|
|
90900
|
-
* of reverse) is handled as expected without needing to return a new `Index`.
|
|
90901
|
-
*
|
|
90902
|
-
* Removing the children property of `parent` still results in them being
|
|
90903
|
-
* traversed.
|
|
90999
|
+
* Like `VisitorExit` in `unist-util-visit-parents`,
|
|
91000
|
+
* but with `index` and `parent` instead of `parents`.
|
|
90904
91001
|
* @param {Visited} node
|
|
90905
91002
|
* Found node.
|
|
90906
91003
|
* @param {Visited extends UnistNode ? number | undefined : never} index
|
|
90907
|
-
* Index of `node` in `parent
|
|
91004
|
+
* Index of `node` in `parent`,
|
|
91005
|
+
* or `undefined` for the tree itself.
|
|
90908
91006
|
* @param {Ancestor extends UnistParent ? Ancestor | undefined : never} parent
|
|
90909
|
-
* Parent of `node
|
|
90910
|
-
*
|
|
91007
|
+
* Parent of `node`,
|
|
91008
|
+
* or `undefined` for the tree itself.
|
|
91009
|
+
* @returns {VisitorResultExit}
|
|
90911
91010
|
* What to do next.
|
|
90912
|
-
*
|
|
90913
|
-
* An `Index` is treated as a tuple of `[CONTINUE, Index]`.
|
|
90914
|
-
* An `Action` is treated as a tuple of `[Action]`.
|
|
90915
|
-
*
|
|
90916
|
-
* Passing a tuple back only makes sense if the `Action` is `SKIP`.
|
|
90917
|
-
* When the `Action` is `EXIT`, that action can be returned.
|
|
90918
|
-
* When the `Action` is `CONTINUE`, `Index` can be returned.
|
|
90919
91011
|
* @template {UnistNode} [Visited=UnistNode]
|
|
90920
91012
|
* Visited node type.
|
|
90921
91013
|
* @template {UnistParent} [Ancestor=UnistParent]
|
|
90922
91014
|
* Ancestor type.
|
|
90923
91015
|
*/
|
|
90924
91016
|
|
|
91017
|
+
/**
|
|
91018
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
91019
|
+
* Visited node type.
|
|
91020
|
+
* @template {UnistParent} [Ancestor=UnistParent]
|
|
91021
|
+
* Ancestor type.
|
|
91022
|
+
* @typedef Visitors
|
|
91023
|
+
* Handle nodes when entering and exiting them.
|
|
91024
|
+
*
|
|
91025
|
+
* Like `Visitors` in `unist-util-visit-parents`.
|
|
91026
|
+
* @property {Visitor<Visited, Ancestor> | null | undefined} [enter]
|
|
91027
|
+
* Handle a node before its children (optional).
|
|
91028
|
+
* @property {VisitorExit<Visited, Ancestor>} exit
|
|
91029
|
+
* Handle a node after its children.
|
|
91030
|
+
*/
|
|
91031
|
+
|
|
90925
91032
|
/**
|
|
90926
91033
|
* @typedef {Visitor<Visited, Parent<Ancestor, Visited>>} BuildVisitorFromMatch
|
|
90927
91034
|
* Build a typed `Visitor` function from a node and all possible parents.
|
|
@@ -90965,6 +91072,25 @@ function toResult(value) {
|
|
|
90965
91072
|
* Test type.
|
|
90966
91073
|
*/
|
|
90967
91074
|
|
|
91075
|
+
/**
|
|
91076
|
+
* @typedef {(
|
|
91077
|
+
* Visitors<
|
|
91078
|
+
* Matches<InclusiveDescendant<Tree>, Check>,
|
|
91079
|
+
* Parent<
|
|
91080
|
+
* Extract<InclusiveDescendant<Tree>, UnistParent>,
|
|
91081
|
+
* Matches<InclusiveDescendant<Tree>, Check>
|
|
91082
|
+
* >
|
|
91083
|
+
* >
|
|
91084
|
+
* )} BuildVisitors
|
|
91085
|
+
* Build typed `Visitors` from a tree and a test.
|
|
91086
|
+
*
|
|
91087
|
+
* It will infer which values are passed as `node` and which as `parent`.
|
|
91088
|
+
* @template {UnistNode} [Tree=UnistNode]
|
|
91089
|
+
* Node type.
|
|
91090
|
+
* @template {Test} [Check=Test]
|
|
91091
|
+
* Test type.
|
|
91092
|
+
*/
|
|
91093
|
+
|
|
90968
91094
|
|
|
90969
91095
|
|
|
90970
91096
|
|
|
@@ -90973,10 +91099,13 @@ function toResult(value) {
|
|
|
90973
91099
|
* Visit nodes.
|
|
90974
91100
|
*
|
|
90975
91101
|
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
|
90976
|
-
* (**NLR**) or if `reverse` is given,
|
|
91102
|
+
* (**NLR**) or if `reverse` is given,
|
|
91103
|
+
* in *reverse preorder* (**NRL**).
|
|
91104
|
+
* An `exit` visitor is called in *postorder* (**LRN**)
|
|
91105
|
+
* or if `reverse` is given, in *reverse postorder* (**RLN**).
|
|
90977
91106
|
*
|
|
90978
|
-
* You can choose
|
|
90979
|
-
* For complex tests, you should test yourself in
|
|
91107
|
+
* You can choose which nodes are visited by passing a `test`.
|
|
91108
|
+
* For complex tests, you should test yourself in a visitor, as it will be
|
|
90980
91109
|
* faster and will have improved type information.
|
|
90981
91110
|
*
|
|
90982
91111
|
* Walking the tree is an intensive task.
|
|
@@ -90985,29 +91114,48 @@ function toResult(value) {
|
|
|
90985
91114
|
* to check if a node matches, and then perform different operations.
|
|
90986
91115
|
*
|
|
90987
91116
|
* You can change the tree.
|
|
90988
|
-
*
|
|
91117
|
+
* Changes inside a node made when entering it are walked,
|
|
91118
|
+
* changes made when exiting it are not.
|
|
91119
|
+
* See `Visitor` and `VisitorExit` for more info.
|
|
90989
91120
|
*
|
|
90990
91121
|
* @overload
|
|
90991
91122
|
* @param {Tree} tree
|
|
91123
|
+
* Tree to traverse.
|
|
90992
91124
|
* @param {Check} check
|
|
90993
|
-
*
|
|
91125
|
+
* `unist-util-is`-compatible test.
|
|
91126
|
+
* @param {BuildVisitor<Tree, Check> | BuildVisitors<Tree, Check>} visitors
|
|
91127
|
+
* Handle each node when entering it,
|
|
91128
|
+
* or `{enter, exit}` to also handle it when exiting it.
|
|
90994
91129
|
* @param {boolean | null | undefined} [reverse]
|
|
91130
|
+
* Walk children from last to first;
|
|
91131
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
91132
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
90995
91133
|
* @returns {undefined}
|
|
91134
|
+
* Nothing.
|
|
90996
91135
|
*
|
|
90997
91136
|
* @overload
|
|
90998
91137
|
* @param {Tree} tree
|
|
90999
|
-
*
|
|
91138
|
+
* Tree to traverse.
|
|
91139
|
+
* @param {BuildVisitor<Tree> | BuildVisitors<Tree>} visitors
|
|
91140
|
+
* Handle each node when entering it,
|
|
91141
|
+
* or `{enter, exit}` to also handle it when exiting it.
|
|
91000
91142
|
* @param {boolean | null | undefined} [reverse]
|
|
91143
|
+
* Walk children from last to first;
|
|
91144
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
91145
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
91001
91146
|
* @returns {undefined}
|
|
91147
|
+
* Nothing.
|
|
91002
91148
|
*
|
|
91003
91149
|
* @param {UnistNode} tree
|
|
91004
91150
|
* Tree to traverse.
|
|
91005
|
-
* @param {Visitor | Test}
|
|
91006
|
-
* `unist-util-is`-compatible test
|
|
91007
|
-
* @param {Visitor | boolean | null | undefined} [
|
|
91008
|
-
*
|
|
91009
|
-
* @param {boolean | null | undefined} [maybeReverse
|
|
91010
|
-
*
|
|
91151
|
+
* @param {Visitor | Visitors | Test} testOrEnterOrVisitors
|
|
91152
|
+
* `unist-util-is`-compatible test, `enter`, or `visitors`.
|
|
91153
|
+
* @param {Visitor | Visitors | boolean | null | undefined} [enterOrVisitorsOrReverse]
|
|
91154
|
+
* `enter`, `visitors`, or `reverse` after a test.
|
|
91155
|
+
* @param {boolean | null | undefined} [maybeReverse]
|
|
91156
|
+
* Walk children from last to first;
|
|
91157
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
91158
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
91011
91159
|
* @returns {undefined}
|
|
91012
91160
|
* Nothing.
|
|
91013
91161
|
*
|
|
@@ -91016,39 +91164,90 @@ function toResult(value) {
|
|
|
91016
91164
|
* @template {Test} Check
|
|
91017
91165
|
* `unist-util-is`-compatible test.
|
|
91018
91166
|
*/
|
|
91019
|
-
function lib_visit(
|
|
91167
|
+
function lib_visit(
|
|
91168
|
+
tree,
|
|
91169
|
+
testOrEnterOrVisitors,
|
|
91170
|
+
enterOrVisitorsOrReverse,
|
|
91171
|
+
maybeReverse
|
|
91172
|
+
) {
|
|
91173
|
+
/** @type {Test} */
|
|
91174
|
+
let check
|
|
91175
|
+
/** @type {Visitor | Visitors} */
|
|
91176
|
+
let visitors
|
|
91020
91177
|
/** @type {boolean | null | undefined} */
|
|
91021
91178
|
let reverse
|
|
91022
|
-
/** @type {Test} */
|
|
91023
|
-
let test
|
|
91024
|
-
/** @type {Visitor} */
|
|
91025
|
-
let visitor
|
|
91026
91179
|
|
|
91180
|
+
// Third parameter is an enter visitor or a visitors object, so expect a `test` too.
|
|
91027
91181
|
if (
|
|
91028
|
-
typeof
|
|
91029
|
-
typeof
|
|
91182
|
+
typeof enterOrVisitorsOrReverse === 'function' ||
|
|
91183
|
+
(enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === 'object')
|
|
91030
91184
|
) {
|
|
91031
|
-
|
|
91032
|
-
|
|
91033
|
-
reverse = visitorOrReverse
|
|
91034
|
-
} else {
|
|
91035
|
-
// @ts-expect-error: assume the overload with test was given.
|
|
91036
|
-
test = testOrVisitor
|
|
91037
|
-
// @ts-expect-error: assume the overload with test was given.
|
|
91038
|
-
visitor = visitorOrReverse
|
|
91185
|
+
check = /** @type {Test} */ (testOrEnterOrVisitors)
|
|
91186
|
+
visitors = enterOrVisitorsOrReverse
|
|
91039
91187
|
reverse = maybeReverse
|
|
91040
91188
|
}
|
|
91189
|
+
// Assume no test.
|
|
91190
|
+
else {
|
|
91191
|
+
visitors = /** @type {Visitor | Visitors} */ (testOrEnterOrVisitors)
|
|
91192
|
+
reverse = enterOrVisitorsOrReverse
|
|
91193
|
+
}
|
|
91041
91194
|
|
|
91042
|
-
|
|
91195
|
+
if (typeof visitors === 'function') {
|
|
91196
|
+
visitParents(tree, check, lib_wrap(visitors), reverse)
|
|
91197
|
+
} else {
|
|
91198
|
+
visitParents(tree, check, wrapVisitors(visitors), reverse)
|
|
91199
|
+
}
|
|
91200
|
+
}
|
|
91201
|
+
|
|
91202
|
+
/**
|
|
91203
|
+
* Turn `visit` visitors into `visitParents` visitors.
|
|
91204
|
+
*
|
|
91205
|
+
* @param {Visitors} visitors
|
|
91206
|
+
* Visitors for `visit`.
|
|
91207
|
+
* @returns {ParentsVisitors}
|
|
91208
|
+
* Visitors for `visitParents`.
|
|
91209
|
+
*/
|
|
91210
|
+
function wrapVisitors(visitors) {
|
|
91211
|
+
// Pass anything else straight to `visitParents` to get its errors.
|
|
91212
|
+
if (!visitors || typeof visitors !== 'object') return visitors
|
|
91213
|
+
|
|
91214
|
+
return {
|
|
91215
|
+
enter:
|
|
91216
|
+
typeof visitors.enter === 'function'
|
|
91217
|
+
? lib_wrap(visitors.enter)
|
|
91218
|
+
: visitors.enter,
|
|
91219
|
+
exit:
|
|
91220
|
+
typeof visitors.exit === 'function' ? lib_wrap(visitors.exit) : visitors.exit
|
|
91221
|
+
}
|
|
91222
|
+
}
|
|
91223
|
+
|
|
91224
|
+
/**
|
|
91225
|
+
* Turn a `visit` visitor into a `visitParents` one.
|
|
91226
|
+
*
|
|
91227
|
+
* @template {VisitorResult} Result
|
|
91228
|
+
* Result type.
|
|
91229
|
+
* @param {(node: UnistNode, index: number | undefined, parent: UnistParent | undefined) => Result} visitor
|
|
91230
|
+
* Visitor for `visit`.
|
|
91231
|
+
* @returns {(node: UnistNode, parents: Array<UnistParent>, index: number | undefined) => Result}
|
|
91232
|
+
* Visitor for `visitParents`.
|
|
91233
|
+
*/
|
|
91234
|
+
function lib_wrap(visitor) {
|
|
91235
|
+
return overload
|
|
91043
91236
|
|
|
91044
91237
|
/**
|
|
91238
|
+
* Call `visitor` with `index` and `parent` instead of `parents`.
|
|
91239
|
+
*
|
|
91045
91240
|
* @param {UnistNode} node
|
|
91241
|
+
* Visited node.
|
|
91046
91242
|
* @param {Array<UnistParent>} parents
|
|
91243
|
+
* Ancestors of `node`.
|
|
91244
|
+
* @param {number | undefined} index
|
|
91245
|
+
* Index of `node` in its parent.
|
|
91246
|
+
* @returns {Result}
|
|
91247
|
+
* What to do next.
|
|
91047
91248
|
*/
|
|
91048
|
-
function overload(node, parents) {
|
|
91049
|
-
|
|
91050
|
-
const index = parent ? parent.children.indexOf(node) : undefined
|
|
91051
|
-
return visitor(node, index, parent)
|
|
91249
|
+
function overload(node, parents, index) {
|
|
91250
|
+
return visitor(node, index, parents[parents.length - 1])
|
|
91052
91251
|
}
|
|
91053
91252
|
}
|
|
91054
91253
|
|
|
@@ -94371,7 +94570,7 @@ function trough() {
|
|
|
94371
94570
|
|
|
94372
94571
|
// Next or done.
|
|
94373
94572
|
if (fn) {
|
|
94374
|
-
|
|
94573
|
+
trough_lib_wrap(fn, next)(...output)
|
|
94375
94574
|
} else {
|
|
94376
94575
|
callback(null, ...output)
|
|
94377
94576
|
}
|
|
@@ -94423,7 +94622,7 @@ function trough() {
|
|
|
94423
94622
|
* @returns {Run}
|
|
94424
94623
|
* Wrapped middleware.
|
|
94425
94624
|
*/
|
|
94426
|
-
function
|
|
94625
|
+
function trough_lib_wrap(middleware, callback) {
|
|
94427
94626
|
/** @type {boolean} */
|
|
94428
94627
|
let called
|
|
94429
94628
|
|