ast-monkey-traverse 3.0.2 → 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.
package/CHANGELOG.md CHANGED
@@ -3,12 +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.1 (2021-09-13)
7
-
8
- ### Bug Fixes
9
-
10
- - bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
11
-
12
6
  ## 3.0.0 (2021-09-09)
13
7
 
14
8
  ### Features
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-%YEAR% Roy Revelt and other contributors
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.2
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.2";
14
+ var version$1 = "3.0.6";
15
15
 
16
16
  const version = version$1;
17
17
  function traverse(tree1, cb1) {
18
- const stop2 = {
19
- now: false
20
- };
21
- function traverseInner(treeOriginal, callback, originalInnerObj, stop) {
22
- const tree = clone(treeOriginal);
23
- let res;
24
- const innerObj = {
25
- depth: -1,
26
- path: "",
27
- ...originalInnerObj
28
- };
29
- innerObj.depth += 1;
30
- if (Array.isArray(tree)) {
31
- for (let i = 0, len = tree.length; i < len; i++) {
32
- if (stop.now) {
33
- break;
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
- const path = innerObj.path ? `${innerObj.path}.${i}` : `${i}`;
36
- if (tree[i] !== undefined) {
37
- innerObj.parent = clone(tree);
38
- innerObj.parentType = "array";
39
- innerObj.parentKey = parent(path);
40
- res = traverseInner(callback(tree[i], undefined, { ...innerObj,
41
- path
42
- }, stop), callback, { ...innerObj,
43
- path
44
- }, stop);
45
- if (Number.isNaN(res) && i < tree.length) {
46
- tree.splice(i, 1);
47
- i -= 1;
48
- } else {
49
- tree[i] = res;
50
- }
51
- } else {
52
- tree.splice(i, 1);
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 tree;
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.2
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.2
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.2",Object.defineProperty(t,"__esModule",{value:!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.2",
3
+ "version": "3.0.6",
4
4
  "description": "Utility library to traverse AST",
5
5
  "keywords": [
6
6
  "ast",
@@ -45,9 +45,10 @@
45
45
  "types": "types/index.d.ts",
46
46
  "scripts": {
47
47
  "build": "rollup -c",
48
- "esbuild": "node '../../scripts/esbuild.js'",
49
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
50
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
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",
51
+ "clean_types": "../../scripts/cleanTypes.js",
51
52
  "dev": "rollup -c --dev",
52
53
  "devunittest": "npm run dev && tap --only -R 'base'",
53
54
  "format": "npm run lect && npm run prettier && npm run lint",
@@ -57,20 +58,15 @@
57
58
  "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
58
59
  "republish": "npm publish || :",
59
60
  "tap": "tap",
60
- "tsc": "tsc",
61
61
  "pretest": "npm run build",
62
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
62
+ "test": "npm run test:ci && npm run perf",
63
+ "test:ci": "npm run unittest && npm run test:examples && npm run format",
63
64
  "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
64
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf",
65
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
66
- "clean_types": "../../scripts/cleanTypes.js"
65
+ "tsc": "tsc",
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,54 +90,54 @@
94
90
  }
95
91
  },
96
92
  "dependencies": {
97
- "@babel/runtime": "^7.15.4",
98
- "ast-monkey-util": "^2.0.2",
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
  },
102
98
  "devDependencies": {
103
- "@babel/cli": "^7.15.4",
104
- "@babel/core": "^7.15.5",
105
- "@babel/node": "^7.15.4",
106
- "@babel/plugin-external-helpers": "^7.14.5",
107
- "@babel/plugin-proposal-class-properties": "^7.14.5",
108
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
109
- "@babel/plugin-proposal-object-rest-spread": "^7.15.6",
110
- "@babel/plugin-proposal-optional-chaining": "^7.14.5",
111
- "@babel/plugin-transform-runtime": "^7.15.0",
112
- "@babel/preset-env": "^7.15.6",
113
- "@babel/preset-typescript": "^7.15.0",
114
- "@babel/register": "^7.15.3",
99
+ "@babel/cli": "^7.16.0",
100
+ "@babel/core": "^7.16.0",
101
+ "@babel/node": "^7.16.0",
102
+ "@babel/plugin-external-helpers": "^7.16.0",
103
+ "@babel/plugin-proposal-class-properties": "^7.16.0",
104
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
105
+ "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
106
+ "@babel/plugin-proposal-optional-chaining": "^7.16.0",
107
+ "@babel/plugin-transform-runtime": "^7.16.4",
108
+ "@babel/preset-env": "^7.16.4",
109
+ "@babel/preset-typescript": "^7.16.0",
110
+ "@babel/register": "^7.16.0",
115
111
  "@istanbuljs/esm-loader-hook": "^0.1.2",
116
112
  "@rollup/plugin-babel": "^5.3.0",
117
- "@rollup/plugin-commonjs": "^20.0.0",
113
+ "@rollup/plugin-commonjs": "^21.0.1",
118
114
  "@rollup/plugin-json": "^4.1.0",
119
- "@rollup/plugin-node-resolve": "^13.0.4",
115
+ "@rollup/plugin-node-resolve": "^13.0.6",
120
116
  "@rollup/plugin-strip": "^2.1.0",
121
- "@rollup/plugin-typescript": "^8.2.5",
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.9.1",
120
+ "@types/node": "^16.11.9",
125
121
  "@types/tap": "^15.0.5",
126
- "@typescript-eslint/eslint-plugin": "^4.31.0",
127
- "@typescript-eslint/parser": "^4.31.0",
128
- "core-js": "^3.17.3",
122
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
123
+ "@typescript-eslint/parser": "^5.4.0",
124
+ "core-js": "^3.19.1",
129
125
  "cross-env": "^7.0.3",
130
- "eslint": "^7.32.0",
131
- "lect": "^0.18.2",
126
+ "eslint": "^8.3.0",
127
+ "lect": "^0.18.6",
132
128
  "lodash.isequal": "^4.5.0",
133
- "object-path": "^0.11.7",
134
- "rollup": "^2.56.3",
129
+ "object-path": "^0.11.8",
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
- "rollup-plugin-dts": "^4.0.0",
134
+ "rollup-plugin-dts": "^4.0.1",
139
135
  "rollup-plugin-terser": "^7.0.2",
140
- "tap": "^15.0.9",
136
+ "tap": "^15.1.2",
141
137
  "tslib": "^2.3.1",
142
- "typescript": "^4.4.3"
138
+ "typescript": "^4.5.2"
143
139
  },
144
140
  "engines": {
145
- "node": ">=12"
141
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
146
142
  }
147
143
  }