ast-monkey-traverse 3.0.5 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ast-monkey-traverse
|
|
3
3
|
* @fileoverview Utility library to traverse AST
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.6
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ast-monkey-traverse/}
|
|
@@ -11,74 +11,64 @@ import clone from 'lodash.clonedeep';
|
|
|
11
11
|
import isObj from 'lodash.isplainobject';
|
|
12
12
|
import { parent } from 'ast-monkey-util';
|
|
13
13
|
|
|
14
|
-
var version$1 = "3.0.
|
|
14
|
+
var version$1 = "3.0.6";
|
|
15
15
|
|
|
16
16
|
const version = version$1;
|
|
17
17
|
function traverse(tree1, cb1) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
const stop2 = { now: false };
|
|
19
|
+
function traverseInner(treeOriginal, callback, originalInnerObj, stop) {
|
|
20
|
+
const tree = clone(treeOriginal);
|
|
21
|
+
let res;
|
|
22
|
+
const innerObj = { depth: -1, path: "", ...originalInnerObj };
|
|
23
|
+
innerObj.depth += 1;
|
|
24
|
+
if (Array.isArray(tree)) {
|
|
25
|
+
for (let i = 0, len = tree.length; i < len; i++) {
|
|
26
|
+
if (stop.now) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
const path = innerObj.path ? `${innerObj.path}.${i}` : `${i}`;
|
|
30
|
+
if (tree[i] !== undefined) {
|
|
31
|
+
innerObj.parent = clone(tree);
|
|
32
|
+
innerObj.parentType = "array";
|
|
33
|
+
innerObj.parentKey = parent(path);
|
|
34
|
+
res = traverseInner(callback(tree[i], undefined, { ...innerObj, path }, stop), callback, { ...innerObj, path }, stop);
|
|
35
|
+
if (Number.isNaN(res) && i < tree.length) {
|
|
36
|
+
tree.splice(i, 1);
|
|
37
|
+
i -= 1;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
tree[i] = res;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
tree.splice(i, 1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
34
47
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
else if (isObj(tree)) {
|
|
49
|
+
for (const key in tree) {
|
|
50
|
+
if (stop.now && key != null) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
const path = innerObj.path ? `${innerObj.path}.${key}` : key;
|
|
54
|
+
if (innerObj.depth === 0 && key != null) {
|
|
55
|
+
innerObj.topmostKey = key;
|
|
56
|
+
}
|
|
57
|
+
innerObj.parent = clone(tree);
|
|
58
|
+
innerObj.parentType = "object";
|
|
59
|
+
innerObj.parentKey = parent(path);
|
|
60
|
+
res = traverseInner(callback(key, tree[key], { ...innerObj, path }, stop), callback, { ...innerObj, path }, stop);
|
|
61
|
+
if (Number.isNaN(res)) {
|
|
62
|
+
delete tree[key];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
tree[key] = res;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
53
68
|
}
|
|
54
|
-
|
|
55
|
-
} else if (isObj(tree)) {
|
|
56
|
-
for (const key in tree) {
|
|
57
|
-
if (stop.now && key != null) {
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
const path = innerObj.path ? `${innerObj.path}.${key}` : key;
|
|
61
|
-
if (innerObj.depth === 0 && key != null) {
|
|
62
|
-
innerObj.topmostKey = key;
|
|
63
|
-
}
|
|
64
|
-
innerObj.parent = clone(tree);
|
|
65
|
-
innerObj.parentType = "object";
|
|
66
|
-
innerObj.parentKey = parent(path);
|
|
67
|
-
res = traverseInner(callback(key, tree[key], { ...innerObj,
|
|
68
|
-
path
|
|
69
|
-
}, stop), callback, { ...innerObj,
|
|
70
|
-
path
|
|
71
|
-
}, stop);
|
|
72
|
-
if (Number.isNaN(res)) {
|
|
73
|
-
delete tree[key];
|
|
74
|
-
} else {
|
|
75
|
-
tree[key] = res;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
69
|
+
return tree;
|
|
78
70
|
}
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
return traverseInner(tree1, cb1, {}, stop2);
|
|
71
|
+
return traverseInner(tree1, cb1, {}, stop2);
|
|
82
72
|
}
|
|
83
73
|
|
|
84
74
|
export { traverse, version };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ast-monkey-traverse
|
|
3
3
|
* @fileoverview Utility library to traverse AST
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.6
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ast-monkey-traverse/}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
/**
|
|
12
12
|
* @name ast-monkey-util
|
|
13
13
|
* @fileoverview Utility library of AST helper functions
|
|
14
|
-
* @version 2.0.
|
|
14
|
+
* @version 2.0.6
|
|
15
15
|
* @author Roy Revelt, Codsen Ltd
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/ast-monkey-util/}
|
|
18
|
-
*/function y(t){if(t.includes(".")){const e=t.lastIndexOf(".");if(!t.slice(0,e).includes("."))return t.slice(0,e);for(let r=e-1;r--;)if("."===t[r])return t.slice(r+1,e)}return null}t.traverse=function(t,e){return function t(e,r,o,c){const u=n(e);let a;const i={depth:-1,path:"",...o};if(i.depth+=1,Array.isArray(u))for(let e=0,o=u.length;e<o&&!c.now;e++){const o=i.path?`${i.path}.${e}`:`${e}`;void 0!==u[e]?(i.parent=n(u),i.parentType="array",i.parentKey=y(o),a=t(r(u[e],void 0,{...i,path:o},c),r,{...i,path:o},c),Number.isNaN(a)&&e<u.length?(u.splice(e,1),e-=1):u[e]=a):u.splice(e,1)}else if(p(u))for(const e in u){if(c.now&&null!=e)break;const o=i.path?`${i.path}.${e}`:e;0===i.depth&&null!=e&&(i.topmostKey=e),i.parent=n(u),i.parentType="object",i.parentKey=y(o),a=t(r(e,u[e],{...i,path:o},c),r,{...i,path:o},c),Number.isNaN(a)?delete u[e]:u[e]=a}return u}(t,e,{},{now:!1})},t.version="3.0.
|
|
18
|
+
*/function y(t){if(t.includes(".")){const e=t.lastIndexOf(".");if(!t.slice(0,e).includes("."))return t.slice(0,e);for(let r=e-1;r--;)if("."===t[r])return t.slice(r+1,e)}return null}t.traverse=function(t,e){return function t(e,r,o,c){const u=n(e);let a;const i={depth:-1,path:"",...o};if(i.depth+=1,Array.isArray(u))for(let e=0,o=u.length;e<o&&!c.now;e++){const o=i.path?`${i.path}.${e}`:`${e}`;void 0!==u[e]?(i.parent=n(u),i.parentType="array",i.parentKey=y(o),a=t(r(u[e],void 0,{...i,path:o},c),r,{...i,path:o},c),Number.isNaN(a)&&e<u.length?(u.splice(e,1),e-=1):u[e]=a):u.splice(e,1)}else if(p(u))for(const e in u){if(c.now&&null!=e)break;const o=i.path?`${i.path}.${e}`:e;0===i.depth&&null!=e&&(i.topmostKey=e),i.parent=n(u),i.parentType="object",i.parentKey=y(o),a=t(r(e,u[e],{...i,path:o},c),r,{...i,path:o},c),Number.isNaN(a)?delete u[e]:u[e]=a}return u}(t,e,{},{now:!1})},t.version="3.0.6",Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ast-monkey-traverse",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "Utility library to traverse AST",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -45,13 +45,12 @@
|
|
|
45
45
|
"types": "types/index.d.ts",
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "rollup -c",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
48
|
+
"build:esbuild": "node '../../scripts/esbuild.js'",
|
|
49
|
+
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
50
|
+
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
|
|
50
51
|
"clean_types": "../../scripts/cleanTypes.js",
|
|
51
52
|
"dev": "rollup -c --dev",
|
|
52
53
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
53
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
54
|
-
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
55
54
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
56
55
|
"lect": "lect",
|
|
57
56
|
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
|
|
@@ -60,17 +59,14 @@
|
|
|
60
59
|
"republish": "npm publish || :",
|
|
61
60
|
"tap": "tap",
|
|
62
61
|
"pretest": "npm run build",
|
|
63
|
-
"test": "npm run
|
|
62
|
+
"test": "npm run test:ci && npm run perf",
|
|
63
|
+
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
64
64
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
65
65
|
"tsc": "tsc",
|
|
66
|
-
"unittest": "tap --no-only --
|
|
66
|
+
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
67
67
|
},
|
|
68
68
|
"tap": {
|
|
69
69
|
"check-coverage": false,
|
|
70
|
-
"coverage-report": [
|
|
71
|
-
"json-summary",
|
|
72
|
-
"text"
|
|
73
|
-
],
|
|
74
70
|
"node-arg": [
|
|
75
71
|
"--no-warnings",
|
|
76
72
|
"--experimental-loader",
|
|
@@ -94,8 +90,8 @@
|
|
|
94
90
|
}
|
|
95
91
|
},
|
|
96
92
|
"dependencies": {
|
|
97
|
-
"@babel/runtime": "^7.16.
|
|
98
|
-
"ast-monkey-util": "^2.0.
|
|
93
|
+
"@babel/runtime": "^7.16.3",
|
|
94
|
+
"ast-monkey-util": "^2.0.6",
|
|
99
95
|
"lodash.clonedeep": "^4.5.0",
|
|
100
96
|
"lodash.isplainobject": "^4.0.6"
|
|
101
97
|
},
|
|
@@ -108,8 +104,8 @@
|
|
|
108
104
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
109
105
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
110
106
|
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
111
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
112
|
-
"@babel/preset-env": "^7.16.
|
|
107
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
108
|
+
"@babel/preset-env": "^7.16.4",
|
|
113
109
|
"@babel/preset-typescript": "^7.16.0",
|
|
114
110
|
"@babel/register": "^7.16.0",
|
|
115
111
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
@@ -121,27 +117,27 @@
|
|
|
121
117
|
"@rollup/plugin-typescript": "^8.3.0",
|
|
122
118
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
123
119
|
"@types/lodash.isplainobject": "^4.0.6",
|
|
124
|
-
"@types/node": "^16.11.
|
|
120
|
+
"@types/node": "^16.11.9",
|
|
125
121
|
"@types/tap": "^15.0.5",
|
|
126
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
127
|
-
"@typescript-eslint/parser": "^5.
|
|
122
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
123
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
128
124
|
"core-js": "^3.19.1",
|
|
129
125
|
"cross-env": "^7.0.3",
|
|
130
|
-
"eslint": "^8.
|
|
131
|
-
"lect": "^0.18.
|
|
126
|
+
"eslint": "^8.3.0",
|
|
127
|
+
"lect": "^0.18.6",
|
|
132
128
|
"lodash.isequal": "^4.5.0",
|
|
133
129
|
"object-path": "^0.11.8",
|
|
134
|
-
"rollup": "^2.
|
|
130
|
+
"rollup": "^2.60.0",
|
|
135
131
|
"rollup-plugin-ascii": "^0.0.3",
|
|
136
132
|
"rollup-plugin-banner": "^0.2.1",
|
|
137
133
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
138
134
|
"rollup-plugin-dts": "^4.0.1",
|
|
139
135
|
"rollup-plugin-terser": "^7.0.2",
|
|
140
|
-
"tap": "^15.
|
|
136
|
+
"tap": "^15.1.2",
|
|
141
137
|
"tslib": "^2.3.1",
|
|
142
|
-
"typescript": "^4.
|
|
138
|
+
"typescript": "^4.5.2"
|
|
143
139
|
},
|
|
144
140
|
"engines": {
|
|
145
|
-
"node": ">=
|
|
141
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
146
142
|
}
|
|
147
143
|
}
|