9.20/4 我也不知道改啥了
This commit is contained in:
61
admin/node_modules/estree-walker/src/walker.js
generated
vendored
Normal file
61
admin/node_modules/estree-walker/src/walker.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
// @ts-check
|
||||
/** @typedef { import('estree').BaseNode} BaseNode */
|
||||
|
||||
/** @typedef {{
|
||||
skip: () => void;
|
||||
remove: () => void;
|
||||
replace: (node: BaseNode) => void;
|
||||
}} WalkerContext */
|
||||
|
||||
export class WalkerBase {
|
||||
constructor() {
|
||||
/** @type {boolean} */
|
||||
this.should_skip = false;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.should_remove = false;
|
||||
|
||||
/** @type {BaseNode | null} */
|
||||
this.replacement = null;
|
||||
|
||||
/** @type {WalkerContext} */
|
||||
this.context = {
|
||||
skip: () => (this.should_skip = true),
|
||||
remove: () => (this.should_remove = true),
|
||||
replace: (node) => (this.replacement = node)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {any} parent
|
||||
* @param {string} prop
|
||||
* @param {number} index
|
||||
* @param {BaseNode} node
|
||||
*/
|
||||
replace(parent, prop, index, node) {
|
||||
if (parent) {
|
||||
if (index !== null) {
|
||||
parent[prop][index] = node;
|
||||
} else {
|
||||
parent[prop] = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {any} parent
|
||||
* @param {string} prop
|
||||
* @param {number} index
|
||||
*/
|
||||
remove(parent, prop, index) {
|
||||
if (parent) {
|
||||
if (index !== null) {
|
||||
parent[prop].splice(index, 1);
|
||||
} else {
|
||||
delete parent[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user