ast-monkey-traverse 3.0.6 → 3.0.12

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-2021 Roy Revelt and other contributors
3
+ Copyright (c) 2010-2022 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
package/README.md CHANGED
@@ -26,18 +26,17 @@
26
26
 
27
27
  ## Install
28
28
 
29
- This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:
29
+ The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `2.1.0`.
30
30
 
31
31
  ```bash
32
32
  npm i ast-monkey-traverse
33
33
  ```
34
34
 
35
- If you need a legacy version which works with `require`, use version 2.1.0
36
-
37
35
  ## Quick Take
38
36
 
39
37
  ```js
40
38
  import { strict as assert } from "assert";
39
+
41
40
  import { traverse } from "ast-monkey-traverse";
42
41
 
43
42
  const paths = [];
@@ -61,7 +60,7 @@ const source = {
61
60
  traverse(source, (key, val, innerObj) => {
62
61
  // if currently an object is traversed, you get both "key" and "val"
63
62
  // if it's array, only "key" is present, "val" is undefined
64
- const current = val !== undefined ? val : key;
63
+ let current = val !== undefined ? val : key;
65
64
  if (
66
65
  // it's object (not array)
67
66
  val !== undefined &&
@@ -80,7 +79,7 @@ assert.deepEqual(paths, ["a.foo", "a.foo.bar.0.foo", "a.foo.d.e.foo"]);
80
79
 
81
80
  ## Documentation
82
81
 
83
- Please [visit codsen.com](https://codsen.com/os/ast-monkey-traverse/) for a full description of the API and examples.
82
+ Please [visit codsen.com](https://codsen.com/os/ast-monkey-traverse/) for a full description of the API.
84
83
 
85
84
  ## Contributing
86
85
 
@@ -90,6 +89,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
90
89
 
91
90
  MIT License
92
91
 
93
- Copyright (c) 2010-2021 Roy Revelt and other contributors
92
+ Copyright (c) 2010-2022 Roy Revelt and other contributors
94
93
 
95
94
  <img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
@@ -1,74 +1,10 @@
1
1
  /**
2
2
  * @name ast-monkey-traverse
3
3
  * @fileoverview Utility library to traverse AST
4
- * @version 3.0.6
4
+ * @version 3.0.12
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/ast-monkey-traverse/}
8
8
  */
9
9
 
10
- import clone from 'lodash.clonedeep';
11
- import isObj from 'lodash.isplainobject';
12
- import { parent } from 'ast-monkey-util';
13
-
14
- var version$1 = "3.0.6";
15
-
16
- const version = version$1;
17
- function traverse(tree1, cb1) {
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
- }
47
- }
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
- }
68
- }
69
- return tree;
70
- }
71
- return traverseInner(tree1, cb1, {}, stop2);
72
- }
73
-
74
- export { traverse, version };
10
+ import p from"lodash.clonedeep";import g from"lodash.isplainobject";import{parent as m}from"ast-monkey-util";var u="3.0.12";var D=u;function k(y,c){let d={now:!1};function a($,l,b,r){let n=p($),s,t={depth:-1,path:"",...b};if(t.depth+=1,Array.isArray(n))for(let e=0,o=n.length;e<o&&!r.now;e++){let i=t.path?`${t.path}.${e}`:`${e}`;n[e]!==void 0?(t.parent=p(n),t.parentType="array",t.parentKey=m(i),s=a(l(n[e],void 0,{...t,path:i},r),l,{...t,path:i},r),Number.isNaN(s)&&e<n.length?(n.splice(e,1),e-=1):n[e]=s):n.splice(e,1)}else if(g(n))for(let e in n){if(r.now&&e!=null)break;let o=t.path?`${t.path}.${e}`:e;t.depth===0&&e!=null&&(t.topmostKey=e),t.parent=p(n),t.parentType="object",t.parentKey=m(o),s=a(l(e,n[e],{...t,path:o},r),l,{...t,path:o},r),Number.isNaN(s)?delete n[e]:n[e]=s}return n}return a(y,c,{},d)}export{k as traverse,D as version};
@@ -1,18 +1,18 @@
1
1
  /**
2
2
  * @name ast-monkey-traverse
3
3
  * @fileoverview Utility library to traverse AST
4
- * @version 3.0.6
4
+ * @version 3.0.12
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/ast-monkey-traverse/}
8
8
  */
9
9
 
10
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).astMonkeyTraverse={})}(this,(function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r={exports:{}};!function(t,r){var n="__lodash_hash_undefined__",o=9007199254740991,c="[object Arguments]",u="[object Boolean]",a="[object Date]",i="[object Function]",f="[object GeneratorFunction]",s="[object Map]",l="[object Number]",p="[object Object]",y="[object Promise]",h="[object RegExp]",_="[object Set]",v="[object String]",d="[object Symbol]",b="[object WeakMap]",j="[object ArrayBuffer]",g="[object DataView]",w="[object Float32Array]",O="[object Float64Array]",A="[object Int8Array]",m="[object Int16Array]",x="[object Int32Array]",S="[object Uint8Array]",$="[object Uint8ClampedArray]",P="[object Uint16Array]",T="[object Uint32Array]",I=/\w*$/,k=/^\[object .+?Constructor\]$/,E=/^(?:0|[1-9]\d*)$/,F={};F[c]=F["[object Array]"]=F[j]=F[g]=F[u]=F[a]=F[w]=F[O]=F[A]=F[m]=F[x]=F[s]=F[l]=F[p]=F[h]=F[_]=F[v]=F[d]=F[S]=F[$]=F[P]=F[T]=!0,F["[object Error]"]=F[i]=F[b]=!1;var N="object"==typeof self&&self&&self.Object===Object&&self,M="object"==typeof e&&e&&e.Object===Object&&e||N||Function("return this")(),B=r&&!r.nodeType&&r,U=B&&t&&!t.nodeType&&t,D=U&&U.exports===B;function K(t,e){return t.set(e[0],e[1]),t}function R(t,e){return t.add(e),t}function z(t,e,r,n){var o=-1,c=t?t.length:0;for(n&&c&&(r=t[++o]);++o<c;)r=e(r,t[o],o,t);return r}function C(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function L(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function V(t,e){return function(r){return t(e(r))}}function W(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}var G,q=Array.prototype,H=Function.prototype,J=Object.prototype,Q=M["__core-js_shared__"],X=(G=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||""))?"Symbol(src)_1."+G:"",Y=H.toString,Z=J.hasOwnProperty,tt=J.toString,et=RegExp("^"+Y.call(Z).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rt=D?M.Buffer:void 0,nt=M.Symbol,ot=M.Uint8Array,ct=V(Object.getPrototypeOf,Object),ut=Object.create,at=J.propertyIsEnumerable,it=q.splice,ft=Object.getOwnPropertySymbols,st=rt?rt.isBuffer:void 0,lt=V(Object.keys,Object),pt=Ut(M,"DataView"),yt=Ut(M,"Map"),ht=Ut(M,"Promise"),_t=Ut(M,"Set"),vt=Ut(M,"WeakMap"),dt=Ut(Object,"create"),bt=Ct(pt),jt=Ct(yt),gt=Ct(ht),wt=Ct(_t),Ot=Ct(vt),At=nt?nt.prototype:void 0,mt=At?At.valueOf:void 0;function xt(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function St(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function $t(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Pt(t){this.__data__=new St(t)}function Tt(t,e){var r=Vt(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&Wt(t)}(t)&&Z.call(t,"callee")&&(!at.call(t,"callee")||tt.call(t)==c)}(t)?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],n=r.length,o=!!n;for(var u in t)!e&&!Z.call(t,u)||o&&("length"==u||Rt(u,n))||r.push(u);return r}function It(t,e,r){var n=t[e];Z.call(t,e)&&Lt(n,r)&&(void 0!==r||e in t)||(t[e]=r)}function kt(t,e){for(var r=t.length;r--;)if(Lt(t[r][0],e))return r;return-1}function Et(t,e,r,n,o,y,b){var k;if(n&&(k=y?n(t,o,y,b):n(t)),void 0!==k)return k;if(!Ht(t))return t;var E=Vt(t);if(E){if(k=function(t){var e=t.length,r=t.constructor(e);e&&"string"==typeof t[0]&&Z.call(t,"index")&&(r.index=t.index,r.input=t.input);return r}(t),!e)return function(t,e){var r=-1,n=t.length;e||(e=Array(n));for(;++r<n;)e[r]=t[r];return e}(t,k)}else{var N=Kt(t),M=N==i||N==f;if(Gt(t))return function(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}(t,e);if(N==p||N==c||M&&!y){if(C(t))return y?t:{};if(k=function(t){return"function"!=typeof t.constructor||zt(t)?{}:(e=ct(t),Ht(e)?ut(e):{});var e}(M?{}:t),!e)return function(t,e){return Mt(t,Dt(t),e)}(t,function(t,e){return t&&Mt(e,Jt(e),t)}(k,t))}else{if(!F[N])return y?t:{};k=function(t,e,r,n){var o=t.constructor;switch(e){case j:return Nt(t);case u:case a:return new o(+t);case g:return function(t,e){var r=e?Nt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,n);case w:case O:case A:case m:case x:case S:case $:case P:case T:return function(t,e){var r=e?Nt(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,n);case s:return function(t,e,r){return z(e?r(L(t),!0):L(t),K,new t.constructor)}(t,n,r);case l:case v:return new o(t);case h:return function(t){var e=new t.constructor(t.source,I.exec(t));return e.lastIndex=t.lastIndex,e}(t);case _:return function(t,e,r){return z(e?r(W(t),!0):W(t),R,new t.constructor)}(t,n,r);case d:return c=t,mt?Object(mt.call(c)):{}}var c}(t,N,Et,e)}}b||(b=new Pt);var B=b.get(t);if(B)return B;if(b.set(t,k),!E)var U=r?function(t){return function(t,e,r){var n=e(t);return Vt(t)?n:function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}(n,r(t))}(t,Jt,Dt)}(t):Jt(t);return function(t,e){for(var r=-1,n=t?t.length:0;++r<n&&!1!==e(t[r],r,t););}(U||t,(function(o,c){U&&(o=t[c=o]),It(k,c,Et(o,e,r,n,c,t,b))})),k}function Ft(t){return!(!Ht(t)||(e=t,X&&X in e))&&(qt(t)||C(t)?et:k).test(Ct(t));var e}function Nt(t){var e=new t.constructor(t.byteLength);return new ot(e).set(new ot(t)),e}function Mt(t,e,r,n){r||(r={});for(var o=-1,c=e.length;++o<c;){var u=e[o],a=n?n(r[u],t[u],u,r,t):void 0;It(r,u,void 0===a?t[u]:a)}return r}function Bt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function Ut(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return Ft(r)?r:void 0}xt.prototype.clear=function(){this.__data__=dt?dt(null):{}},xt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},xt.prototype.get=function(t){var e=this.__data__;if(dt){var r=e[t];return r===n?void 0:r}return Z.call(e,t)?e[t]:void 0},xt.prototype.has=function(t){var e=this.__data__;return dt?void 0!==e[t]:Z.call(e,t)},xt.prototype.set=function(t,e){return this.__data__[t]=dt&&void 0===e?n:e,this},St.prototype.clear=function(){this.__data__=[]},St.prototype.delete=function(t){var e=this.__data__,r=kt(e,t);return!(r<0)&&(r==e.length-1?e.pop():it.call(e,r,1),!0)},St.prototype.get=function(t){var e=this.__data__,r=kt(e,t);return r<0?void 0:e[r][1]},St.prototype.has=function(t){return kt(this.__data__,t)>-1},St.prototype.set=function(t,e){var r=this.__data__,n=kt(r,t);return n<0?r.push([t,e]):r[n][1]=e,this},$t.prototype.clear=function(){this.__data__={hash:new xt,map:new(yt||St),string:new xt}},$t.prototype.delete=function(t){return Bt(this,t).delete(t)},$t.prototype.get=function(t){return Bt(this,t).get(t)},$t.prototype.has=function(t){return Bt(this,t).has(t)},$t.prototype.set=function(t,e){return Bt(this,t).set(t,e),this},Pt.prototype.clear=function(){this.__data__=new St},Pt.prototype.delete=function(t){return this.__data__.delete(t)},Pt.prototype.get=function(t){return this.__data__.get(t)},Pt.prototype.has=function(t){return this.__data__.has(t)},Pt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof St){var n=r.__data__;if(!yt||n.length<199)return n.push([t,e]),this;r=this.__data__=new $t(n)}return r.set(t,e),this};var Dt=ft?V(ft,Object):function(){return[]},Kt=function(t){return tt.call(t)};function Rt(t,e){return!!(e=null==e?o:e)&&("number"==typeof t||E.test(t))&&t>-1&&t%1==0&&t<e}function zt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||J)}function Ct(t){if(null!=t){try{return Y.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Lt(t,e){return t===e||t!=t&&e!=e}(pt&&Kt(new pt(new ArrayBuffer(1)))!=g||yt&&Kt(new yt)!=s||ht&&Kt(ht.resolve())!=y||_t&&Kt(new _t)!=_||vt&&Kt(new vt)!=b)&&(Kt=function(t){var e=tt.call(t),r=e==p?t.constructor:void 0,n=r?Ct(r):void 0;if(n)switch(n){case bt:return g;case jt:return s;case gt:return y;case wt:return _;case Ot:return b}return e});var Vt=Array.isArray;function Wt(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=o}(t.length)&&!qt(t)}var Gt=st||function(){return!1};function qt(t){var e=Ht(t)?tt.call(t):"";return e==i||e==f}function Ht(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Jt(t){return Wt(t)?Tt(t):function(t){if(!zt(t))return lt(t);var e=[];for(var r in Object(t))Z.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}t.exports=function(t){return Et(t,!0,!0)}}(r,r.exports);var n=r.exports;var o,c,u=Object.prototype,a=Function.prototype.toString,i=u.hasOwnProperty,f=a.call(Object),s=u.toString,l=(o=Object.getPrototypeOf,c=Object,function(t){return o(c(t))});var p=function(t){if(!function(t){return!!t&&"object"==typeof t}(t)||"[object Object]"!=s.call(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t))return!1;var e=l(t);if(null===e)return!0;var r=i.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&a.call(r)==f};
10
+ var astMonkeyTraverse=(()=>{var ne=Object.create;var w=Object.defineProperty,oe=Object.defineProperties,ae=Object.getOwnPropertyDescriptor,ie=Object.getOwnPropertyDescriptors,se=Object.getOwnPropertyNames,rt=Object.getOwnPropertySymbols,ce=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var ot=(t,e,r)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e)=>{for(var r in e||(e={}))nt.call(e,r)&&ot(t,r,e[r]);if(rt)for(var r of rt(e))ue.call(e,r)&&ot(t,r,e[r]);return t},T=(t,e)=>oe(t,ie(e)),at=t=>w(t,"__esModule",{value:!0});var it=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),le=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})},st=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of se(e))!nt.call(t,o)&&(r||o!=="default")&&w(t,o,{get:()=>e[o],enumerable:!(n=ae(e,o))||n.enumerable});return t},ct=(t,e)=>st(at(w(t!=null?ne(ce(t)):{},"default",!e&&t&&t.__esModule?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t),fe=(t=>(e,r)=>t&&t.get(e)||(r=st(at({}),e,1),t&&t.set(e,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var Xt=it((C,x)=>{var pe=200,ut="__lodash_hash_undefined__",lt=9007199254740991,k="[object Arguments]",de="[object Array]",ft="[object Boolean]",pt="[object Date]",he="[object Error]",F="[object Function]",dt="[object GeneratorFunction]",P="[object Map]",ht="[object Number]",H="[object Object]",gt="[object Promise]",yt="[object RegExp]",D="[object Set]",bt="[object String]",_t="[object Symbol]",L="[object WeakMap]",mt="[object ArrayBuffer]",N="[object DataView]",$t="[object Float32Array]",vt="[object Float64Array]",jt="[object Int8Array]",Ot="[object Int16Array]",St="[object Int32Array]",xt="[object Uint8Array]",wt="[object Uint8ClampedArray]",Tt="[object Uint16Array]",At="[object Uint32Array]",ge=/[\\^$.*+?()[\]{}|]/g,ye=/\w*$/,be=/^\[object .+?Constructor\]$/,_e=/^(?:0|[1-9]\d*)$/,a={};a[k]=a[de]=a[mt]=a[N]=a[ft]=a[pt]=a[$t]=a[vt]=a[jt]=a[Ot]=a[St]=a[P]=a[ht]=a[H]=a[yt]=a[D]=a[bt]=a[_t]=a[xt]=a[wt]=a[Tt]=a[At]=!0;a[he]=a[F]=a[L]=!1;var me=typeof global=="object"&&global&&global.Object===Object&&global,$e=typeof self=="object"&&self&&self.Object===Object&&self,d=me||$e||Function("return this")(),Et=typeof C=="object"&&C&&!C.nodeType&&C,Ct=Et&&typeof x=="object"&&x&&!x.nodeType&&x,ve=Ct&&Ct.exports===Et;function je(t,e){return t.set(e[0],e[1]),t}function Oe(t,e){return t.add(e),t}function Se(t,e){for(var r=-1,n=t?t.length:0;++r<n&&e(t[r],r,t)!==!1;);return t}function xe(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function It(t,e,r,n){var o=-1,c=t?t.length:0;for(n&&c&&(r=t[++o]);++o<c;)r=e(r,t[o],o,t);return r}function we(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}function Te(t,e){return t==null?void 0:t[e]}function Pt(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(r){}return e}function Dt(t){var e=-1,r=Array(t.size);return t.forEach(function(n,o){r[++e]=[o,n]}),r}function U(t,e){return function(r){return t(e(r))}}function Nt(t){var e=-1,r=Array(t.size);return t.forEach(function(n){r[++e]=n}),r}var Ae=Array.prototype,Ee=Function.prototype,K=Object.prototype,J=d["__core-js_shared__"],Kt=function(){var t=/[^.]+$/.exec(J&&J.keys&&J.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Vt=Ee.toString,y=K.hasOwnProperty,V=K.toString,Ce=RegExp("^"+Vt.call(y).replace(ge,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Mt=ve?d.Buffer:void 0,Rt=d.Symbol,Bt=d.Uint8Array,Ie=U(Object.getPrototypeOf,Object),Pe=Object.create,De=K.propertyIsEnumerable,Ne=Ae.splice,Gt=Object.getOwnPropertySymbols,Ke=Mt?Mt.isBuffer:void 0,Ve=U(Object.keys,Object),W=S(d,"DataView"),A=S(d,"Map"),q=S(d,"Promise"),Y=S(d,"Set"),X=S(d,"WeakMap"),E=S(Object,"create"),Me=$(W),Re=$(A),Be=$(q),Ge=$(Y),ke=$(X),kt=Rt?Rt.prototype:void 0,Ft=kt?kt.valueOf:void 0;function _(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Fe(){this.__data__=E?E(null):{}}function He(t){return this.has(t)&&delete this.__data__[t]}function Le(t){var e=this.__data__;if(E){var r=e[t];return r===ut?void 0:r}return y.call(e,t)?e[t]:void 0}function Ue(t){var e=this.__data__;return E?e[t]!==void 0:y.call(e,t)}function Je(t,e){var r=this.__data__;return r[t]=E&&e===void 0?ut:e,this}_.prototype.clear=Fe;_.prototype.delete=He;_.prototype.get=Le;_.prototype.has=Ue;_.prototype.set=Je;function h(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function We(){this.__data__=[]}function qe(t){var e=this.__data__,r=M(e,t);if(r<0)return!1;var n=e.length-1;return r==n?e.pop():Ne.call(e,r,1),!0}function Ye(t){var e=this.__data__,r=M(e,t);return r<0?void 0:e[r][1]}function Xe(t){return M(this.__data__,t)>-1}function Ze(t,e){var r=this.__data__,n=M(r,t);return n<0?r.push([t,e]):r[n][1]=e,this}h.prototype.clear=We;h.prototype.delete=qe;h.prototype.get=Ye;h.prototype.has=Xe;h.prototype.set=Ze;function j(t){var e=-1,r=t?t.length:0;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Qe(){this.__data__={hash:new _,map:new(A||h),string:new _}}function ze(t){return R(this,t).delete(t)}function tr(t){return R(this,t).get(t)}function er(t){return R(this,t).has(t)}function rr(t,e){return R(this,t).set(t,e),this}j.prototype.clear=Qe;j.prototype.delete=ze;j.prototype.get=tr;j.prototype.has=er;j.prototype.set=rr;function O(t){this.__data__=new h(t)}function nr(){this.__data__=new h}function or(t){return this.__data__.delete(t)}function ar(t){return this.__data__.get(t)}function ir(t){return this.__data__.has(t)}function sr(t,e){var r=this.__data__;if(r instanceof h){var n=r.__data__;if(!A||n.length<pe-1)return n.push([t,e]),this;r=this.__data__=new j(n)}return r.set(t,e),this}O.prototype.clear=nr;O.prototype.delete=or;O.prototype.get=ar;O.prototype.has=ir;O.prototype.set=sr;function cr(t,e){var r=z(t)||Pr(t)?we(t.length,String):[],n=r.length,o=!!n;for(var c in t)(e||y.call(t,c))&&!(o&&(c=="length"||Ar(c,n)))&&r.push(c);return r}function Ht(t,e,r){var n=t[e];(!(y.call(t,e)&&Wt(n,r))||r===void 0&&!(e in t))&&(t[e]=r)}function M(t,e){for(var r=t.length;r--;)if(Wt(t[r][0],e))return r;return-1}function ur(t,e){return t&&Lt(e,tt(e),t)}function Z(t,e,r,n,o,c,f){var s;if(n&&(s=c?n(t,o,c,f):n(t)),s!==void 0)return s;if(!B(t))return t;var l=z(t);if(l){if(s=xr(t),!e)return jr(t,s)}else{var p=m(t),u=p==F||p==dt;if(Nr(t))return gr(t,e);if(p==H||p==k||u&&!c){if(Pt(t))return c?t:{};if(s=wr(u?{}:t),!e)return Or(t,ur(s,t))}else{if(!a[p])return c?t:{};s=Tr(t,p,Z,e)}}f||(f=new O);var i=f.get(t);if(i)return i;if(f.set(t,s),!l)var g=r?Sr(t):tt(t);return Se(g||t,function(b,I){g&&(I=b,b=t[I]),Ht(s,I,Z(b,e,r,n,I,t,f))}),s}function lr(t){return B(t)?Pe(t):{}}function fr(t,e,r){var n=e(t);return z(t)?n:xe(n,r(t))}function pr(t){return V.call(t)}function dr(t){if(!B(t)||Cr(t))return!1;var e=Yt(t)||Pt(t)?Ce:be;return e.test($(t))}function hr(t){if(!Jt(t))return Ve(t);var e=[];for(var r in Object(t))y.call(t,r)&&r!="constructor"&&e.push(r);return e}function gr(t,e){if(e)return t.slice();var r=new t.constructor(t.length);return t.copy(r),r}function Q(t){var e=new t.constructor(t.byteLength);return new Bt(e).set(new Bt(t)),e}function yr(t,e){var r=e?Q(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}function br(t,e,r){var n=e?r(Dt(t),!0):Dt(t);return It(n,je,new t.constructor)}function _r(t){var e=new t.constructor(t.source,ye.exec(t));return e.lastIndex=t.lastIndex,e}function mr(t,e,r){var n=e?r(Nt(t),!0):Nt(t);return It(n,Oe,new t.constructor)}function $r(t){return Ft?Object(Ft.call(t)):{}}function vr(t,e){var r=e?Q(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}function jr(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}function Lt(t,e,r,n){r||(r={});for(var o=-1,c=e.length;++o<c;){var f=e[o],s=n?n(r[f],t[f],f,r,t):void 0;Ht(r,f,s===void 0?t[f]:s)}return r}function Or(t,e){return Lt(t,Ut(t),e)}function Sr(t){return fr(t,tt,Ut)}function R(t,e){var r=t.__data__;return Er(e)?r[typeof e=="string"?"string":"hash"]:r.map}function S(t,e){var r=Te(t,e);return dr(r)?r:void 0}var Ut=Gt?U(Gt,Object):Mr,m=pr;(W&&m(new W(new ArrayBuffer(1)))!=N||A&&m(new A)!=P||q&&m(q.resolve())!=gt||Y&&m(new Y)!=D||X&&m(new X)!=L)&&(m=function(t){var e=V.call(t),r=e==H?t.constructor:void 0,n=r?$(r):void 0;if(n)switch(n){case Me:return N;case Re:return P;case Be:return gt;case Ge:return D;case ke:return L}return e});function xr(t){var e=t.length,r=t.constructor(e);return e&&typeof t[0]=="string"&&y.call(t,"index")&&(r.index=t.index,r.input=t.input),r}function wr(t){return typeof t.constructor=="function"&&!Jt(t)?lr(Ie(t)):{}}function Tr(t,e,r,n){var o=t.constructor;switch(e){case mt:return Q(t);case ft:case pt:return new o(+t);case N:return yr(t,n);case $t:case vt:case jt:case Ot:case St:case xt:case wt:case Tt:case At:return vr(t,n);case P:return br(t,n,r);case ht:case bt:return new o(t);case yt:return _r(t);case D:return mr(t,n,r);case _t:return $r(t)}}function Ar(t,e){return e=e==null?lt:e,!!e&&(typeof t=="number"||_e.test(t))&&t>-1&&t%1==0&&t<e}function Er(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Cr(t){return!!Kt&&Kt in t}function Jt(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||K;return t===r}function $(t){if(t!=null){try{return Vt.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function Ir(t){return Z(t,!0,!0)}function Wt(t,e){return t===e||t!==t&&e!==e}function Pr(t){return Dr(t)&&y.call(t,"callee")&&(!De.call(t,"callee")||V.call(t)==k)}var z=Array.isArray;function qt(t){return t!=null&&Kr(t.length)&&!Yt(t)}function Dr(t){return Vr(t)&&qt(t)}var Nr=Ke||Rr;function Yt(t){var e=B(t)?V.call(t):"";return e==F||e==dt}function Kr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=lt}function B(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Vr(t){return!!t&&typeof t=="object"}function tt(t){return qt(t)?cr(t):hr(t)}function Mr(){return[]}function Rr(){return!1}x.exports=Ir});var te=it((en,zt)=>{var Br="[object Object]";function Gr(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(r){}return e}function kr(t,e){return function(r){return t(e(r))}}var Fr=Function.prototype,Zt=Object.prototype,Qt=Fr.toString,Hr=Zt.hasOwnProperty,Lr=Qt.call(Object),Ur=Zt.toString,Jr=kr(Object.getPrototypeOf,Object);function Wr(t){return!!t&&typeof t=="object"}function qr(t){if(!Wr(t)||Ur.call(t)!=Br||Gr(t))return!1;var e=Jr(t);if(e===null)return!0;var r=Hr.call(e,"constructor")&&e.constructor;return typeof r=="function"&&r instanceof r&&Qt.call(r)==Lr}zt.exports=qr});var zr={};le(zr,{traverse:()=>Qr,version:()=>Zr});var G=ct(Xt(),1),re=ct(te(),1);function Yr(t){if(t.includes(".")){let 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}var et=Yr;var ee="3.0.12";var Zr=ee;function Qr(t,e){let r={now:!1};function n(o,c,f,s){let l=(0,G.default)(o),p,u=v({depth:-1,path:""},f);if(u.depth+=1,Array.isArray(l))for(let i=0,g=l.length;i<g&&!s.now;i++){let b=u.path?`${u.path}.${i}`:`${i}`;l[i]!==void 0?(u.parent=(0,G.default)(l),u.parentType="array",u.parentKey=et(b),p=n(c(l[i],void 0,T(v({},u),{path:b}),s),c,T(v({},u),{path:b}),s),Number.isNaN(p)&&i<l.length?(l.splice(i,1),i-=1):l[i]=p):l.splice(i,1)}else if((0,re.default)(l))for(let i in l){if(s.now&&i!=null)break;let g=u.path?`${u.path}.${i}`:i;u.depth===0&&i!=null&&(u.topmostKey=i),u.parent=(0,G.default)(l),u.parentType="object",u.parentKey=et(g),p=n(c(i,l[i],T(v({},u),{path:g}),s),c,T(v({},u),{path:g}),s),Number.isNaN(p)?delete l[i]:l[i]=p}return l}return n(t,e,{},r)}return fe(zr);})();
11
11
  /**
12
12
  * @name ast-monkey-util
13
13
  * @fileoverview Utility library of AST helper functions
14
- * @version 2.0.6
14
+ * @version 2.0.12
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.6",Object.defineProperty(t,"__esModule",{value:!0})}));
18
+ */
@@ -1,6 +1,7 @@
1
1
  // Quick Take
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { traverse } from "../dist/ast-monkey-traverse.esm.js";
5
6
 
6
7
  const paths = [];
@@ -24,7 +25,7 @@ const source = {
24
25
  traverse(source, (key, val, innerObj) => {
25
26
  // if currently an object is traversed, you get both "key" and "val"
26
27
  // if it's array, only "key" is present, "val" is undefined
27
- const current = val !== undefined ? val : key;
28
+ let current = val !== undefined ? val : key;
28
29
  if (
29
30
  // it's object (not array)
30
31
  val !== undefined &&
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { strict as assert } from "assert";
4
4
  import op from "object-path";
5
+
5
6
  import { traverse } from "../dist/ast-monkey-traverse.esm.js";
6
7
 
7
8
  const input = { a: "1", b: [{ c: "2" }] };
@@ -10,7 +11,7 @@ const result1 = [];
10
11
 
11
12
  // the full traversal would look like this:
12
13
  traverse(input, (key1, val1, innerObj) => {
13
- const current = val1 !== undefined ? val1 : key1;
14
+ let current = val1 !== undefined ? val1 : key1;
14
15
  result1.push(innerObj.path);
15
16
  return current;
16
17
  });
@@ -1,6 +1,7 @@
1
1
  // Stop
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { traverse } from "../dist/ast-monkey-traverse.esm.js";
5
6
 
6
7
  const input = { a: "1", b: { c: "2" } };
@@ -8,7 +9,7 @@ const result1 = [];
8
9
 
9
10
  // the full traversal would look like this:
10
11
  traverse(input, (key1, val1, innerObj) => {
11
- const current = val1 !== undefined ? val1 : key1;
12
+ let current = val1 !== undefined ? val1 : key1;
12
13
  result1.push(innerObj.path);
13
14
  return current;
14
15
  });
@@ -18,7 +19,7 @@ assert.deepEqual(result1, ["a", "b", "b.c"]);
18
19
  // path, how object-path would reference it)
19
20
  const result2 = [];
20
21
  traverse(input, (key1, val1, innerObj, stop) => {
21
- const current = val1 !== undefined ? val1 : key1;
22
+ let current = val1 !== undefined ? val1 : key1;
22
23
  result2.push(innerObj.path);
23
24
  if (innerObj.path === "b") {
24
25
  stop.now = true; // <---------------- !!!!!!!!!!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ast-monkey-traverse",
3
- "version": "3.0.6",
3
+ "version": "3.0.12",
4
4
  "description": "Utility library to traverse AST",
5
5
  "keywords": [
6
6
  "ast",
@@ -44,100 +44,47 @@
44
44
  },
45
45
  "types": "types/index.d.ts",
46
46
  "scripts": {
47
- "build": "rollup -c",
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",
52
- "dev": "rollup -c --dev",
53
- "devunittest": "npm run dev && tap --only -R 'base'",
54
- "format": "npm run lect && npm run prettier && npm run lint",
55
- "lect": "lect",
56
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
57
- "perf": "node perf/check",
58
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
59
- "republish": "npm publish || :",
60
- "tap": "tap",
61
- "pretest": "npm run build",
62
- "test": "npm run test:ci && npm run perf",
63
- "test:ci": "npm run unittest && npm run test:examples && npm run format",
64
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
65
- "tsc": "tsc",
66
- "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
47
+ "build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
48
+ "dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
49
+ "devtest": "c8 yarn run unit && yarn run examples && yarn run lint",
50
+ "dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
51
+ "examples": "node '../../ops/scripts/run-examples.js'",
52
+ "lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
53
+ "letspublish": "yarn publish || :",
54
+ "lint": "eslint . --fix",
55
+ "perf": "node perf/check.js",
56
+ "prepare": "echo 'ready'",
57
+ "prettier": "prettier",
58
+ "prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
59
+ "pretest": "yarn run lect && yarn run build",
60
+ "test": "yarn run devtest",
61
+ "unit": "uvu test"
67
62
  },
68
- "tap": {
69
- "check-coverage": false,
70
- "node-arg": [
71
- "--no-warnings",
72
- "--experimental-loader",
73
- "@istanbuljs/esm-loader-hook"
63
+ "engines": {
64
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
65
+ },
66
+ "c8": {
67
+ "check-coverage": true,
68
+ "exclude": [
69
+ "**/test/**/*.*"
74
70
  ],
75
- "timeout": 0
71
+ "lines": 100
76
72
  },
77
73
  "lect": {
78
74
  "licence": {
79
75
  "extras": [
80
76
  ""
81
77
  ]
82
- },
83
- "req": "{ traverse }",
84
- "various": {
85
- "devDependencies": [
86
- "@types/lodash.isplainobject",
87
- "lodash.isequal",
88
- "object-path"
89
- ]
90
78
  }
91
79
  },
92
80
  "dependencies": {
93
- "@babel/runtime": "^7.16.3",
94
- "ast-monkey-util": "^2.0.6",
81
+ "ast-monkey-util": "^2.0.12",
95
82
  "lodash.clonedeep": "^4.5.0",
96
83
  "lodash.isplainobject": "^4.0.6"
97
84
  },
98
85
  "devDependencies": {
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",
111
- "@istanbuljs/esm-loader-hook": "^0.1.2",
112
- "@rollup/plugin-babel": "^5.3.0",
113
- "@rollup/plugin-commonjs": "^21.0.1",
114
- "@rollup/plugin-json": "^4.1.0",
115
- "@rollup/plugin-node-resolve": "^13.0.6",
116
- "@rollup/plugin-strip": "^2.1.0",
117
- "@rollup/plugin-typescript": "^8.3.0",
118
86
  "@types/lodash.clonedeep": "^4.5.6",
119
87
  "@types/lodash.isplainobject": "^4.0.6",
120
- "@types/node": "^16.11.9",
121
- "@types/tap": "^15.0.5",
122
- "@typescript-eslint/eslint-plugin": "^5.4.0",
123
- "@typescript-eslint/parser": "^5.4.0",
124
- "core-js": "^3.19.1",
125
- "cross-env": "^7.0.3",
126
- "eslint": "^8.3.0",
127
- "lect": "^0.18.6",
128
- "lodash.isequal": "^4.5.0",
129
- "object-path": "^0.11.8",
130
- "rollup": "^2.60.0",
131
- "rollup-plugin-ascii": "^0.0.3",
132
- "rollup-plugin-banner": "^0.2.1",
133
- "rollup-plugin-cleanup": "^3.2.1",
134
- "rollup-plugin-dts": "^4.0.1",
135
- "rollup-plugin-terser": "^7.0.2",
136
- "tap": "^15.1.2",
137
- "tslib": "^2.3.1",
138
- "typescript": "^4.5.2"
139
- },
140
- "engines": {
141
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
88
+ "lodash.isequal": "^4.5.0"
142
89
  }
143
90
  }
package/types/index.d.ts CHANGED
@@ -1,16 +1,21 @@
1
1
  declare const version: string;
2
2
  interface Stop {
3
- now: boolean;
3
+ now: boolean;
4
4
  }
5
5
  interface InnerObj {
6
- depth: number;
7
- path: string;
8
- topmostKey: string;
9
- parent: any;
10
- parentType: string;
11
- parentKey: string | null;
6
+ depth: number;
7
+ path: string;
8
+ topmostKey: string;
9
+ parent: any;
10
+ parentType: string;
11
+ parentKey: string | null;
12
12
  }
13
- declare type Callback = (key: string, val: any, innerObj: InnerObj, stop: Stop) => any;
13
+ declare type Callback = (
14
+ key: string,
15
+ val: any,
16
+ innerObj: InnerObj,
17
+ stop: Stop
18
+ ) => any;
14
19
  /**
15
20
  * Utility library to traverse AST
16
21
  */
package/examples/api.json DELETED
@@ -1 +0,0 @@
1
- {"_quickTake.js":{"title":"Quick Take","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; traverse &#x7D; from \"ast-monkey-traverse\";\n\nconst paths = [];\nconst source = &#x7B;\n a: &#x7B;\n foo: &#x7B;\n bar: [\n &#x7B;\n foo: \"c\",\n &#x7D;,\n ],\n d: &#x7B;\n e: &#x7B;\n foo: \"f\",\n &#x7D;,\n &#x7D;,\n &#x7D;,\n &#x7D;,\n&#x7D;;\n\ntraverse(source, (key, val, innerObj) => &#x7B;\n // if currently an object is traversed, you get both \"key\" and \"val\"\n // if it's array, only \"key\" is present, \"val\" is undefined\n const current = val !== undefined ? val : key;\n if (\n // it's object (not array)\n val !== undefined &&\n // and has the key we need\n key === \"foo\"\n ) &#x7B;\n // push the path to array in the outer scope\n paths.push(innerObj.path);\n &#x7D;\n return current;\n&#x7D;);\n\n// notice object-path notation \"a.foo.bar.0.foo\" - array segments use dots too:\nassert.deepEqual(paths, [\"a.foo\", \"a.foo.bar.0.foo\", \"a.foo.d.e.foo\"]);"},"compatible-with-object-path.js":{"title":"Compatible With `object-path`","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport op from \"object-path\";\nimport &#x7B; traverse &#x7D; from \"ast-monkey-traverse\";\n\nconst input = &#x7B; a: \"1\", b: [&#x7B; c: \"2\" &#x7D;] &#x7D;;\nObject.freeze(input); // let's freeze it, just for fun\nconst result1 = [];\n\n// the full traversal would look like this:\ntraverse(input, (key1, val1, innerObj) => &#x7B;\n const current = val1 !== undefined ? val1 : key1;\n result1.push(innerObj.path);\n return current;\n&#x7D;);\n\n// notice the object-path notation is \"b.0.c\" not \"b[0].c\"\nassert.deepEqual(result1, [\"a\", \"b\", \"b.0\", \"b.0.c\"]);\n\n// each reported path is fully compatible with `object-path` get() method\nassert.deepEqual(op.get(input, \"a\"), \"1\");\nassert.deepEqual(op.get(input, \"b\"), [&#x7B; c: \"2\" &#x7D;]);\nassert.deepEqual(op.get(input, \"b.0\"), &#x7B; c: \"2\" &#x7D;);\nassert.deepEqual(op.get(input, \"b.0.c\"), \"2\");"},"stopping.js":{"title":"Stop","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; traverse &#x7D; from \"ast-monkey-traverse\";\n\nconst input = &#x7B; a: \"1\", b: &#x7B; c: \"2\" &#x7D; &#x7D;;\nconst result1 = [];\n\n// the full traversal would look like this:\ntraverse(input, (key1, val1, innerObj) => &#x7B;\n const current = val1 !== undefined ? val1 : key1;\n result1.push(innerObj.path);\n return current;\n&#x7D;);\nassert.deepEqual(result1, [\"a\", \"b\", \"b.c\"]);\n\n// now let's stop the traversal at path \"b\" (that's real\n// path, how object-path would reference it)\nconst result2 = [];\ntraverse(input, (key1, val1, innerObj, stop) => &#x7B;\n const current = val1 !== undefined ? val1 : key1;\n result2.push(innerObj.path);\n if (innerObj.path === \"b\") &#x7B;\n stop.now = true; // <---------------- !!!!!!!!!!\n &#x7D;\n return current;\n&#x7D;);\nassert.deepEqual(result2, [\"a\", \"b\"]);"}}