You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
5.8 KiB
JavaScript
196 lines
5.8 KiB
JavaScript
import "./chunk-ZKNUHGJ4.mjs";
|
|
|
|
// node_modules/.pnpm/estree-walker@3.0.1/node_modules/estree-walker/src/walker.js
|
|
var WalkerBase = class {
|
|
constructor() {
|
|
this.should_skip = false;
|
|
this.should_remove = false;
|
|
this.replacement = null;
|
|
this.context = {
|
|
skip: () => this.should_skip = true,
|
|
remove: () => this.should_remove = true,
|
|
replace: (node) => this.replacement = node
|
|
};
|
|
}
|
|
replace(parent, prop, index, node) {
|
|
if (parent) {
|
|
if (index !== null) {
|
|
parent[prop][index] = node;
|
|
} else {
|
|
parent[prop] = node;
|
|
}
|
|
}
|
|
}
|
|
remove(parent, prop, index) {
|
|
if (parent) {
|
|
if (index !== null) {
|
|
parent[prop].splice(index, 1);
|
|
} else {
|
|
delete parent[prop];
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
// node_modules/.pnpm/estree-walker@3.0.1/node_modules/estree-walker/src/sync.js
|
|
var SyncWalker = class extends WalkerBase {
|
|
constructor(enter, leave) {
|
|
super();
|
|
this.enter = enter;
|
|
this.leave = leave;
|
|
}
|
|
visit(node, parent, prop, index) {
|
|
if (node) {
|
|
if (this.enter) {
|
|
const _should_skip = this.should_skip;
|
|
const _should_remove = this.should_remove;
|
|
const _replacement = this.replacement;
|
|
this.should_skip = false;
|
|
this.should_remove = false;
|
|
this.replacement = null;
|
|
this.enter.call(this.context, node, parent, prop, index);
|
|
if (this.replacement) {
|
|
node = this.replacement;
|
|
this.replace(parent, prop, index, node);
|
|
}
|
|
if (this.should_remove) {
|
|
this.remove(parent, prop, index);
|
|
}
|
|
const skipped = this.should_skip;
|
|
const removed = this.should_remove;
|
|
this.should_skip = _should_skip;
|
|
this.should_remove = _should_remove;
|
|
this.replacement = _replacement;
|
|
if (skipped)
|
|
return node;
|
|
if (removed)
|
|
return null;
|
|
}
|
|
for (const key in node) {
|
|
const value = node[key];
|
|
if (typeof value !== "object") {
|
|
continue;
|
|
} else if (Array.isArray(value)) {
|
|
for (let i = 0; i < value.length; i += 1) {
|
|
if (value[i] !== null && typeof value[i].type === "string") {
|
|
if (!this.visit(value[i], node, key, i)) {
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
} else if (value !== null && typeof value.type === "string") {
|
|
this.visit(value, node, key, null);
|
|
}
|
|
}
|
|
if (this.leave) {
|
|
const _replacement = this.replacement;
|
|
const _should_remove = this.should_remove;
|
|
this.replacement = null;
|
|
this.should_remove = false;
|
|
this.leave.call(this.context, node, parent, prop, index);
|
|
if (this.replacement) {
|
|
node = this.replacement;
|
|
this.replace(parent, prop, index, node);
|
|
}
|
|
if (this.should_remove) {
|
|
this.remove(parent, prop, index);
|
|
}
|
|
const removed = this.should_remove;
|
|
this.replacement = _replacement;
|
|
this.should_remove = _should_remove;
|
|
if (removed)
|
|
return null;
|
|
}
|
|
}
|
|
return node;
|
|
}
|
|
};
|
|
|
|
// node_modules/.pnpm/estree-walker@3.0.1/node_modules/estree-walker/src/async.js
|
|
var AsyncWalker = class extends WalkerBase {
|
|
constructor(enter, leave) {
|
|
super();
|
|
this.enter = enter;
|
|
this.leave = leave;
|
|
}
|
|
async visit(node, parent, prop, index) {
|
|
if (node) {
|
|
if (this.enter) {
|
|
const _should_skip = this.should_skip;
|
|
const _should_remove = this.should_remove;
|
|
const _replacement = this.replacement;
|
|
this.should_skip = false;
|
|
this.should_remove = false;
|
|
this.replacement = null;
|
|
await this.enter.call(this.context, node, parent, prop, index);
|
|
if (this.replacement) {
|
|
node = this.replacement;
|
|
this.replace(parent, prop, index, node);
|
|
}
|
|
if (this.should_remove) {
|
|
this.remove(parent, prop, index);
|
|
}
|
|
const skipped = this.should_skip;
|
|
const removed = this.should_remove;
|
|
this.should_skip = _should_skip;
|
|
this.should_remove = _should_remove;
|
|
this.replacement = _replacement;
|
|
if (skipped)
|
|
return node;
|
|
if (removed)
|
|
return null;
|
|
}
|
|
for (const key in node) {
|
|
const value = node[key];
|
|
if (typeof value !== "object") {
|
|
continue;
|
|
} else if (Array.isArray(value)) {
|
|
for (let i = 0; i < value.length; i += 1) {
|
|
if (value[i] !== null && typeof value[i].type === "string") {
|
|
if (!await this.visit(value[i], node, key, i)) {
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
} else if (value !== null && typeof value.type === "string") {
|
|
await this.visit(value, node, key, null);
|
|
}
|
|
}
|
|
if (this.leave) {
|
|
const _replacement = this.replacement;
|
|
const _should_remove = this.should_remove;
|
|
this.replacement = null;
|
|
this.should_remove = false;
|
|
await this.leave.call(this.context, node, parent, prop, index);
|
|
if (this.replacement) {
|
|
node = this.replacement;
|
|
this.replace(parent, prop, index, node);
|
|
}
|
|
if (this.should_remove) {
|
|
this.remove(parent, prop, index);
|
|
}
|
|
const removed = this.should_remove;
|
|
this.replacement = _replacement;
|
|
this.should_remove = _should_remove;
|
|
if (removed)
|
|
return null;
|
|
}
|
|
}
|
|
return node;
|
|
}
|
|
};
|
|
|
|
// node_modules/.pnpm/estree-walker@3.0.1/node_modules/estree-walker/src/index.js
|
|
function walk(ast, { enter, leave }) {
|
|
const instance = new SyncWalker(enter, leave);
|
|
return instance.visit(ast, null);
|
|
}
|
|
async function asyncWalk(ast, { enter, leave }) {
|
|
const instance = new AsyncWalker(enter, leave);
|
|
return await instance.visit(ast, null);
|
|
}
|
|
export {
|
|
asyncWalk,
|
|
walk
|
|
};
|