🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
14
node_modules/unist-util-visit-parents/complex-types.d.ts
generated
vendored
Normal file
14
node_modules/unist-util-visit-parents/complex-types.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// To do: next major: remove this file?
|
||||
export type {
|
||||
// Used in `unist-util-visit`:
|
||||
VisitorResult,
|
||||
|
||||
// Documented:
|
||||
Visitor,
|
||||
BuildVisitor
|
||||
} from './index.js'
|
||||
export type {
|
||||
// Used in `unist-util-visit`:
|
||||
Matches,
|
||||
InclusiveDescendant
|
||||
} from './lib/complex-types.js'
|
||||
10
node_modules/unist-util-visit-parents/index.d.ts
generated
vendored
Normal file
10
node_modules/unist-util-visit-parents/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
export type {Test} from 'unist-util-is'
|
||||
export type {
|
||||
Action,
|
||||
ActionTuple,
|
||||
BuildVisitor,
|
||||
Index,
|
||||
Visitor,
|
||||
VisitorResult
|
||||
} from './lib/index.js'
|
||||
export {CONTINUE, EXIT, SKIP, visitParents} from './lib/index.js'
|
||||
2
node_modules/unist-util-visit-parents/index.js
generated
vendored
Normal file
2
node_modules/unist-util-visit-parents/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// Note: types exported from `index.d.ts`
|
||||
export {CONTINUE, EXIT, SKIP, visitParents} from './lib/index.js'
|
||||
5
node_modules/unist-util-visit-parents/lib/color.browser.d.ts
generated
vendored
Normal file
5
node_modules/unist-util-visit-parents/lib/color.browser.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* @param {string} d
|
||||
* @returns {string}
|
||||
*/
|
||||
export function color(d: string): string;
|
||||
7
node_modules/unist-util-visit-parents/lib/color.browser.js
generated
vendored
Normal file
7
node_modules/unist-util-visit-parents/lib/color.browser.js
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* @param {string} d
|
||||
* @returns {string}
|
||||
*/
|
||||
export function color(d) {
|
||||
return d
|
||||
}
|
||||
5
node_modules/unist-util-visit-parents/lib/color.d.ts
generated
vendored
Normal file
5
node_modules/unist-util-visit-parents/lib/color.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* @param {string} d
|
||||
* @returns {string}
|
||||
*/
|
||||
export function color(d: string): string;
|
||||
7
node_modules/unist-util-visit-parents/lib/color.js
generated
vendored
Normal file
7
node_modules/unist-util-visit-parents/lib/color.js
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* @param {string} d
|
||||
* @returns {string}
|
||||
*/
|
||||
export function color(d) {
|
||||
return '\u001B[33m' + d + '\u001B[39m'
|
||||
}
|
||||
67
node_modules/unist-util-visit-parents/lib/complex-types.d.ts
generated
vendored
Normal file
67
node_modules/unist-util-visit-parents/lib/complex-types.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
|
||||
import type {Node, Parent} from 'unist'
|
||||
import type {Test} from 'unist-util-is'
|
||||
import type {Visitor} from './index.js'
|
||||
|
||||
/**
|
||||
* Internal utility to collect all descendants of in `Tree`.
|
||||
*/
|
||||
export type InclusiveDescendant<
|
||||
Tree extends Node = never,
|
||||
Found = void
|
||||
> = Tree extends Parent
|
||||
?
|
||||
| Tree
|
||||
| InclusiveDescendant<
|
||||
Exclude<Tree['children'][number], Found | Tree>,
|
||||
Found | Tree
|
||||
>
|
||||
: Tree
|
||||
|
||||
/**
|
||||
* Infer the thing that is asserted from a type guard.
|
||||
*/
|
||||
type Predicate<Fn, Fallback = never> = Fn extends (
|
||||
value: any
|
||||
) => value is infer Thing
|
||||
? Thing
|
||||
: Fallback
|
||||
|
||||
/**
|
||||
* Check if a node matches a test.
|
||||
*
|
||||
* Returns either the node if it matches or `never` otherwise.
|
||||
*/
|
||||
type MatchesOne<Value, Check> =
|
||||
// Is this a node?
|
||||
Value extends Node
|
||||
? // No test.
|
||||
Check extends null
|
||||
? Value
|
||||
: // No test.
|
||||
Check extends undefined
|
||||
? Value
|
||||
: // Function test.
|
||||
Check extends Function
|
||||
? Extract<Value, Predicate<Check, Value>>
|
||||
: // String (type) test.
|
||||
Value['type'] extends Check
|
||||
? Value
|
||||
: // Partial test.
|
||||
Value extends Check
|
||||
? Value
|
||||
: never
|
||||
: never
|
||||
|
||||
/**
|
||||
* Check if a node matches one or more tests.
|
||||
*
|
||||
* Returns either the node if it matches or `never` otherwise.
|
||||
*/
|
||||
export type Matches<Value, Check> =
|
||||
// Is this a list?
|
||||
Check extends Array<any>
|
||||
? MatchesOne<Value, Check[keyof Check]>
|
||||
: MatchesOne<Value, Check>
|
||||
/* eslint-enable @typescript-eslint/ban-types */
|
||||
92
node_modules/unist-util-visit-parents/lib/index.d.ts
generated
vendored
Normal file
92
node_modules/unist-util-visit-parents/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
* Continue traversing as normal.
|
||||
*/
|
||||
export const CONTINUE: true;
|
||||
/**
|
||||
* Stop traversing immediately.
|
||||
*/
|
||||
export const EXIT: false;
|
||||
/**
|
||||
* Do not traverse this node’s children.
|
||||
*/
|
||||
export const SKIP: "skip";
|
||||
/**
|
||||
* Visit nodes, with ancestral information.
|
||||
*
|
||||
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
||||
* (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
|
||||
*
|
||||
* You can choose for which nodes `visitor` is called by passing a `test`.
|
||||
* For complex tests, you should test yourself in `visitor`, as it will be
|
||||
* faster and will have improved type information.
|
||||
*
|
||||
* Walking the tree is an intensive task.
|
||||
* Make use of the return values of the visitor when possible.
|
||||
* Instead of walking a tree multiple times, walk it once, use `unist-util-is`
|
||||
* to check if a node matches, and then perform different operations.
|
||||
*
|
||||
* You can change the tree.
|
||||
* See `Visitor` for more info.
|
||||
*
|
||||
* @param tree
|
||||
* Tree to traverse.
|
||||
* @param test
|
||||
* `unist-util-is`-compatible test
|
||||
* @param visitor
|
||||
* Handle each node.
|
||||
* @param reverse
|
||||
* Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
|
||||
* @returns
|
||||
* Nothing.
|
||||
*/
|
||||
export const visitParents: (<Tree extends import("unist").Node<import("unist").Data>, Check extends import("unist-util-is/lib/index.js").Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) & (<Tree_1 extends import("unist").Node<import("unist").Data>>(tree: Tree_1, visitor: BuildVisitor<Tree_1, string>, reverse?: boolean | null | undefined) => void);
|
||||
export type Node = import('unist').Node;
|
||||
export type Parent = import('unist').Parent;
|
||||
export type Test = import('unist-util-is').Test;
|
||||
/**
|
||||
* Union of the action types.
|
||||
*/
|
||||
export type Action = boolean | 'skip';
|
||||
/**
|
||||
* Move to the sibling at `index` next (after node itself is completely
|
||||
* traversed).
|
||||
*
|
||||
* Useful if mutating the tree, such as removing the node the visitor is
|
||||
* currently on, or any of its previous siblings.
|
||||
* Results less than 0 or greater than or equal to `children.length` stop
|
||||
* traversing the parent.
|
||||
*/
|
||||
export type Index = number;
|
||||
/**
|
||||
* List with one or two values, the first an action, the second an index.
|
||||
*/
|
||||
export type ActionTuple = [(Action | null | undefined | void)?, (Index | null | undefined)?];
|
||||
/**
|
||||
* Any value that can be returned from a visitor.
|
||||
*/
|
||||
export type VisitorResult = Action | [(void | Action | null | undefined)?, (number | null | undefined)?] | Index | null | undefined | void;
|
||||
/**
|
||||
* Handle a node (matching `test`, if given).
|
||||
*
|
||||
* Visitors are free to transform `node`.
|
||||
* They can also transform the parent of node (the last of `ancestors`).
|
||||
*
|
||||
* Replacing `node` itself, if `SKIP` is not returned, still causes its
|
||||
* descendants to be walked (which is a bug).
|
||||
*
|
||||
* When adding or removing previous siblings of `node` (or next siblings, in
|
||||
* case of reverse), the `Visitor` should return a new `Index` to specify the
|
||||
* sibling to traverse after `node` is traversed.
|
||||
* Adding or removing next siblings of `node` (or previous siblings, in case
|
||||
* of reverse) is handled as expected without needing to return a new `Index`.
|
||||
*
|
||||
* Removing the children property of an ancestor still results in them being
|
||||
* traversed.
|
||||
*/
|
||||
export type Visitor<Visited extends import("unist").Node<import("unist").Data> = import("unist").Node<import("unist").Data>, Ancestor extends import("unist").Parent<import("unist").Node<import("unist").Data>, import("unist").Data> = import("unist").Parent<import("unist").Node<import("unist").Data>, import("unist").Data>> = (node: Visited, ancestors: Array<Ancestor>) => VisitorResult;
|
||||
/**
|
||||
* Build a typed `Visitor` function from a tree and a test.
|
||||
*
|
||||
* It will infer which values are passed as `node` and which as `parents`.
|
||||
*/
|
||||
export type BuildVisitor<Tree extends import("unist").Node<import("unist").Data> = import("unist").Node<import("unist").Data>, Check extends import("unist-util-is/lib/index.js").Test = string> = Visitor<import('./complex-types.js').Matches<import('./complex-types.js').InclusiveDescendant<Tree>, Check>, Extract<import('./complex-types.js').InclusiveDescendant<Tree>, Parent>>;
|
||||
241
node_modules/unist-util-visit-parents/lib/index.js
generated
vendored
Normal file
241
node_modules/unist-util-visit-parents/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
/**
|
||||
* @typedef {import('unist').Node} Node
|
||||
* @typedef {import('unist').Parent} Parent
|
||||
* @typedef {import('unist-util-is').Test} Test
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {boolean | 'skip'} Action
|
||||
* Union of the action types.
|
||||
*
|
||||
* @typedef {number} Index
|
||||
* Move to the sibling at `index` next (after node itself is completely
|
||||
* traversed).
|
||||
*
|
||||
* Useful if mutating the tree, such as removing the node the visitor is
|
||||
* currently on, or any of its previous siblings.
|
||||
* Results less than 0 or greater than or equal to `children.length` stop
|
||||
* traversing the parent.
|
||||
*
|
||||
* @typedef {[(Action | null | undefined | void)?, (Index | null | undefined)?]} ActionTuple
|
||||
* List with one or two values, the first an action, the second an index.
|
||||
*
|
||||
* @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult
|
||||
* Any value that can be returned from a visitor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {Node} [Visited=Node]
|
||||
* Visited node type.
|
||||
* @template {Parent} [Ancestor=Parent]
|
||||
* Ancestor type.
|
||||
* @callback Visitor
|
||||
* Handle a node (matching `test`, if given).
|
||||
*
|
||||
* Visitors are free to transform `node`.
|
||||
* They can also transform the parent of node (the last of `ancestors`).
|
||||
*
|
||||
* Replacing `node` itself, if `SKIP` is not returned, still causes its
|
||||
* descendants to be walked (which is a bug).
|
||||
*
|
||||
* When adding or removing previous siblings of `node` (or next siblings, in
|
||||
* case of reverse), the `Visitor` should return a new `Index` to specify the
|
||||
* sibling to traverse after `node` is traversed.
|
||||
* Adding or removing next siblings of `node` (or previous siblings, in case
|
||||
* of reverse) is handled as expected without needing to return a new `Index`.
|
||||
*
|
||||
* Removing the children property of an ancestor still results in them being
|
||||
* traversed.
|
||||
* @param {Visited} node
|
||||
* Found node.
|
||||
* @param {Array<Ancestor>} ancestors
|
||||
* Ancestors of `node`.
|
||||
* @returns {VisitorResult}
|
||||
* What to do next.
|
||||
*
|
||||
* An `Index` is treated as a tuple of `[CONTINUE, Index]`.
|
||||
* An `Action` is treated as a tuple of `[Action]`.
|
||||
*
|
||||
* Passing a tuple back only makes sense if the `Action` is `SKIP`.
|
||||
* When the `Action` is `EXIT`, that action can be returned.
|
||||
* When the `Action` is `CONTINUE`, `Index` can be returned.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template {Node} [Tree=Node]
|
||||
* Tree type.
|
||||
* @template {Test} [Check=string]
|
||||
* Test type.
|
||||
* @typedef {Visitor<import('./complex-types.js').Matches<import('./complex-types.js').InclusiveDescendant<Tree>, Check>, Extract<import('./complex-types.js').InclusiveDescendant<Tree>, Parent>>} BuildVisitor
|
||||
* Build a typed `Visitor` function from a tree and a test.
|
||||
*
|
||||
* It will infer which values are passed as `node` and which as `parents`.
|
||||
*/
|
||||
|
||||
import {convert} from 'unist-util-is'
|
||||
import {color} from './color.js'
|
||||
|
||||
/**
|
||||
* Continue traversing as normal.
|
||||
*/
|
||||
export const CONTINUE = true
|
||||
|
||||
/**
|
||||
* Stop traversing immediately.
|
||||
*/
|
||||
export const EXIT = false
|
||||
|
||||
/**
|
||||
* Do not traverse this node’s children.
|
||||
*/
|
||||
export const SKIP = 'skip'
|
||||
|
||||
/**
|
||||
* Visit nodes, with ancestral information.
|
||||
*
|
||||
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
||||
* (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
|
||||
*
|
||||
* You can choose for which nodes `visitor` is called by passing a `test`.
|
||||
* For complex tests, you should test yourself in `visitor`, as it will be
|
||||
* faster and will have improved type information.
|
||||
*
|
||||
* Walking the tree is an intensive task.
|
||||
* Make use of the return values of the visitor when possible.
|
||||
* Instead of walking a tree multiple times, walk it once, use `unist-util-is`
|
||||
* to check if a node matches, and then perform different operations.
|
||||
*
|
||||
* You can change the tree.
|
||||
* See `Visitor` for more info.
|
||||
*
|
||||
* @param tree
|
||||
* Tree to traverse.
|
||||
* @param test
|
||||
* `unist-util-is`-compatible test
|
||||
* @param visitor
|
||||
* Handle each node.
|
||||
* @param reverse
|
||||
* Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
|
||||
* @returns
|
||||
* Nothing.
|
||||
*/
|
||||
export const visitParents =
|
||||
/**
|
||||
* @type {(
|
||||
* (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &
|
||||
* (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)
|
||||
* )}
|
||||
*/
|
||||
(
|
||||
/**
|
||||
* @param {Node} tree
|
||||
* @param {Test} test
|
||||
* @param {Visitor<Node>} visitor
|
||||
* @param {boolean | null | undefined} [reverse]
|
||||
* @returns {void}
|
||||
*/
|
||||
function (tree, test, visitor, reverse) {
|
||||
if (typeof test === 'function' && typeof visitor !== 'function') {
|
||||
reverse = visitor
|
||||
// @ts-expect-error no visitor given, so `visitor` is test.
|
||||
visitor = test
|
||||
test = null
|
||||
}
|
||||
|
||||
const is = convert(test)
|
||||
const step = reverse ? -1 : 1
|
||||
|
||||
factory(tree, undefined, [])()
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @param {number | undefined} index
|
||||
* @param {Array<Parent>} parents
|
||||
*/
|
||||
function factory(node, index, parents) {
|
||||
/** @type {Record<string, unknown>} */
|
||||
// @ts-expect-error: hush
|
||||
const value = node && typeof node === 'object' ? node : {}
|
||||
|
||||
if (typeof value.type === 'string') {
|
||||
const name =
|
||||
// `hast`
|
||||
typeof value.tagName === 'string'
|
||||
? value.tagName
|
||||
: // `xast`
|
||||
typeof value.name === 'string'
|
||||
? value.name
|
||||
: undefined
|
||||
|
||||
Object.defineProperty(visit, 'name', {
|
||||
value:
|
||||
'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'
|
||||
})
|
||||
}
|
||||
|
||||
return visit
|
||||
|
||||
function visit() {
|
||||
/** @type {ActionTuple} */
|
||||
let result = []
|
||||
/** @type {ActionTuple} */
|
||||
let subresult
|
||||
/** @type {number} */
|
||||
let offset
|
||||
/** @type {Array<Parent>} */
|
||||
let grandparents
|
||||
|
||||
if (!test || is(node, index, parents[parents.length - 1] || null)) {
|
||||
result = toResult(visitor(node, parents))
|
||||
|
||||
if (result[0] === EXIT) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-expect-error looks like a parent.
|
||||
if (node.children && result[0] !== SKIP) {
|
||||
// @ts-expect-error looks like a parent.
|
||||
offset = (reverse ? node.children.length : -1) + step
|
||||
// @ts-expect-error looks like a parent.
|
||||
grandparents = parents.concat(node)
|
||||
|
||||
// @ts-expect-error looks like a parent.
|
||||
while (offset > -1 && offset < node.children.length) {
|
||||
// @ts-expect-error looks like a parent.
|
||||
subresult = factory(node.children[offset], offset, grandparents)()
|
||||
|
||||
if (subresult[0] === EXIT) {
|
||||
return subresult
|
||||
}
|
||||
|
||||
offset =
|
||||
typeof subresult[1] === 'number' ? subresult[1] : offset + step
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Turn a return value into a clean result.
|
||||
*
|
||||
* @param {VisitorResult} value
|
||||
* Valid return values from visitors.
|
||||
* @returns {ActionTuple}
|
||||
* Clean result.
|
||||
*/
|
||||
function toResult(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value
|
||||
}
|
||||
|
||||
if (typeof value === 'number') {
|
||||
return [CONTINUE, value]
|
||||
}
|
||||
|
||||
return [value]
|
||||
}
|
||||
22
node_modules/unist-util-visit-parents/license
generated
vendored
Normal file
22
node_modules/unist-util-visit-parents/license
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
104
node_modules/unist-util-visit-parents/package.json
generated
vendored
Normal file
104
node_modules/unist-util-visit-parents/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
{
|
||||
"name": "unist-util-visit-parents",
|
||||
"version": "5.1.3",
|
||||
"description": "unist utility to recursively walk over nodes, with ancestral information",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"unist-util",
|
||||
"util",
|
||||
"utility",
|
||||
"tree",
|
||||
"ast",
|
||||
"visit",
|
||||
"traverse",
|
||||
"walk",
|
||||
"check",
|
||||
"parent",
|
||||
"parents"
|
||||
],
|
||||
"repository": "syntax-tree/unist-util-visit-parents",
|
||||
"bugs": "https://github.com/syntax-tree/unist-util-visit-parents/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"browser": {
|
||||
"./lib/color.js": "./lib/color.browser.js"
|
||||
},
|
||||
"react-native": {
|
||||
"./lib/color.js": "./lib/color.browser.js"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"lib/",
|
||||
"complex-types.d.ts",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/unist": "^2.0.0",
|
||||
"unist-util-is": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/hast": "^2.0.0",
|
||||
"@types/mdast": "^3.0.0",
|
||||
"@types/node": "^18.0.0",
|
||||
"c8": "^7.0.0",
|
||||
"mdast-util-from-markdown": "^1.0.0",
|
||||
"mdast-util-gfm": "^2.0.0",
|
||||
"micromark-extension-gfm": "^2.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^11.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"strip-ansi": "^7.0.0",
|
||||
"tsd": "^0.25.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^4.7.0",
|
||||
"xo": "^0.53.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepack": "npm run build && npm run format",
|
||||
"build": "tsc --build --clean && tsc --build && tsd && type-coverage",
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"test-api": "node --conditions development test.js",
|
||||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
|
||||
"test": "npm run build && npm run format && npm run test-coverage"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"rules": {
|
||||
"@typescript-eslint/array-type": "off"
|
||||
}
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"remark-preset-wooorm"
|
||||
]
|
||||
},
|
||||
"typeCoverage": {
|
||||
"atLeast": 100,
|
||||
"detail": true,
|
||||
"strict": true,
|
||||
"ignoreCatch": true,
|
||||
"#": "needed `any`s",
|
||||
"ignoreFiles": [
|
||||
"lib/complex-types.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
385
node_modules/unist-util-visit-parents/readme.md
generated
vendored
Normal file
385
node_modules/unist-util-visit-parents/readme.md
generated
vendored
Normal file
|
|
@ -0,0 +1,385 @@
|
|||
# unist-util-visit-parents
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
[unist][] utility to walk the tree with a stack of parents.
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is this?](#what-is-this)
|
||||
* [When should I use this?](#when-should-i-use-this)
|
||||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`visitParents(tree[, test], visitor[, reverse])`](#visitparentstree-test-visitor-reverse)
|
||||
* [`CONTINUE`](#continue)
|
||||
* [`EXIT`](#exit)
|
||||
* [`SKIP`](#skip)
|
||||
* [`Action`](#action)
|
||||
* [`ActionTuple`](#actiontuple)
|
||||
* [`BuildVisitor`](#buildvisitor)
|
||||
* [`Index`](#index)
|
||||
* [`Test`](#test)
|
||||
* [`Visitor`](#visitor)
|
||||
* [`VisitorResult`](#visitorresult)
|
||||
* [Types](#types)
|
||||
* [Compatibility](#compatibility)
|
||||
* [Related](#related)
|
||||
* [Contribute](#contribute)
|
||||
* [License](#license)
|
||||
|
||||
## What is this?
|
||||
|
||||
This is a very important utility for working with unist as it lets you walk the
|
||||
tree.
|
||||
|
||||
## When should I use this?
|
||||
|
||||
You can use this utility when you want to walk the tree and want to know about
|
||||
every parent of each node.
|
||||
You can use [`unist-util-visit`][unist-util-visit] if you don’t care about the
|
||||
entire stack of parents.
|
||||
|
||||
## Install
|
||||
|
||||
This package is [ESM only][esm].
|
||||
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
|
||||
|
||||
```sh
|
||||
npm install unist-util-visit-parents
|
||||
```
|
||||
|
||||
In Deno with [`esm.sh`][esmsh]:
|
||||
|
||||
```js
|
||||
import {visitParents} from 'https://esm.sh/unist-util-visit-parents@5'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import {visitParents} from 'https://esm.sh/unist-util-visit-parents@5?bundle'
|
||||
</script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import {visitParents} from 'unist-util-visit-parents'
|
||||
import {fromMarkdown} from 'mdast-util-from-markdown'
|
||||
|
||||
const tree = fromMarkdown('Some *emphasis*, **strong**, and `code`.')
|
||||
|
||||
visitParents(tree, 'strong', (node, ancestors) => {
|
||||
console.log(node.type, ancestors.map(ancestor => ancestor.type))
|
||||
})
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```js
|
||||
strong ['root', 'paragraph']
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This package exports the identifiers [`CONTINUE`][api-continue],
|
||||
[`EXIT`][api-exit], [`SKIP`][api-skip], and [`visitParents`][api-visitparents].
|
||||
There is no default export.
|
||||
|
||||
### `visitParents(tree[, test], visitor[, reverse])`
|
||||
|
||||
Visit nodes, with ancestral information.
|
||||
|
||||
This algorithm performs *[depth-first][]* *[tree traversal][tree-traversal]*
|
||||
in *[preorder][]* (**NLR**) or if `reverse` is given, in *reverse preorder*
|
||||
(**NRL**).
|
||||
|
||||
You can choose for which nodes `visitor` is called by passing a `test`.
|
||||
For complex tests, you should test yourself in `visitor`, as it will be
|
||||
faster and will have improved type information.
|
||||
|
||||
Walking the tree is an intensive task.
|
||||
Make use of the return values of the visitor when possible.
|
||||
Instead of walking a tree multiple times, walk it once, use
|
||||
[`unist-util-is`][unist-util-is] to check if a node matches, and then perform
|
||||
different operations.
|
||||
|
||||
You can change the tree.
|
||||
See [`Visitor`][api-visitor] for more info.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `tree` ([`Node`][node])
|
||||
— tree to traverse
|
||||
* `test` ([`Test`][api-test], optional)
|
||||
— [`unist-util-is`][unist-util-is]-compatible test
|
||||
* `visitor` ([`Visitor`][api-visitor])
|
||||
— handle each node
|
||||
* `reverse` (`boolean`, default: `false`)
|
||||
— traverse in reverse preorder (NRL) instead of the default preorder (NLR)
|
||||
|
||||
###### Returns
|
||||
|
||||
Nothing (`void`).
|
||||
|
||||
### `CONTINUE`
|
||||
|
||||
Continue traversing as normal (`true`).
|
||||
|
||||
### `EXIT`
|
||||
|
||||
Stop traversing immediately (`false`).
|
||||
|
||||
### `SKIP`
|
||||
|
||||
Do not traverse this node’s children (`'skip'`).
|
||||
|
||||
### `Action`
|
||||
|
||||
Union of the action types (TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
type Action = typeof CONTINUE | typeof EXIT | typeof SKIP
|
||||
```
|
||||
|
||||
### `ActionTuple`
|
||||
|
||||
List with one or two values, the first an action, the second an index
|
||||
(TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
type ActionTuple = [
|
||||
(Action | null | undefined | void)?,
|
||||
(Index | null | undefined)?
|
||||
]
|
||||
```
|
||||
|
||||
### `BuildVisitor`
|
||||
|
||||
Build a typed `Visitor` function from a tree and a test (TypeScript type).
|
||||
|
||||
It will infer which values are passed as `node` and which as `parents`.
|
||||
|
||||
###### Type parameters
|
||||
|
||||
* `Tree` ([`Node`][node], default: `Node`)
|
||||
— tree type
|
||||
* `Check` ([`Test`][api-test], default: `string`)
|
||||
— test type
|
||||
|
||||
###### Returns
|
||||
|
||||
[`Visitor`][api-visitor].
|
||||
|
||||
### `Index`
|
||||
|
||||
Move to the sibling at `index` next (after node itself is completely
|
||||
traversed) (TypeScript type).
|
||||
|
||||
Useful if mutating the tree, such as removing the node the visitor is currently
|
||||
on, or any of its previous siblings.
|
||||
Results less than `0` or greater than or equal to `children.length` stop
|
||||
traversing the parent.
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
type Index = number
|
||||
```
|
||||
|
||||
### `Test`
|
||||
|
||||
[`unist-util-is`][unist-util-is] compatible test (TypeScript type).
|
||||
|
||||
### `Visitor`
|
||||
|
||||
Handle a node (matching `test`, if given) (TypeScript type).
|
||||
|
||||
Visitors are free to transform `node`.
|
||||
They can also transform the parent of node (the last of `ancestors`).
|
||||
|
||||
Replacing `node` itself, if `SKIP` is not returned, still causes its
|
||||
descendants to be walked (which is a bug).
|
||||
|
||||
When adding or removing previous siblings of `node` (or next siblings, in
|
||||
case of reverse), the `Visitor` should return a new `Index` to specify the
|
||||
sibling to traverse after `node` is traversed.
|
||||
Adding or removing next siblings of `node` (or previous siblings, in case
|
||||
of reverse) is handled as expected without needing to return a new `Index`.
|
||||
|
||||
Removing the children property of an ancestor still results in them being
|
||||
traversed.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `node` ([`Node`][node])
|
||||
— found node
|
||||
* `parents` ([`Array<Node>`][node])
|
||||
— ancestors of `node`
|
||||
|
||||
###### Returns
|
||||
|
||||
What to do next.
|
||||
|
||||
An `Index` is treated as a tuple of `[CONTINUE, Index]`.
|
||||
An `Action` is treated as a tuple of `[Action]`.
|
||||
|
||||
Passing a tuple back only makes sense if the `Action` is `SKIP`.
|
||||
When the `Action` is `EXIT`, that action can be returned.
|
||||
When the `Action` is `CONTINUE`, `Index` can be returned.
|
||||
|
||||
### `VisitorResult`
|
||||
|
||||
Any value that can be returned from a visitor (TypeScript type).
|
||||
|
||||
###### Type
|
||||
|
||||
```ts
|
||||
type VisitorResult =
|
||||
| Action
|
||||
| ActionTuple
|
||||
| Index
|
||||
| null
|
||||
| undefined
|
||||
| void
|
||||
```
|
||||
|
||||
## Types
|
||||
|
||||
This package is fully typed with [TypeScript][].
|
||||
It exports the additional types [`Action`][api-action],
|
||||
[`ActionTuple`][api-actiontuple], [`BuildVisitor`][api-buildvisitor],
|
||||
[`Index`][api-index], [`Test`][api-test], [`Visitor`][api-visitor], and
|
||||
[`VisitorResult`][api-visitorresult].
|
||||
|
||||
## Compatibility
|
||||
|
||||
Projects maintained by the unified collective are compatible with all maintained
|
||||
versions of Node.js.
|
||||
As of now, that is Node.js 14.14+ and 16.0+.
|
||||
Our projects sometimes work with older versions, but this is not guaranteed.
|
||||
|
||||
## Related
|
||||
|
||||
* [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)
|
||||
— walk the tree with one parent
|
||||
* [`unist-util-filter`](https://github.com/syntax-tree/unist-util-filter)
|
||||
— create a new tree with all nodes that pass a test
|
||||
* [`unist-util-map`](https://github.com/syntax-tree/unist-util-map)
|
||||
— create a new tree with all nodes mapped by a given function
|
||||
* [`unist-util-flatmap`](https://gitlab.com/staltz/unist-util-flatmap)
|
||||
— create a new tree by mapping (to an array) with the given function
|
||||
* [`unist-util-remove`](https://github.com/syntax-tree/unist-util-remove)
|
||||
— remove nodes from a tree that pass a test
|
||||
* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
|
||||
— select nodes with CSS-like selectors
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
|
||||
ways to get started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organization, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definition -->
|
||||
|
||||
[build-badge]: https://github.com/syntax-tree/unist-util-visit-parents/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/unist-util-visit-parents/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-visit-parents.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/unist-util-visit-parents
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-visit-parents.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/unist-util-visit-parents
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-visit-parents.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=unist-util-visit-parents
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[chat]: https://github.com/syntax-tree/unist/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
||||
|
||||
[esmsh]: https://esm.sh
|
||||
|
||||
[typescript]: https://www.typescriptlang.org
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[health]: https://github.com/syntax-tree/.github
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[unist]: https://github.com/syntax-tree/unist
|
||||
|
||||
[node]: https://github.com/syntax-tree/unist#node
|
||||
|
||||
[depth-first]: https://github.com/syntax-tree/unist#depth-first-traversal
|
||||
|
||||
[tree-traversal]: https://github.com/syntax-tree/unist#tree-traversal
|
||||
|
||||
[preorder]: https://github.com/syntax-tree/unist#preorder
|
||||
|
||||
[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit
|
||||
|
||||
[unist-util-is]: https://github.com/syntax-tree/unist-util-is
|
||||
|
||||
[api-visitparents]: #visitparentstree-test-visitor-reverse
|
||||
|
||||
[api-continue]: #continue
|
||||
|
||||
[api-exit]: #exit
|
||||
|
||||
[api-skip]: #skip
|
||||
|
||||
[api-action]: #action
|
||||
|
||||
[api-actiontuple]: #actiontuple
|
||||
|
||||
[api-buildvisitor]: #buildvisitor
|
||||
|
||||
[api-index]: #index
|
||||
|
||||
[api-test]: #test
|
||||
|
||||
[api-visitor]: #visitor
|
||||
|
||||
[api-visitorresult]: #visitorresult
|
||||
Loading…
Add table
Add a link
Reference in a new issue