ast-monkey-traverse 4.2.2 → 4.3.1
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 +26 -0
- package/README.md +6 -5
- package/dist/ast-monkey-traverse.esm.js +2 -2
- package/dist/ast-monkey-traverse.umd.js +2 -10
- package/package.json +1 -7
- package/types/index.d.ts +38 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
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
|
+
## 4.3.1 (2026-09-06)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **ast-monkey-traverse:** remove unnecessary test dependency ([013b228](https://github.com/codsen/codsen/commit/013b2283e7b554debb27e135726cb4241e2139cd))
|
|
11
|
+
|
|
12
|
+
## 4.3.0 (2026-09-01)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **ast-monkey:** preserve traversal data semantics ([861b9fc](https://github.com/codsen/codsen/commit/861b9fc242abb9e6a06c665a80e884970276b22d))
|
|
17
|
+
- enforce traversal tree inputs ([c539860](https://github.com/codsen/codsen/commit/c5398605891bca6e8074a9ab1cd8903489e0ddb0))
|
|
18
|
+
- isolate traversal parent snapshots ([10b3735](https://github.com/codsen/codsen/commit/10b3735f6d243dc831f6cf84e3be89094730b351))
|
|
19
|
+
- make ast traversal stack-safe ([fce2227](https://github.com/codsen/codsen/commit/fce22270cbec4406974b3b89e964ec3e78584374))
|
|
20
|
+
- publish sound traversal types ([03f3d46](https://github.com/codsen/codsen/commit/03f3d467978a27d41a16599a17d6cccf15d35634))
|
|
21
|
+
- refresh metadata after container callbacks ([a39d320](https://github.com/codsen/codsen/commit/a39d32002d4d46b19ebe234c7e46256546fae822))
|
|
22
|
+
- traverse compacted array entries ([815cb45](https://github.com/codsen/codsen/commit/815cb4511820d7cf409ea081ed30360c34105045))
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
- expose exact traversal path segments ([7fad3cb](https://github.com/codsen/codsen/commit/7fad3cbe99b0bcb9eae2c7600ccdd2318d5c2d02))
|
|
27
|
+
|
|
28
|
+
### Performance Improvements
|
|
29
|
+
|
|
30
|
+
- establish corrected traversal baseline ([fd8b705](https://github.com/codsen/codsen/commit/fd8b705aec8373b1cd1e9b8e11dbcaacd15bf202))
|
|
31
|
+
|
|
6
32
|
## 4.2.2 (2026-08-22)
|
|
7
33
|
|
|
8
34
|
### Performance Improvements
|
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
<img src="https://img.shields.io/badge/licence-MIT-brightgreen.svg?style=flat-square" alt="MIT Licence">
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
|
+
**No dependencies whatsoever.** This package declares no dependencies or devDependencies.
|
|
25
|
+
|
|
24
26
|
## Install
|
|
25
27
|
|
|
26
28
|
This package is [pure ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). If you're not ready yet, install an older version of this program, 2.1.0 (`npm i ast-monkey-traverse@2.1.0`).
|
|
@@ -55,12 +57,11 @@ const source = {
|
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
traverse(source, (key, val, innerObj) => {
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
let current = val !== undefined ? val : key;
|
|
60
|
+
// Objects supply a property key and value; arrays supply the element as key.
|
|
61
|
+
let current = innerObj.parentType === "object" ? val : key;
|
|
61
62
|
if (
|
|
62
63
|
// it's object (not array)
|
|
63
|
-
|
|
64
|
+
innerObj.parentType === "object" &&
|
|
64
65
|
// and has the key we need
|
|
65
66
|
key === "foo"
|
|
66
67
|
) {
|
|
@@ -77,7 +78,7 @@ assert.deepEqual(paths, ["a.foo", "a.foo.bar.0.foo", "a.foo.d.e.foo"]);
|
|
|
77
78
|
|
|
78
79
|
## Documentation
|
|
79
80
|
|
|
80
|
-
Please [visit codsen.com](https://codsen.com/os/ast-monkey-traverse/) for a full description of the API.
|
|
81
|
+
Please [visit codsen.com](https://codsen.com/os/ast-monkey-traverse/) for a full description of the API. For **Changelog**, see [raw md on GitHub](https://github.com/codsen/codsen/blob/main/packages/ast-monkey-traverse/CHANGELOG.md) or [the website](https://codsen.com/os/ast-monkey-traverse/changelog).
|
|
81
82
|
|
|
82
83
|
## Contributing
|
|
83
84
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ast-monkey-traverse
|
|
3
3
|
* @fileoverview Utility library to traverse AST
|
|
4
|
-
* @version 4.
|
|
4
|
+
* @version 4.3.1
|
|
5
5
|
* @author Roy Revelt
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ast-monkey-traverse/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
var $="4.3.1";var G=$,K=Symbol.for("ast-monkey-traverse.delete"),W=Object.prototype.hasOwnProperty;function f(e){throw new TypeError(`ast-monkey-traverse/traverse(): [THROW_ID_02] The first argument must be an acyclic, unaliased tree of arrays, plain objects, and supported primitive values; ${e}.`)}function B(e,n){let r=Number(e);return Number.isInteger(r)&&r>=0&&r<n&&`${r}`===e}function D(e){return Array.isArray(e)?new Array(e.length):{}}function P(e,n,r){n==="__proto__"?Object.defineProperty(e,n,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[n]=r}function N(e){return e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function I(e,n=!1){if(N(e))return e;typeof e!="object"&&f(`encountered an unsupported ${typeof e} value`);let r=e,i=D(r),o=[{source:r,target:i}],u=new WeakSet([r]);for(;o.length;){let t=o.pop(),{source:l,target:d}=t,s=Array.isArray(l);Object.getPrototypeOf(l)!==(s?Array.prototype:Object.prototype)&&f(s?"encountered an array with a custom prototype":"encountered a non-plain or custom-prototype object");for(let a of Reflect.ownKeys(l)){if(s&&a==="length")continue;typeof a!="string"&&f(s?"encountered a symbol-keyed array property":"encountered a symbol-keyed object property"),s&&!B(a,l.length)&&f(`encountered the non-index array property ${JSON.stringify(a)}`);let c=Object.getOwnPropertyDescriptor(l,a);c.enumerable||f(s?`encountered a non-enumerable array index ${a}`:`encountered a non-enumerable property ${JSON.stringify(a)}`),!("value"in c)&&!n&&f(s?`encountered an accessor array index ${a}`:`encountered an accessor property ${JSON.stringify(a)}`);let p="value"in c?c.value:l[a];if(N(p))P(d,a,p);else if(typeof p=="object"){u.has(p)&&f("encountered a cycle or repeated object reference"),u.add(p);let g=D(p);P(d,a,g),o.push({source:p,target:g})}else f(`encountered an unsupported ${typeof p} value`)}}return i}var m=Symbol("deleted snapshot entry");function k(e){let n={array:Array.isArray(e),entries:new Map,...Array.isArray(e)?{lengths:[{value:e.length,version:0}]}:{}},r=[{source:e,target:n}];for(;r.length;){let i=r.pop(),{source:o,target:u}=i;for(let t of Object.keys(o)){let l=o[t];if(typeof l=="object"&&l!==null){let d={array:Array.isArray(l),entries:new Map,...Array.isArray(l)?{lengths:[{value:l.length,version:0}]}:{}};u.entries.set(t,[{value:d,version:0}]),r.push({source:l,target:d})}else u.entries.set(t,[{value:l,version:0}])}}return n}function F(e,n){let r=0,i=e.length-1;for(;r<i;){let o=Math.ceil((r+i)/2);e[o].version<=n?r=o:i=o-1}return e[r]}function T(e,n,r){let i=e.entries.get(n);return i?F(i,r).value:m}function V(e,n){return F(e.lengths,n).value}function O(e,n,r,i){let o=e.entries.get(n);o?o.push({value:r,version:i}):e.entries.set(n,[{value:m,version:i-1},{value:r,version:i}])}function H(e,n,r){let i=r-1,o=V(e,i);for(let u=n;u<o-1;u+=1)O(e,`${u}`,T(e,`${u+1}`,i),r);o&&O(e,`${o-1}`,m,r),e.lengths.push({value:Math.max(0,o-1),version:r})}function _(e,n){let r=new WeakMap;function i(o){let u=r.get(o);if(u)return u;let t=o.array?new Array(V(o,n)):{},l={defineProperty:()=>!0,deleteProperty:()=>!0,get:(s,a,c)=>{if(o.array&&a==="length")return V(o,n);if(typeof a=="string"){let p=T(o,a,n);if(p!==m)return typeof p=="object"&&p!==null?i(p):p}return Reflect.get(s,a,c)},getOwnPropertyDescriptor:(s,a)=>{if(o.array&&a==="length")return Reflect.getOwnPropertyDescriptor(s,a);if(typeof a=="string"){let c=T(o,a,n);return c===m?void 0:{configurable:!0,enumerable:!0,value:typeof c=="object"&&c!==null?i(c):c,writable:!0}}},has:(s,a)=>typeof a=="string"&&T(o,a,n)!==m||Reflect.has(s,a),ownKeys:()=>{let s=[...o.entries].filter(([a])=>T(o,a,n)!==m).map(([a])=>a);return o.array?[...s,"length"]:s},set:()=>!0,setPrototypeOf:()=>!0},d=new Proxy(t,l);return r.set(o,d),d}return i(e)}function M(e){let n=[],r=e;for(;r;)n.push(r.segment),r=r.parent;return n.reverse()}function J(e){let n="";for(let r of e)n=n?`${n}.${r}`:r;return n}function Q(e,n){if(typeof n!="function")throw new TypeError(`ast-monkey-traverse/traverse(): [THROW_ID_01] The second argument must be a callback function. It was ${typeof n}.`);let r=I(e);if(typeof r!="object"||r===null)return r;let i=0,o={now:!1},u=[{container:r,depth:0,index:0,keys:Array.isArray(r)?[]:Object.keys(r),parentKey:null}];for(;u.length&&!o.now;){let t=u[u.length-1],l=Array.isArray(t.container)?t.container:void 0,d=!!l,s;if(l){if(t.index>=l.length){u.pop();continue}if(!W.call(l,t.index)){t.index+=1;continue}s=`${t.index}`}else{if(t.index>=t.keys.length){u.pop();continue}s=t.keys[t.index]}let a=t.container[s],c={parent:t.pathNode,segment:s},p=t.depth===0&&!d?s:t.topmostKey,g,R=i,j,v,S;if(t.depth<100)j=t.path?`${t.path}.${s}`:s,v=t.pathSegments?[...t.pathSegments,s]:[s],S={depth:t.depth,path:j,pathSegments:v,get parent(){return t.snapshot||=k(t.container),g||=_(t.snapshot,R),g},parentType:d?"array":"object",parentKey:t.parentKey,...p===void 0?{}:{topmostKey:p}};else{let x,E;S={depth:t.depth,get path(){return x||=M(c),E??=J(x),E},get pathSegments(){return x||=M(c),x},get parent(){return t.snapshot||=k(t.container),g||=_(t.snapshot,R),g},parentType:d?"array":"object",parentKey:t.parentKey,...p===void 0?{}:{topmostKey:p}}}let y=n(d?a:s,d?void 0:a,S,o),A=y===K,w=typeof y=="object"&&y!==null,C=w&&(typeof a=="object"&&a!==null)&&y===a&&!!t.snapshot,h=y===K?a:y,b;!A&&!w&&!N(y)&&f(`encountered an unsupported ${typeof y} value`),!A&&w&&(y!==a||C)&&(h=I(y,!0),t.snapshot&&(b=k(h))),A?l?(l.splice(t.index,1),i+=1,t.snapshot&&H(t.snapshot,t.index,i)):(delete t.container[s],i+=1,t.snapshot&&O(t.snapshot,s,m,i),t.index+=1):((!Object.is(h,a)||C)&&(P(t.container,s,h),i+=1,t.snapshot&&O(t.snapshot,s,b===void 0?h:b,i)),t.index+=1,!o.now&&typeof h=="object"&&h!==null&&u.push({container:h,depth:t.depth+1,index:0,keys:Array.isArray(h)?[]:Object.keys(h),parentKey:s,...j===void 0?{}:{path:j},pathNode:c,...v===void 0?{}:{pathSegments:v},...b?{snapshot:b}:{},...p===void 0?{}:{topmostKey:p}}))}return r}export{K as DELETE,Q as traverse,G as version};
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name ast-monkey-traverse
|
|
3
3
|
* @fileoverview Utility library to traverse AST
|
|
4
|
-
* @version 4.
|
|
4
|
+
* @version 4.3.1
|
|
5
5
|
* @author Roy Revelt
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/ast-monkey-traverse/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
"use strict";var astMonkeyTraverse=(()=>{var
|
|
11
|
-
/**
|
|
12
|
-
* @name codsen-utils
|
|
13
|
-
* @fileoverview Various utility functions
|
|
14
|
-
* @version 1.9.0
|
|
15
|
-
* @author Roy Revelt
|
|
16
|
-
* @license MIT
|
|
17
|
-
* {@link https://codsen.com/os/codsen-utils/}
|
|
18
|
-
*/
|
|
10
|
+
"use strict";var astMonkeyTraverse=(()=>{var S=Object.defineProperty,z=Object.defineProperties,U=Object.getOwnPropertyDescriptor,G=Object.getOwnPropertyDescriptors,Q=Object.getOwnPropertyNames,I=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var _=(e,r,t)=>r in e?S(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,g=(e,r)=>{for(var t in r||(r={}))M.call(r,t)&&_(e,t,r[t]);if(I)for(var t of I(r))X.call(r,t)&&_(e,t,r[t]);return e},F=(e,r)=>z(e,G(r));var Y=(e,r)=>{for(var t in r)S(e,t,{get:r[t],enumerable:!0})},Z=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Q(r))!M.call(e,o)&&o!==t&&S(e,o,{get:()=>r[o],enumerable:!(s=U(r,o))||s.enumerable});return e};var ee=e=>Z(S({},"__esModule",{value:!0}),e);var le={};Y(le,{DELETE:()=>V,traverse:()=>ie,version:()=>re});var L="4.3.1";var re=L,V=Symbol.for("ast-monkey-traverse.delete"),ne=Object.prototype.hasOwnProperty;function m(e){throw new TypeError("ast-monkey-traverse/traverse(): [THROW_ID_02] The first argument must be an acyclic, unaliased tree of arrays, plain objects, and supported primitive values; ".concat(e,"."))}function oe(e,r){let t=Number(e);return Number.isInteger(t)&&t>=0&&t<r&&"".concat(t)===e}function W(e){return Array.isArray(e)?new Array(e.length):{}}function C(e,r,t){r==="__proto__"?Object.defineProperty(e,r,{configurable:!0,enumerable:!0,value:t,writable:!0}):e[r]=t}function E(e){return e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function B(e,r=!1){if(E(e))return e;typeof e!="object"&&m("encountered an unsupported ".concat(typeof e," value"));let t=e,s=W(t),o=[{source:t,target:s}],u=new WeakSet([t]);for(;o.length;){let n=o.pop(),{source:l,target:y}=n,i=Array.isArray(l);Object.getPrototypeOf(l)!==(i?Array.prototype:Object.prototype)&&m(i?"encountered an array with a custom prototype":"encountered a non-plain or custom-prototype object");for(let a of Reflect.ownKeys(l)){if(i&&a==="length")continue;typeof a!="string"&&m(i?"encountered a symbol-keyed array property":"encountered a symbol-keyed object property"),i&&!oe(a,l.length)&&m("encountered the non-index array property ".concat(JSON.stringify(a)));let c=Object.getOwnPropertyDescriptor(l,a);c.enumerable||m(i?"encountered a non-enumerable array index ".concat(a):"encountered a non-enumerable property ".concat(JSON.stringify(a))),!("value"in c)&&!r&&m(i?"encountered an accessor array index ".concat(a):"encountered an accessor property ".concat(JSON.stringify(a)));let p="value"in c?c.value:l[a];if(E(p))C(y,a,p);else if(typeof p=="object"){u.has(p)&&m("encountered a cycle or repeated object reference"),u.add(p);let f=W(p);C(y,a,f),o.push({source:p,target:f})}else m("encountered an unsupported ".concat(typeof p," value"))}}return s}var b=Symbol("deleted snapshot entry");function R(e){let r=g({array:Array.isArray(e),entries:new Map},Array.isArray(e)?{lengths:[{value:e.length,version:0}]}:{}),t=[{source:e,target:r}];for(;t.length;){let s=t.pop(),{source:o,target:u}=s;for(let n of Object.keys(o)){let l=o[n];if(typeof l=="object"&&l!==null){let y=g({array:Array.isArray(l),entries:new Map},Array.isArray(l)?{lengths:[{value:l.length,version:0}]}:{});u.entries.set(n,[{value:y,version:0}]),t.push({source:l,target:y})}else u.entries.set(n,[{value:l,version:0}])}}return r}function q(e,r){let t=0,s=e.length-1;for(;t<s;){let o=Math.ceil((t+s)/2);e[o].version<=r?t=o:s=o-1}return e[t]}function x(e,r,t){let s=e.entries.get(r);return s?q(s,t).value:b}function $(e,r){return q(e.lengths,r).value}function w(e,r,t,s){let o=e.entries.get(r);o?o.push({value:t,version:s}):e.entries.set(r,[{value:b,version:s-1},{value:t,version:s}])}function ae(e,r,t){let s=t-1,o=$(e,s);for(let u=r;u<o-1;u+=1)w(e,"".concat(u),x(e,"".concat(u+1),s),t);o&&w(e,"".concat(o-1),b,t),e.lengths.push({value:Math.max(0,o-1),version:t})}function H(e,r){let t=new WeakMap;function s(o){let u=t.get(o);if(u)return u;let n=o.array?new Array($(o,r)):{},l={defineProperty:()=>!0,deleteProperty:()=>!0,get:(i,a,c)=>{if(o.array&&a==="length")return $(o,r);if(typeof a=="string"){let p=x(o,a,r);if(p!==b)return typeof p=="object"&&p!==null?s(p):p}return Reflect.get(i,a,c)},getOwnPropertyDescriptor:(i,a)=>{if(o.array&&a==="length")return Reflect.getOwnPropertyDescriptor(i,a);if(typeof a=="string"){let c=x(o,a,r);return c===b?void 0:{configurable:!0,enumerable:!0,value:typeof c=="object"&&c!==null?s(c):c,writable:!0}}},has:(i,a)=>typeof a=="string"&&x(o,a,r)!==b||Reflect.has(i,a),ownKeys:()=>{let i=[...o.entries].filter(([a])=>x(o,a,r)!==b).map(([a])=>a);return o.array?[...i,"length"]:i},set:()=>!0,setPrototypeOf:()=>!0},y=new Proxy(n,l);return t.set(o,y),y}return s(e)}function J(e){let r=[],t=e;for(;t;)r.push(t.segment),t=t.parent;return r.reverse()}function se(e){let r="";for(let t of e)r=r?"".concat(r,".").concat(t):t;return r}function ie(e,r){if(typeof r!="function")throw new TypeError("ast-monkey-traverse/traverse(): [THROW_ID_01] The second argument must be a callback function. It was ".concat(typeof r,"."));let t=B(e);if(typeof t!="object"||t===null)return t;let s=0,o={now:!1},u=[{container:t,depth:0,index:0,keys:Array.isArray(t)?[]:Object.keys(t),parentKey:null}];for(;u.length&&!o.now;){let n=u[u.length-1],l=Array.isArray(n.container)?n.container:void 0,y=!!l,i;if(l){if(n.index>=l.length){u.pop();continue}if(!ne.call(l,n.index)){n.index+=1;continue}i="".concat(n.index)}else{if(n.index>=n.keys.length){u.pop();continue}i=n.keys[n.index]}let a=n.container[i],c={parent:n.pathNode,segment:i},p=n.depth===0&&!y?i:n.topmostKey,f,K=s,O,A,k;if(n.depth<100)O=n.path?"".concat(n.path,".").concat(i):i,A=n.pathSegments?[...n.pathSegments,i]:[i],k=g({depth:n.depth,path:O,pathSegments:A,get parent(){return n.snapshot||(n.snapshot=R(n.container)),f||(f=H(n.snapshot,K)),f},parentType:y?"array":"object",parentKey:n.parentKey},p===void 0?{}:{topmostKey:p});else{let T,v;k=g({depth:n.depth,get path(){return T||(T=J(c)),v!=null||(v=se(T)),v},get pathSegments(){return T||(T=J(c)),T},get parent(){return n.snapshot||(n.snapshot=R(n.container)),f||(f=H(n.snapshot,K)),f},parentType:y?"array":"object",parentKey:n.parentKey},p===void 0?{}:{topmostKey:p})}let d=r(y?a:i,y?void 0:a,k,o),N=d===V,P=typeof d=="object"&&d!==null,D=P&&(typeof a=="object"&&a!==null)&&d===a&&!!n.snapshot,h=d===V?a:d,j;!N&&!P&&!E(d)&&m("encountered an unsupported ".concat(typeof d," value")),!N&&P&&(d!==a||D)&&(h=B(d,!0),n.snapshot&&(j=R(h))),N?l?(l.splice(n.index,1),s+=1,n.snapshot&&ae(n.snapshot,n.index,s)):(delete n.container[i],s+=1,n.snapshot&&w(n.snapshot,i,b,s),n.index+=1):((!Object.is(h,a)||D)&&(C(n.container,i,h),s+=1,n.snapshot&&w(n.snapshot,i,j===void 0?h:j,s)),n.index+=1,!o.now&&typeof h=="object"&&h!==null&&u.push(g(g(g(F(g({container:h,depth:n.depth+1,index:0,keys:Array.isArray(h)?[]:Object.keys(h),parentKey:i},O===void 0?{}:{path:O}),{pathNode:c}),A===void 0?{}:{pathSegments:A}),j?{snapshot:j}:{}),p===void 0?{}:{topmostKey:p})))}return t}return ee(le);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ast-monkey-traverse",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"description": "Utility library to traverse AST",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -79,12 +79,6 @@
|
|
|
79
79
|
"extras": [""]
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
|
-
"dependencies": {
|
|
83
|
-
"codsen-utils": "^1.9.0"
|
|
84
|
-
},
|
|
85
|
-
"devDependencies": {
|
|
86
|
-
"deep-equal": "^2.2.3"
|
|
87
|
-
},
|
|
88
82
|
"engines": {
|
|
89
83
|
"node": ">=18.20.8"
|
|
90
84
|
},
|
package/types/index.d.ts
CHANGED
|
@@ -2,19 +2,51 @@ declare const version: string;
|
|
|
2
2
|
interface Stop {
|
|
3
3
|
now: boolean;
|
|
4
4
|
}
|
|
5
|
+
type TreePrimitive = string | number | boolean | null | undefined;
|
|
6
|
+
type TreeValue = TreePrimitive | TreeArray | TreeObject;
|
|
7
|
+
interface TreeArray extends Array<TreeValue> {}
|
|
8
|
+
interface TreeObject {
|
|
9
|
+
[key: string]: TreeValue;
|
|
10
|
+
}
|
|
11
|
+
type ReadonlyTreeValue = TreePrimitive | ReadonlyTreeArray | ReadonlyTreeObject;
|
|
12
|
+
interface ReadonlyTreeArray extends ReadonlyArray<ReadonlyTreeValue> {}
|
|
13
|
+
interface ReadonlyTreeObject {
|
|
14
|
+
readonly [key: string]: ReadonlyTreeValue;
|
|
15
|
+
}
|
|
16
|
+
type ReadonlyTreeContainer = ReadonlyTreeArray | ReadonlyTreeObject;
|
|
17
|
+
/** Return this value from a traversal callback to delete the current node. */
|
|
18
|
+
declare const DELETE: unique symbol;
|
|
5
19
|
interface InnerObj {
|
|
6
20
|
depth: number;
|
|
7
21
|
path: string;
|
|
22
|
+
pathSegments: readonly string[];
|
|
8
23
|
topmostKey?: string;
|
|
9
|
-
parent:
|
|
10
|
-
parentType:
|
|
24
|
+
parent: ReadonlyTreeContainer;
|
|
25
|
+
parentType: "array" | "object";
|
|
11
26
|
parentKey: string | null;
|
|
12
27
|
}
|
|
13
|
-
type Callback = (
|
|
28
|
+
type Callback = (
|
|
29
|
+
key: string | TreeValue,
|
|
30
|
+
val: TreeValue | undefined,
|
|
31
|
+
innerObj: InnerObj,
|
|
32
|
+
stop: Stop,
|
|
33
|
+
) => TreeValue | typeof DELETE;
|
|
14
34
|
/**
|
|
15
35
|
* Utility library to traverse AST
|
|
16
36
|
*/
|
|
17
|
-
declare function traverse
|
|
37
|
+
declare function traverse(tree1: TreeValue, cb1: Callback): TreeValue;
|
|
18
38
|
|
|
19
|
-
export { traverse, version };
|
|
20
|
-
export type {
|
|
39
|
+
export { DELETE, traverse, version };
|
|
40
|
+
export type {
|
|
41
|
+
Callback,
|
|
42
|
+
InnerObj,
|
|
43
|
+
ReadonlyTreeArray,
|
|
44
|
+
ReadonlyTreeContainer,
|
|
45
|
+
ReadonlyTreeObject,
|
|
46
|
+
ReadonlyTreeValue,
|
|
47
|
+
Stop,
|
|
48
|
+
TreeArray,
|
|
49
|
+
TreeObject,
|
|
50
|
+
TreePrimitive,
|
|
51
|
+
TreeValue,
|
|
52
|
+
};
|