ast-monkey-traverse 3.0.3 → 3.0.7
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.
- package/CHANGELOG.md +0 -20
- package/LICENSE +1 -1
- package/dist/ast-monkey-traverse.esm.js +53 -63
- package/dist/ast-monkey-traverse.umd.js +3 -3
- package/package.json +22 -26
package/CHANGELOG.md
CHANGED
|
@@ -3,26 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## 3.0.3 (2021-11-02)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
|
|
11
|
-
|
|
12
|
-
### Features
|
|
13
|
-
|
|
14
|
-
- migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
|
|
15
|
-
|
|
16
|
-
### BREAKING CHANGES
|
|
17
|
-
|
|
18
|
-
- programs now are in ES Modules and won't work with Common JS require()
|
|
19
|
-
|
|
20
|
-
## 3.0.1 (2021-09-13)
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
25
|
-
|
|
26
6
|
## 3.0.0 (2021-09-09)
|
|
27
7
|
|
|
28
8
|
### Features
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010
|
|
3
|
+
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
|
@@ -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.7
|
|
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.7";
|
|
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.7
|
|
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.7
|
|
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.7",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.7",
|
|
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.7",
|
|
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.10",
|
|
125
121
|
"@types/tap": "^15.0.5",
|
|
126
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
127
|
-
"@typescript-eslint/parser": "^5.
|
|
128
|
-
"core-js": "^3.19.
|
|
122
|
+
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
123
|
+
"@typescript-eslint/parser": "^5.5.0",
|
|
124
|
+
"core-js": "^3.19.2",
|
|
129
125
|
"cross-env": "^7.0.3",
|
|
130
|
-
"eslint": "^8.
|
|
131
|
-
"lect": "^0.18.
|
|
126
|
+
"eslint": "^8.3.0",
|
|
127
|
+
"lect": "^0.18.7",
|
|
132
128
|
"lodash.isequal": "^4.5.0",
|
|
133
129
|
"object-path": "^0.11.8",
|
|
134
|
-
"rollup": "^2.
|
|
130
|
+
"rollup": "^2.60.1",
|
|
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
|
-
"rollup-plugin-dts": "^4.0.
|
|
134
|
+
"rollup-plugin-dts": "^4.0.1",
|
|
139
135
|
"rollup-plugin-terser": "^7.0.2",
|
|
140
|
-
"tap": "^15.
|
|
136
|
+
"tap": "^15.1.5",
|
|
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
|
}
|