🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
5
node_modules/estree-util-visit/lib/color.browser.d.ts
generated
vendored
Normal file
5
node_modules/estree-util-visit/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/estree-util-visit/lib/color.browser.js
generated
vendored
Normal file
7
node_modules/estree-util-visit/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/estree-util-visit/lib/color.d.ts
generated
vendored
Normal file
5
node_modules/estree-util-visit/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/estree-util-visit/lib/color.js
generated
vendored
Normal file
7
node_modules/estree-util-visit/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'
|
||||
}
|
||||
90
node_modules/estree-util-visit/lib/index.d.ts
generated
vendored
Normal file
90
node_modules/estree-util-visit/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* Visit nodes, with ancestral information.
|
||||
*
|
||||
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
||||
* (**NLR**) and/or *postorder* (**LRN**).
|
||||
*
|
||||
* Walking the tree is an intensive task.
|
||||
* Make use of the return values of the visitor(s) 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.
|
||||
*
|
||||
* @param {Node} tree
|
||||
* Tree to traverse
|
||||
* @param {Visitor | Visitors | null | undefined} [visitor]
|
||||
* Handle each node.
|
||||
* @returns {void}
|
||||
* Nothing.
|
||||
*/
|
||||
export function visit(
|
||||
tree: Node,
|
||||
visitor?: Visitor | Visitors | null | undefined
|
||||
): void
|
||||
/**
|
||||
* Continue traversing as normal.
|
||||
*/
|
||||
export const CONTINUE: unique symbol
|
||||
/**
|
||||
* Stop traversing immediately.
|
||||
*/
|
||||
export const EXIT: unique symbol
|
||||
/**
|
||||
* Do not traverse this node’s children.
|
||||
*/
|
||||
export const SKIP: unique symbol
|
||||
export type Node = import('estree-jsx').Node
|
||||
/**
|
||||
* Union of the action types.
|
||||
*/
|
||||
export type Action = typeof CONTINUE | typeof SKIP | typeof EXIT
|
||||
/**
|
||||
* Move to the sibling at `index` next (after node itself is completely
|
||||
* traversed), when moving in an array.
|
||||
*
|
||||
* 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)?
|
||||
]
|
||||
/**
|
||||
* Handle a node.
|
||||
*
|
||||
* 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`, the `Visitor` should
|
||||
* return a new `Index` to specify the sibling to traverse after `node` is
|
||||
* traversed.
|
||||
* Adding or removing next siblings of `node` is handled as expected without
|
||||
* needing to return a new `Index`.
|
||||
*/
|
||||
export type Visitor = (
|
||||
node: Node,
|
||||
key: string | null,
|
||||
index: number | null,
|
||||
ancestors: Array<Node>
|
||||
) => Action | Index | ActionTuple | null | undefined | void
|
||||
/**
|
||||
* Handle nodes when entering (preorder) and leaving (postorder).
|
||||
*/
|
||||
export type Visitors = {
|
||||
/**
|
||||
* Handle nodes when entering (preorder).
|
||||
*/
|
||||
enter?: Visitor | null | undefined
|
||||
/**
|
||||
* Handle nodes when leaving (postorder).
|
||||
*/
|
||||
leave?: Visitor | null | undefined
|
||||
}
|
||||
229
node_modules/estree-util-visit/lib/index.js
generated
vendored
Normal file
229
node_modules/estree-util-visit/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
/**
|
||||
* @typedef {import('estree-jsx').Node} Node
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {CONTINUE | SKIP | EXIT} Action
|
||||
* Union of the action types.
|
||||
*
|
||||
* @typedef {number} Index
|
||||
* Move to the sibling at `index` next (after node itself is completely
|
||||
* traversed), when moving in an array.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback Visitor
|
||||
* Handle a node.
|
||||
*
|
||||
* 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`, the `Visitor` should
|
||||
* return a new `Index` to specify the sibling to traverse after `node` is
|
||||
* traversed.
|
||||
* Adding or removing next siblings of `node` is handled as expected without
|
||||
* needing to return a new `Index`.
|
||||
* @param {Node} node
|
||||
* Found node.
|
||||
* @param {string | null} key
|
||||
* Field at which `node` lives in its parent (or where a list of nodes lives).
|
||||
* @param {number | null} index
|
||||
* Index where `node` lives if `parent[key]` is an array.
|
||||
* @param {Array<Node>} ancestors
|
||||
* Ancestors of `node`.
|
||||
* @returns {Action | Index | ActionTuple | null | undefined | void}
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef Visitors
|
||||
* Handle nodes when entering (preorder) and leaving (postorder).
|
||||
* @property {Visitor | null | undefined} [enter]
|
||||
* Handle nodes when entering (preorder).
|
||||
* @property {Visitor | null | undefined} [leave]
|
||||
* Handle nodes when leaving (postorder).
|
||||
*/
|
||||
|
||||
import {color} from './color.js'
|
||||
|
||||
const own = {}.hasOwnProperty
|
||||
|
||||
/**
|
||||
* Continue traversing as normal.
|
||||
*/
|
||||
export const CONTINUE = Symbol('continue')
|
||||
|
||||
/**
|
||||
* Stop traversing immediately.
|
||||
*/
|
||||
export const EXIT = Symbol('exit')
|
||||
|
||||
/**
|
||||
* Do not traverse this node’s children.
|
||||
*/
|
||||
export const SKIP = Symbol('skip')
|
||||
|
||||
/**
|
||||
* Visit nodes, with ancestral information.
|
||||
*
|
||||
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
||||
* (**NLR**) and/or *postorder* (**LRN**).
|
||||
*
|
||||
* Walking the tree is an intensive task.
|
||||
* Make use of the return values of the visitor(s) 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.
|
||||
*
|
||||
* @param {Node} tree
|
||||
* Tree to traverse
|
||||
* @param {Visitor | Visitors | null | undefined} [visitor]
|
||||
* Handle each node.
|
||||
* @returns {void}
|
||||
* Nothing.
|
||||
*/
|
||||
export function visit(tree, visitor) {
|
||||
/** @type {Visitor | undefined} */
|
||||
let enter
|
||||
/** @type {Visitor | undefined} */
|
||||
let leave
|
||||
|
||||
if (typeof visitor === 'function') {
|
||||
enter = visitor
|
||||
} else if (visitor && typeof visitor === 'object') {
|
||||
if (visitor.enter) enter = visitor.enter
|
||||
if (visitor.leave) leave = visitor.leave
|
||||
}
|
||||
|
||||
build(tree, null, null, [])()
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @param {string | null} key
|
||||
* @param {number | null} index
|
||||
* @param {Array<Node>} parents
|
||||
*/
|
||||
function build(node, key, index, parents) {
|
||||
if (nodelike(node)) {
|
||||
visit.displayName = 'node (' + color(node.type) + ')'
|
||||
}
|
||||
|
||||
return visit
|
||||
|
||||
/**
|
||||
* @returns {ActionTuple}
|
||||
*/
|
||||
function visit() {
|
||||
/** @type {ActionTuple} */
|
||||
const result = enter ? toResult(enter(node, key, index, parents)) : []
|
||||
|
||||
if (result[0] === EXIT) {
|
||||
return result
|
||||
}
|
||||
|
||||
if (result[0] !== SKIP) {
|
||||
/** @type {keyof node} */
|
||||
let cKey
|
||||
|
||||
for (cKey in node) {
|
||||
if (
|
||||
own.call(node, cKey) &&
|
||||
node[cKey] &&
|
||||
typeof node[cKey] === 'object' &&
|
||||
// @ts-expect-error: custom esast extension.
|
||||
cKey !== 'data' &&
|
||||
// @ts-expect-error: custom esast extension.
|
||||
cKey !== 'position'
|
||||
) {
|
||||
const grandparents = parents.concat(node)
|
||||
/** @type {unknown} */
|
||||
const value = node[cKey]
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
const nodes = /** @type {Array<unknown>} */ (value)
|
||||
let cIndex = 0
|
||||
|
||||
while (cIndex > -1 && cIndex < nodes.length) {
|
||||
const subvalue = nodes[cIndex]
|
||||
|
||||
if (nodelike(subvalue)) {
|
||||
const subresult = build(
|
||||
subvalue,
|
||||
cKey,
|
||||
cIndex,
|
||||
grandparents
|
||||
)()
|
||||
if (subresult[0] === EXIT) return subresult
|
||||
cIndex =
|
||||
typeof subresult[1] === 'number' ? subresult[1] : cIndex + 1
|
||||
} else {
|
||||
cIndex++
|
||||
}
|
||||
}
|
||||
} else if (nodelike(value)) {
|
||||
const subresult = build(value, cKey, null, grandparents)()
|
||||
if (subresult[0] === EXIT) return subresult
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return leave ? toResult(leave(node, key, index, parents)) : result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a return value into a clean result.
|
||||
*
|
||||
* @param {Action | Index | ActionTuple | null | undefined | void} 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]
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if something looks like a node.
|
||||
*
|
||||
* @param {unknown} value
|
||||
* Anything.
|
||||
* @returns {value is Node}
|
||||
* Whether `value` looks like a node.
|
||||
*/
|
||||
function nodelike(value) {
|
||||
return Boolean(
|
||||
value &&
|
||||
typeof value === 'object' &&
|
||||
'type' in value &&
|
||||
typeof value.type === 'string' &&
|
||||
value.type.length > 0
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue