mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-21 14:13:36 +08:00
docs:更新文档
This commit is contained in:
88
node_modules/estree-walker/CHANGELOG.md
generated
vendored
Normal file
88
node_modules/estree-walker/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
# changelog
|
||||
|
||||
## 2.0.1
|
||||
|
||||
* Robustify `this.remove()`, pass current index to walker functions ([#18](https://github.com/Rich-Harris/estree-walker/pull/18))
|
||||
|
||||
## 2.0.0
|
||||
|
||||
* Add an `asyncWalk` export ([#20](https://github.com/Rich-Harris/estree-walker/pull/20))
|
||||
* Internal rewrite
|
||||
|
||||
## 1.0.1
|
||||
|
||||
* Relax node type to `BaseNode` ([#17](https://github.com/Rich-Harris/estree-walker/pull/17))
|
||||
|
||||
## 1.0.0
|
||||
|
||||
* Don't cache child keys
|
||||
|
||||
## 0.9.0
|
||||
|
||||
* Add `this.remove()` method
|
||||
|
||||
## 0.8.1
|
||||
|
||||
* Fix pkg.files
|
||||
|
||||
## 0.8.0
|
||||
|
||||
* Adopt `estree` types
|
||||
|
||||
## 0.7.0
|
||||
|
||||
* Add a `this.replace(node)` method
|
||||
|
||||
## 0.6.1
|
||||
|
||||
* Only traverse nodes that exist and have a type ([#9](https://github.com/Rich-Harris/estree-walker/pull/9))
|
||||
* Only cache keys for nodes with a type ([#8](https://github.com/Rich-Harris/estree-walker/pull/8))
|
||||
|
||||
## 0.6.0
|
||||
|
||||
* Fix walker context type
|
||||
* Update deps, remove unncessary Bublé transformation
|
||||
|
||||
## 0.5.2
|
||||
|
||||
* Add types to package
|
||||
|
||||
## 0.5.1
|
||||
|
||||
* Prevent context corruption when `walk()` is called during a walk
|
||||
|
||||
## 0.5.0
|
||||
|
||||
* Export `childKeys`, for manually fixing in case of malformed ASTs
|
||||
|
||||
## 0.4.0
|
||||
|
||||
* Add TypeScript typings ([#3](https://github.com/Rich-Harris/estree-walker/pull/3))
|
||||
|
||||
## 0.3.1
|
||||
|
||||
* Include `pkg.repository` ([#2](https://github.com/Rich-Harris/estree-walker/pull/2))
|
||||
|
||||
## 0.3.0
|
||||
|
||||
* More predictable ordering
|
||||
|
||||
## 0.2.1
|
||||
|
||||
* Keep `context` shape
|
||||
|
||||
## 0.2.0
|
||||
|
||||
* Add ES6 build
|
||||
|
||||
## 0.1.3
|
||||
|
||||
* npm snafu
|
||||
|
||||
## 0.1.2
|
||||
|
||||
* Pass current prop and index to `enter`/`leave` callbacks
|
||||
|
||||
## 0.1.1
|
||||
|
||||
* First release
|
||||
48
node_modules/estree-walker/README.md
generated
vendored
Normal file
48
node_modules/estree-walker/README.md
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# estree-walker
|
||||
|
||||
Simple utility for walking an [ESTree](https://github.com/estree/estree)-compliant AST, such as one generated by [acorn](https://github.com/marijnh/acorn).
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm i estree-walker
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var walk = require( 'estree-walker' ).walk;
|
||||
var acorn = require( 'acorn' );
|
||||
|
||||
ast = acorn.parse( sourceCode, options ); // https://github.com/acornjs/acorn
|
||||
|
||||
walk( ast, {
|
||||
enter: function ( node, parent, prop, index ) {
|
||||
// some code happens
|
||||
},
|
||||
leave: function ( node, parent, prop, index ) {
|
||||
// some code happens
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Inside the `enter` function, calling `this.skip()` will prevent the node's children being walked, or the `leave` function (which is optional) being called.
|
||||
|
||||
Call `this.replace(new_node)` in either `enter` or `leave` to replace the current node with a new one.
|
||||
|
||||
Call `this.remove()` in either `enter` or `leave` to remove the current node.
|
||||
|
||||
## Why not use estraverse?
|
||||
|
||||
The ESTree spec is evolving to accommodate ES6/7. I've had a couple of experiences where [estraverse](https://github.com/estools/estraverse) was unable to handle an AST generated by recent versions of acorn, because it hard-codes visitor keys.
|
||||
|
||||
estree-walker, by contrast, simply enumerates a node's properties to find child nodes (and child lists of nodes), and is therefore resistant to spec changes. It's also much smaller. (The performance, if you're wondering, is basically identical.)
|
||||
|
||||
None of which should be taken as criticism of estraverse, which has more features and has been battle-tested in many more situations, and for which I'm very grateful.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
253
node_modules/estree-walker/dist/estree-walker.umd.js
generated
vendored
Normal file
253
node_modules/estree-walker/dist/estree-walker.umd.js
generated
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(factory((global.estreeWalker = {})));
|
||||
}(this, (function (exports) { 'use strict';
|
||||
|
||||
class WalkerBase {constructor() { WalkerBase.prototype.__init.call(this);WalkerBase.prototype.__init2.call(this);WalkerBase.prototype.__init3.call(this);WalkerBase.prototype.__init4.call(this); }
|
||||
__init() {this.should_skip = false;}
|
||||
__init2() {this.should_remove = false;}
|
||||
__init3() {this.replacement = null;}
|
||||
|
||||
__init4() {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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SyncWalkerClass extends WalkerBase {
|
||||
|
||||
|
||||
|
||||
constructor(walker) {
|
||||
super();
|
||||
this.enter = walker.enter;
|
||||
this.leave = walker.leave;
|
||||
}
|
||||
|
||||
visit(
|
||||
node,
|
||||
parent,
|
||||
enter,
|
||||
leave,
|
||||
prop,
|
||||
index
|
||||
) {
|
||||
if (node) {
|
||||
if (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;
|
||||
|
||||
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, enter, leave, key, i)) {
|
||||
// removed
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (value !== null && typeof value.type === "string") {
|
||||
this.visit(value, node, enter, leave, key, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncWalkerClass extends WalkerBase {
|
||||
|
||||
|
||||
|
||||
constructor(walker) {
|
||||
super();
|
||||
this.enter = walker.enter;
|
||||
this.leave = walker.leave;
|
||||
}
|
||||
|
||||
async visit(
|
||||
node,
|
||||
parent,
|
||||
enter,
|
||||
leave,
|
||||
prop,
|
||||
index
|
||||
) {
|
||||
if (node) {
|
||||
if (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 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, enter, leave, key, i))) {
|
||||
// removed
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (value !== null && typeof value.type === "string") {
|
||||
await this.visit(value, node, enter, leave, key, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
|
||||
await 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;
|
||||
}
|
||||
}
|
||||
|
||||
function walk(ast, walker) {
|
||||
const instance = new SyncWalkerClass(walker);
|
||||
return instance.visit(ast, null, walker.enter, walker.leave);
|
||||
}
|
||||
|
||||
async function asyncWalk(
|
||||
ast,
|
||||
walker
|
||||
) {
|
||||
const instance = new AsyncWalkerClass(walker);
|
||||
return await instance.visit(ast, null, walker.enter, walker.leave);
|
||||
}
|
||||
|
||||
exports.walk = walk;
|
||||
exports.asyncWalk = asyncWalk;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
72
node_modules/estree-walker/package.json
generated
vendored
Normal file
72
node_modules/estree-walker/package.json
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"estree-walker@2.0.1",
|
||||
"J:\\Github\\CURD-TS"
|
||||
]
|
||||
],
|
||||
"_development": true,
|
||||
"_from": "estree-walker@2.0.1",
|
||||
"_id": "estree-walker@2.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-+OAw+yHO+hg7RLetUWt0dDTno+A=",
|
||||
"_location": "/estree-walker",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "estree-walker@2.0.1",
|
||||
"name": "estree-walker",
|
||||
"escapedName": "estree-walker",
|
||||
"rawSpec": "2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@rollup/plugin-commonjs",
|
||||
"/@rollup/pluginutils",
|
||||
"/@vue/compiler-core",
|
||||
"/@vue/compiler-sfc",
|
||||
"/rollup-plugin-dynamic-import-variables"
|
||||
],
|
||||
"_resolved": "http://192.168.250.101:4873/estree-walker/-/estree-walker-2.0.1.tgz",
|
||||
"_spec": "2.0.1",
|
||||
"_where": "J:\\Github\\CURD-TS",
|
||||
"author": {
|
||||
"name": "Rich Harris"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Rich-Harris/estree-walker/issues"
|
||||
},
|
||||
"description": "Traverse an ESTree-compliant AST",
|
||||
"devDependencies": {
|
||||
"@types/estree": "0.0.42",
|
||||
"mocha": "^5.2.0",
|
||||
"rollup": "^0.67.3",
|
||||
"rollup-plugin-sucrase": "^2.1.0",
|
||||
"typescript": "^3.7.5"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"dist",
|
||||
"types",
|
||||
"README.md"
|
||||
],
|
||||
"homepage": "https://github.com/Rich-Harris/estree-walker#readme",
|
||||
"license": "MIT",
|
||||
"main": "dist/estree-walker.umd.js",
|
||||
"module": "src/estree-walker.js",
|
||||
"name": "estree-walker",
|
||||
"private": false,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Rich-Harris/estree-walker.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc && rollup -c",
|
||||
"prepublishOnly": "npm run build && npm test",
|
||||
"test": "mocha --opts mocha.opts"
|
||||
},
|
||||
"types": "types/index.d.ts",
|
||||
"version": "2.0.1"
|
||||
}
|
||||
113
node_modules/estree-walker/src/async.ts
generated
vendored
Normal file
113
node_modules/estree-walker/src/async.ts
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
import { WalkerBase, WalkerContext } from "./walker";
|
||||
import { BaseNode } from "estree";
|
||||
|
||||
export type AsyncWalker = {
|
||||
enter?: AsyncWalkerHandler;
|
||||
leave?: AsyncWalkerHandler;
|
||||
};
|
||||
|
||||
export type AsyncWalkerHandler = (
|
||||
this: WalkerContext,
|
||||
node: BaseNode,
|
||||
parent: BaseNode,
|
||||
key: string,
|
||||
index: number
|
||||
) => Promise<void>;
|
||||
|
||||
export class AsyncWalkerClass extends WalkerBase {
|
||||
protected enter: AsyncWalker["enter"];
|
||||
protected leave: AsyncWalker["leave"];
|
||||
|
||||
constructor(walker: AsyncWalker) {
|
||||
super();
|
||||
this.enter = walker.enter;
|
||||
this.leave = walker.leave;
|
||||
}
|
||||
|
||||
public async visit(
|
||||
node: BaseNode,
|
||||
parent: BaseNode,
|
||||
enter: AsyncWalkerHandler,
|
||||
leave: AsyncWalkerHandler,
|
||||
prop?: string,
|
||||
index?: number
|
||||
): Promise<BaseNode> {
|
||||
if (node) {
|
||||
if (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 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 as any)[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, enter, leave, key, i))) {
|
||||
// removed
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (value !== null && typeof value.type === "string") {
|
||||
await this.visit(value, node, enter, leave, key, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
|
||||
await 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;
|
||||
}
|
||||
}
|
||||
242
node_modules/estree-walker/src/estree-walker.js
generated
vendored
Normal file
242
node_modules/estree-walker/src/estree-walker.js
generated
vendored
Normal file
@@ -0,0 +1,242 @@
|
||||
class WalkerBase {constructor() { WalkerBase.prototype.__init.call(this);WalkerBase.prototype.__init2.call(this);WalkerBase.prototype.__init3.call(this);WalkerBase.prototype.__init4.call(this); }
|
||||
__init() {this.should_skip = false;}
|
||||
__init2() {this.should_remove = false;}
|
||||
__init3() {this.replacement = null;}
|
||||
|
||||
__init4() {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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SyncWalkerClass extends WalkerBase {
|
||||
|
||||
|
||||
|
||||
constructor(walker) {
|
||||
super();
|
||||
this.enter = walker.enter;
|
||||
this.leave = walker.leave;
|
||||
}
|
||||
|
||||
visit(
|
||||
node,
|
||||
parent,
|
||||
enter,
|
||||
leave,
|
||||
prop,
|
||||
index
|
||||
) {
|
||||
if (node) {
|
||||
if (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;
|
||||
|
||||
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, enter, leave, key, i)) {
|
||||
// removed
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (value !== null && typeof value.type === "string") {
|
||||
this.visit(value, node, enter, leave, key, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncWalkerClass extends WalkerBase {
|
||||
|
||||
|
||||
|
||||
constructor(walker) {
|
||||
super();
|
||||
this.enter = walker.enter;
|
||||
this.leave = walker.leave;
|
||||
}
|
||||
|
||||
async visit(
|
||||
node,
|
||||
parent,
|
||||
enter,
|
||||
leave,
|
||||
prop,
|
||||
index
|
||||
) {
|
||||
if (node) {
|
||||
if (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 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, enter, leave, key, i))) {
|
||||
// removed
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (value !== null && typeof value.type === "string") {
|
||||
await this.visit(value, node, enter, leave, key, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
|
||||
await 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;
|
||||
}
|
||||
}
|
||||
|
||||
function walk(ast, walker) {
|
||||
const instance = new SyncWalkerClass(walker);
|
||||
return instance.visit(ast, null, walker.enter, walker.leave);
|
||||
}
|
||||
|
||||
async function asyncWalk(
|
||||
ast,
|
||||
walker
|
||||
) {
|
||||
const instance = new AsyncWalkerClass(walker);
|
||||
return await instance.visit(ast, null, walker.enter, walker.leave);
|
||||
}
|
||||
|
||||
export { walk, asyncWalk };
|
||||
16
node_modules/estree-walker/src/index.ts
generated
vendored
Normal file
16
node_modules/estree-walker/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { BaseNode } from "estree";
|
||||
import { SyncWalkerClass, SyncWalker } from "./sync";
|
||||
import { AsyncWalkerClass, AsyncWalker } from "./async";
|
||||
|
||||
export function walk(ast: BaseNode, walker: SyncWalker): BaseNode {
|
||||
const instance = new SyncWalkerClass(walker);
|
||||
return instance.visit(ast, null, walker.enter, walker.leave);
|
||||
}
|
||||
|
||||
export async function asyncWalk(
|
||||
ast: BaseNode,
|
||||
walker: AsyncWalker
|
||||
): Promise<BaseNode> {
|
||||
const instance = new AsyncWalkerClass(walker);
|
||||
return await instance.visit(ast, null, walker.enter, walker.leave);
|
||||
}
|
||||
113
node_modules/estree-walker/src/sync.ts
generated
vendored
Normal file
113
node_modules/estree-walker/src/sync.ts
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
import { WalkerBase, WalkerContext } from "./walker";
|
||||
import { BaseNode } from "estree";
|
||||
|
||||
export type SyncWalker = {
|
||||
enter?: WalkerHandler;
|
||||
leave?: WalkerHandler;
|
||||
};
|
||||
|
||||
export type WalkerHandler = (
|
||||
this: WalkerContext,
|
||||
node: BaseNode,
|
||||
parent: BaseNode,
|
||||
key: string,
|
||||
index: number
|
||||
) => void;
|
||||
|
||||
export class SyncWalkerClass extends WalkerBase {
|
||||
protected enter: SyncWalker["enter"];
|
||||
protected leave: SyncWalker["leave"];
|
||||
|
||||
constructor(walker: SyncWalker) {
|
||||
super();
|
||||
this.enter = walker.enter;
|
||||
this.leave = walker.leave;
|
||||
}
|
||||
|
||||
public visit(
|
||||
node: BaseNode,
|
||||
parent: BaseNode,
|
||||
enter: WalkerHandler,
|
||||
leave: WalkerHandler,
|
||||
prop?: string,
|
||||
index?: number
|
||||
): BaseNode {
|
||||
if (node) {
|
||||
if (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;
|
||||
|
||||
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 as any)[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, enter, leave, key, i)) {
|
||||
// removed
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (value !== null && typeof value.type === "string") {
|
||||
this.visit(value, node, enter, leave, key, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (leave) {
|
||||
const _replacement = this.replacement;
|
||||
const _should_remove = this.should_remove;
|
||||
this.replacement = null;
|
||||
this.should_remove = false;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
39
node_modules/estree-walker/src/walker.ts
generated
vendored
Normal file
39
node_modules/estree-walker/src/walker.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { BaseNode } from "estree";
|
||||
|
||||
export type WalkerContext = {
|
||||
skip: () => void;
|
||||
remove: () => void;
|
||||
replace: (node: BaseNode) => void;
|
||||
};
|
||||
|
||||
export class WalkerBase {
|
||||
protected should_skip: boolean = false;
|
||||
protected should_remove: boolean = false;
|
||||
protected replacement: BaseNode = null;
|
||||
|
||||
public context: WalkerContext = {
|
||||
skip: () => (this.should_skip = true),
|
||||
remove: () => (this.should_remove = true),
|
||||
replace: (node: BaseNode) => (this.replacement = node)
|
||||
};
|
||||
|
||||
public replace(parent: any, prop: string, index: number, node: BaseNode) {
|
||||
if (parent) {
|
||||
if (index !== null) {
|
||||
parent[prop][index] = node;
|
||||
} else {
|
||||
parent[prop] = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public remove(parent: any, prop: string, index: number) {
|
||||
if (parent) {
|
||||
if (index !== null) {
|
||||
parent[prop].splice(index, 1);
|
||||
} else {
|
||||
delete parent[prop];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
node_modules/estree-walker/types/async.d.ts
generated
vendored
Normal file
13
node_modules/estree-walker/types/async.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { WalkerBase, WalkerContext } from "./walker";
|
||||
import { BaseNode } from "estree";
|
||||
export declare type AsyncWalker = {
|
||||
enter?: AsyncWalkerHandler;
|
||||
leave?: AsyncWalkerHandler;
|
||||
};
|
||||
export declare type AsyncWalkerHandler = (this: WalkerContext, node: BaseNode, parent: BaseNode, key: string, index: number) => Promise<void>;
|
||||
export declare class AsyncWalkerClass extends WalkerBase {
|
||||
protected enter: AsyncWalker["enter"];
|
||||
protected leave: AsyncWalker["leave"];
|
||||
constructor(walker: AsyncWalker);
|
||||
visit(node: BaseNode, parent: BaseNode, enter: AsyncWalkerHandler, leave: AsyncWalkerHandler, prop?: string, index?: number): Promise<BaseNode>;
|
||||
}
|
||||
5
node_modules/estree-walker/types/index.d.ts
generated
vendored
Normal file
5
node_modules/estree-walker/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { BaseNode } from "estree";
|
||||
import { SyncWalker } from "./sync";
|
||||
import { AsyncWalker } from "./async";
|
||||
export declare function walk(ast: BaseNode, walker: SyncWalker): BaseNode;
|
||||
export declare function asyncWalk(ast: BaseNode, walker: AsyncWalker): Promise<BaseNode>;
|
||||
13
node_modules/estree-walker/types/sync.d.ts
generated
vendored
Normal file
13
node_modules/estree-walker/types/sync.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { WalkerBase, WalkerContext } from "./walker";
|
||||
import { BaseNode } from "estree";
|
||||
export declare type SyncWalker = {
|
||||
enter?: WalkerHandler;
|
||||
leave?: WalkerHandler;
|
||||
};
|
||||
export declare type WalkerHandler = (this: WalkerContext, node: BaseNode, parent: BaseNode, key: string, index: number) => void;
|
||||
export declare class SyncWalkerClass extends WalkerBase {
|
||||
protected enter: SyncWalker["enter"];
|
||||
protected leave: SyncWalker["leave"];
|
||||
constructor(walker: SyncWalker);
|
||||
visit(node: BaseNode, parent: BaseNode, enter: WalkerHandler, leave: WalkerHandler, prop?: string, index?: number): BaseNode;
|
||||
}
|
||||
14
node_modules/estree-walker/types/walker.d.ts
generated
vendored
Normal file
14
node_modules/estree-walker/types/walker.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { BaseNode } from "estree";
|
||||
export declare type WalkerContext = {
|
||||
skip: () => void;
|
||||
remove: () => void;
|
||||
replace: (node: BaseNode) => void;
|
||||
};
|
||||
export declare class WalkerBase {
|
||||
protected should_skip: boolean;
|
||||
protected should_remove: boolean;
|
||||
protected replacement: BaseNode;
|
||||
context: WalkerContext;
|
||||
replace(parent: any, prop: string, index: number, node: BaseNode): void;
|
||||
remove(parent: any, prop: string, index: number): void;
|
||||
}
|
||||
Reference in New Issue
Block a user