ast-monkey-traverse
Advanced tools
Comparing version
/** | ||
* @name ast-monkey-traverse | ||
* @fileoverview Utility library to traverse AST | ||
* @version 3.0.7 | ||
* @version 3.0.10 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -10,66 +10,2 @@ * @license MIT | ||
import clone from 'lodash.clonedeep'; | ||
import isObj from 'lodash.isplainobject'; | ||
import { parent } from 'ast-monkey-util'; | ||
var version$1 = "3.0.7"; | ||
const version = version$1; | ||
function traverse(tree1, cb1) { | ||
const stop2 = { now: false }; | ||
function traverseInner(treeOriginal, callback, originalInnerObj, stop) { | ||
const tree = clone(treeOriginal); | ||
let res; | ||
const innerObj = { depth: -1, path: "", ...originalInnerObj }; | ||
innerObj.depth += 1; | ||
if (Array.isArray(tree)) { | ||
for (let i = 0, len = tree.length; i < len; i++) { | ||
if (stop.now) { | ||
break; | ||
} | ||
const path = innerObj.path ? `${innerObj.path}.${i}` : `${i}`; | ||
if (tree[i] !== undefined) { | ||
innerObj.parent = clone(tree); | ||
innerObj.parentType = "array"; | ||
innerObj.parentKey = parent(path); | ||
res = traverseInner(callback(tree[i], undefined, { ...innerObj, path }, stop), callback, { ...innerObj, path }, stop); | ||
if (Number.isNaN(res) && i < tree.length) { | ||
tree.splice(i, 1); | ||
i -= 1; | ||
} | ||
else { | ||
tree[i] = res; | ||
} | ||
} | ||
else { | ||
tree.splice(i, 1); | ||
} | ||
} | ||
} | ||
else if (isObj(tree)) { | ||
for (const key in tree) { | ||
if (stop.now && key != null) { | ||
break; | ||
} | ||
const path = innerObj.path ? `${innerObj.path}.${key}` : key; | ||
if (innerObj.depth === 0 && key != null) { | ||
innerObj.topmostKey = key; | ||
} | ||
innerObj.parent = clone(tree); | ||
innerObj.parentType = "object"; | ||
innerObj.parentKey = parent(path); | ||
res = traverseInner(callback(key, tree[key], { ...innerObj, path }, stop), callback, { ...innerObj, path }, stop); | ||
if (Number.isNaN(res)) { | ||
delete tree[key]; | ||
} | ||
else { | ||
tree[key] = res; | ||
} | ||
} | ||
} | ||
return tree; | ||
} | ||
return traverseInner(tree1, cb1, {}, stop2); | ||
} | ||
export { traverse, version }; | ||
import p from"lodash.clonedeep";import g from"lodash.isplainobject";import{parent as m}from"ast-monkey-util";var u="3.0.10";var k=u;function D(y,c){let $={now:!1};function a(b,l,d,r){let n=p(b),s,t={depth:-1,path:"",...d};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,{},$)}export{D as traverse,k as version}; |
/** | ||
* @name ast-monkey-traverse | ||
* @fileoverview Utility library to traverse AST | ||
* @version 3.0.7 | ||
* @version 3.0.10 | ||
* @author Roy Revelt, Codsen Ltd | ||
@@ -10,10 +10,10 @@ * @license MIT | ||
!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}; | ||
var astMonkeyTraverse=(()=>{var re=Object.create;var x=Object.defineProperty,oe=Object.defineProperties,ae=Object.getOwnPropertyDescriptor,ie=Object.getOwnPropertyDescriptors,se=Object.getOwnPropertyNames,nt=Object.getOwnPropertySymbols,ce=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var ot=(t,e,n)=>e in t?x(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,v=(t,e)=>{for(var n in e||(e={}))rt.call(e,n)&&ot(t,n,e[n]);if(nt)for(var n of nt(e))ue.call(e,n)&&ot(t,n,e[n]);return t},w=(t,e)=>oe(t,ie(e)),at=t=>x(t,"__esModule",{value:!0});var it=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),le=(t,e)=>{for(var n in e)x(t,n,{get:e[n],enumerable:!0})},st=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of se(e))!rt.call(t,o)&&(n||o!=="default")&&x(t,o,{get:()=>e[o],enumerable:!(r=ae(e,o))||r.enumerable});return t},ct=(t,e)=>st(at(x(t!=null?re(ce(t)):{},"default",!e&&t&&t.__esModule?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t),fe=(t=>(e,n)=>t&&t.get(e)||(n=st(at({}),e,1),t&&t.set(e,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var Xt=it((C,T)=>{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]",bt="[object RegExp]",D="[object Set]",yt="[object String]",_t="[object Symbol]",L="[object WeakMap]",mt="[object ArrayBuffer]",N="[object DataView]",$t="[object Float32Array]",vt="[object Float64Array]",Ot="[object Int8Array]",jt="[object Int16Array]",St="[object Int32Array]",Tt="[object Uint8Array]",xt="[object Uint8ClampedArray]",wt="[object Uint16Array]",At="[object Uint32Array]",ge=/[\\^$.*+?()[\]{}|]/g,be=/\w*$/,ye=/^\[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[Ot]=a[jt]=a[St]=a[P]=a[ht]=a[H]=a[bt]=a[D]=a[yt]=a[_t]=a[Tt]=a[xt]=a[wt]=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 T=="object"&&T&&!T.nodeType&&T,ve=Ct&&Ct.exports===Et;function Oe(t,e){return t.set(e[0],e[1]),t}function je(t,e){return t.add(e),t}function Se(t,e){for(var n=-1,r=t?t.length:0;++n<r&&e(t[n],n,t)!==!1;);return t}function Te(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}function It(t,e,n,r){var o=-1,c=t?t.length:0;for(r&&c&&(n=t[++o]);++o<c;)n=e(n,t[o],o,t);return n}function xe(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}function we(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(n){}return e}function Dt(t){var e=-1,n=Array(t.size);return t.forEach(function(r,o){n[++e]=[o,r]}),n}function U(t,e){return function(n){return t(e(n))}}function Nt(t){var e=-1,n=Array(t.size);return t.forEach(function(r){n[++e]=r}),n}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,b=K.hasOwnProperty,V=K.toString,Ce=RegExp("^"+Vt.call(b).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,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[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 n=e[t];return n===ut?void 0:n}return b.call(e,t)?e[t]:void 0}function Ue(t){var e=this.__data__;return E?e[t]!==void 0:b.call(e,t)}function Je(t,e){var n=this.__data__;return n[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,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function We(){this.__data__=[]}function qe(t){var e=this.__data__,n=M(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():Ne.call(e,n,1),!0}function Ye(t){var e=this.__data__,n=M(e,t);return n<0?void 0:e[n][1]}function Xe(t){return M(this.__data__,t)>-1}function Ze(t,e){var n=this.__data__,r=M(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}h.prototype.clear=We;h.prototype.delete=qe;h.prototype.get=Ye;h.prototype.has=Xe;h.prototype.set=Ze;function O(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Qe(){this.__data__={hash:new _,map:new(A||h),string:new _}}function ze(t){return R(this,t).delete(t)}function tn(t){return R(this,t).get(t)}function en(t){return R(this,t).has(t)}function nn(t,e){return R(this,t).set(t,e),this}O.prototype.clear=Qe;O.prototype.delete=ze;O.prototype.get=tn;O.prototype.has=en;O.prototype.set=nn;function j(t){this.__data__=new h(t)}function rn(){this.__data__=new h}function on(t){return this.__data__.delete(t)}function an(t){return this.__data__.get(t)}function sn(t){return this.__data__.has(t)}function cn(t,e){var n=this.__data__;if(n instanceof h){var r=n.__data__;if(!A||r.length<pe-1)return r.push([t,e]),this;n=this.__data__=new O(r)}return n.set(t,e),this}j.prototype.clear=rn;j.prototype.delete=on;j.prototype.get=an;j.prototype.has=sn;j.prototype.set=cn;function un(t,e){var n=z(t)||Dn(t)?xe(t.length,String):[],r=n.length,o=!!r;for(var c in t)(e||b.call(t,c))&&!(o&&(c=="length"||En(c,r)))&&n.push(c);return n}function Ht(t,e,n){var r=t[e];(!(b.call(t,e)&&Wt(r,n))||n===void 0&&!(e in t))&&(t[e]=n)}function M(t,e){for(var n=t.length;n--;)if(Wt(t[n][0],e))return n;return-1}function ln(t,e){return t&&Lt(e,tt(e),t)}function Z(t,e,n,r,o,c,f){var s;if(r&&(s=c?r(t,o,c,f):r(t)),s!==void 0)return s;if(!B(t))return t;var l=z(t);if(l){if(s=xn(t),!e)return jn(t,s)}else{var p=m(t),u=p==F||p==dt;if(Kn(t))return bn(t,e);if(p==H||p==k||u&&!c){if(Pt(t))return c?t:{};if(s=wn(u?{}:t),!e)return Sn(t,ln(s,t))}else{if(!a[p])return c?t:{};s=An(t,p,Z,e)}}f||(f=new j);var i=f.get(t);if(i)return i;if(f.set(t,s),!l)var g=n?Tn(t):tt(t);return Se(g||t,function(y,I){g&&(I=y,y=t[I]),Ht(s,I,Z(y,e,n,r,I,t,f))}),s}function fn(t){return B(t)?Pe(t):{}}function pn(t,e,n){var r=e(t);return z(t)?r:Te(r,n(t))}function dn(t){return V.call(t)}function hn(t){if(!B(t)||In(t))return!1;var e=Yt(t)||Pt(t)?Ce:ye;return e.test($(t))}function gn(t){if(!Jt(t))return Ve(t);var e=[];for(var n in Object(t))b.call(t,n)&&n!="constructor"&&e.push(n);return e}function bn(t,e){if(e)return t.slice();var n=new t.constructor(t.length);return t.copy(n),n}function Q(t){var e=new t.constructor(t.byteLength);return new Bt(e).set(new Bt(t)),e}function yn(t,e){var n=e?Q(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}function _n(t,e,n){var r=e?n(Dt(t),!0):Dt(t);return It(r,Oe,new t.constructor)}function mn(t){var e=new t.constructor(t.source,be.exec(t));return e.lastIndex=t.lastIndex,e}function $n(t,e,n){var r=e?n(Nt(t),!0):Nt(t);return It(r,je,new t.constructor)}function vn(t){return Ft?Object(Ft.call(t)):{}}function On(t,e){var n=e?Q(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}function jn(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}function Lt(t,e,n,r){n||(n={});for(var o=-1,c=e.length;++o<c;){var f=e[o],s=r?r(n[f],t[f],f,n,t):void 0;Ht(n,f,s===void 0?t[f]:s)}return n}function Sn(t,e){return Lt(t,Ut(t),e)}function Tn(t){return pn(t,tt,Ut)}function R(t,e){var n=t.__data__;return Cn(e)?n[typeof e=="string"?"string":"hash"]:n.map}function S(t,e){var n=we(t,e);return hn(n)?n:void 0}var Ut=Gt?U(Gt,Object):Rn,m=dn;(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),n=e==H?t.constructor:void 0,r=n?$(n):void 0;if(r)switch(r){case Me:return N;case Re:return P;case Be:return gt;case Ge:return D;case ke:return L}return e});function xn(t){var e=t.length,n=t.constructor(e);return e&&typeof t[0]=="string"&&b.call(t,"index")&&(n.index=t.index,n.input=t.input),n}function wn(t){return typeof t.constructor=="function"&&!Jt(t)?fn(Ie(t)):{}}function An(t,e,n,r){var o=t.constructor;switch(e){case mt:return Q(t);case ft:case pt:return new o(+t);case N:return yn(t,r);case $t:case vt:case Ot:case jt:case St:case Tt:case xt:case wt:case At:return On(t,r);case P:return _n(t,r,n);case ht:case yt:return new o(t);case bt:return mn(t);case D:return $n(t,r,n);case _t:return vn(t)}}function En(t,e){return e=e==null?lt:e,!!e&&(typeof t=="number"||_e.test(t))&&t>-1&&t%1==0&&t<e}function Cn(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function In(t){return!!Kt&&Kt in t}function Jt(t){var e=t&&t.constructor,n=typeof e=="function"&&e.prototype||K;return t===n}function $(t){if(t!=null){try{return Vt.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function Pn(t){return Z(t,!0,!0)}function Wt(t,e){return t===e||t!==t&&e!==e}function Dn(t){return Nn(t)&&b.call(t,"callee")&&(!De.call(t,"callee")||V.call(t)==k)}var z=Array.isArray;function qt(t){return t!=null&&Vn(t.length)&&!Yt(t)}function Nn(t){return Mn(t)&&qt(t)}var Kn=Ke||Bn;function Yt(t){var e=B(t)?V.call(t):"";return e==F||e==dt}function Vn(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 Mn(t){return!!t&&typeof t=="object"}function tt(t){return qt(t)?un(t):gn(t)}function Rn(){return[]}function Bn(){return!1}T.exports=Pn});var te=it((nr,zt)=>{var Gn="[object Object]";function kn(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch(n){}return e}function Fn(t,e){return function(n){return t(e(n))}}var Hn=Function.prototype,Zt=Object.prototype,Qt=Hn.toString,Ln=Zt.hasOwnProperty,Un=Qt.call(Object),Jn=Zt.toString,Wn=Fn(Object.getPrototypeOf,Object);function qn(t){return!!t&&typeof t=="object"}function Yn(t){if(!qn(t)||Jn.call(t)!=Gn||kn(t))return!1;var e=Wn(t);if(e===null)return!0;var n=Ln.call(e,"constructor")&&e.constructor;return typeof n=="function"&&n instanceof n&&Qt.call(n)==Un}zt.exports=Yn});var tr={};le(tr,{traverse:()=>zn,version:()=>Qn});var G=ct(Xt(),1),ne=ct(te(),1);function Xn(t){if(t.includes(".")){let e=t.lastIndexOf(".");if(!t.slice(0,e).includes("."))return t.slice(0,e);for(let n=e-1;n--;)if(t[n]===".")return t.slice(n+1,e)}return null}var et=Xn;var ee="3.0.10";var Qn=ee;function zn(t,e){let n={now:!1};function r(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 y=u.path?`${u.path}.${i}`:`${i}`;l[i]!==void 0?(u.parent=(0,G.default)(l),u.parentType="array",u.parentKey=et(y),p=r(c(l[i],void 0,w(v({},u),{path:y}),s),c,w(v({},u),{path:y}),s),Number.isNaN(p)&&i<l.length?(l.splice(i,1),i-=1):l[i]=p):l.splice(i,1)}else if((0,ne.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=r(c(i,l[i],w(v({},u),{path:g}),s),c,w(v({},u),{path:g}),s),Number.isNaN(p)?delete l[i]:l[i]=p}return l}return r(t,e,{},n)}return fe(tr);})(); | ||
/** | ||
* @name ast-monkey-util | ||
* @fileoverview Utility library of AST helper functions | ||
* @version 2.0.7 | ||
* @version 2.0.10 | ||
* @author Roy Revelt, Codsen Ltd | ||
* @license MIT | ||
* {@link https://codsen.com/os/ast-monkey-util/} | ||
*/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})})); | ||
*/ |
// Quick Take | ||
import { strict as assert } from "assert"; | ||
import { traverse } from "../dist/ast-monkey-traverse.esm.js"; | ||
@@ -27,3 +28,3 @@ | ||
// if it's array, only "key" is present, "val" is undefined | ||
const current = val !== undefined ? val : key; | ||
let current = val !== undefined ? val : key; | ||
if ( | ||
@@ -30,0 +31,0 @@ // it's object (not array) |
@@ -5,2 +5,3 @@ // Compatible With `object-path` | ||
import op from "object-path"; | ||
import { traverse } from "../dist/ast-monkey-traverse.esm.js"; | ||
@@ -14,3 +15,3 @@ | ||
traverse(input, (key1, val1, innerObj) => { | ||
const current = val1 !== undefined ? val1 : key1; | ||
let current = val1 !== undefined ? val1 : key1; | ||
result1.push(innerObj.path); | ||
@@ -17,0 +18,0 @@ return current; |
// Stop | ||
import { strict as assert } from "assert"; | ||
import { traverse } from "../dist/ast-monkey-traverse.esm.js"; | ||
@@ -11,3 +12,3 @@ | ||
traverse(input, (key1, val1, innerObj) => { | ||
const current = val1 !== undefined ? val1 : key1; | ||
let current = val1 !== undefined ? val1 : key1; | ||
result1.push(innerObj.path); | ||
@@ -22,3 +23,3 @@ return current; | ||
traverse(input, (key1, val1, innerObj, stop) => { | ||
const current = val1 !== undefined ? val1 : key1; | ||
let current = val1 !== undefined ? val1 : key1; | ||
result2.push(innerObj.path); | ||
@@ -25,0 +26,0 @@ if (innerObj.path === "b") { |
102
package.json
{ | ||
"name": "ast-monkey-traverse", | ||
"version": "3.0.7", | ||
"version": "3.0.10", | ||
"description": "Utility library to traverse AST", | ||
@@ -47,31 +47,24 @@ "keywords": [ | ||
"scripts": { | ||
"build": "rollup -c", | ||
"build:esbuild": "node '../../scripts/esbuild.js'", | ||
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'", | ||
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent", | ||
"clean_types": "../../scripts/cleanTypes.js", | ||
"dev": "rollup -c --dev", | ||
"devunittest": "npm run dev && tap --only -R 'base'", | ||
"format": "npm run lect && npm run prettier && npm run lint", | ||
"lect": "lect", | ||
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet", | ||
"perf": "node perf/check", | ||
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent", | ||
"republish": "npm publish || :", | ||
"tap": "tap", | ||
"pretest": "npm run build", | ||
"test": "npm run test:ci && npm run perf", | ||
"test:ci": "npm run unittest && npm run test:examples && npm run format", | ||
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier", | ||
"tsc": "tsc", | ||
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit" | ||
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts", | ||
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts", | ||
"dts": "rollup -c", | ||
"examples": "node '../../ops/scripts/run-examples.js'", | ||
"lect": "node '../../ops/lect/lect.js'", | ||
"letspublish": "yarn publish || :", | ||
"lint": "eslint . --fix", | ||
"perf": "node perf/check.js", | ||
"prepare": "echo 'ready'", | ||
"pretest": "yarn run lect && yarn run build", | ||
"test": "c8 yarn run unit && yarn run examples && yarn run lint", | ||
"unit": "uvu test" | ||
}, | ||
"tap": { | ||
"check-coverage": false, | ||
"node-arg": [ | ||
"--no-warnings", | ||
"--experimental-loader", | ||
"@istanbuljs/esm-loader-hook" | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"c8": { | ||
"check-coverage": true, | ||
"exclude": [ | ||
"**/test/**/*.*" | ||
], | ||
"timeout": 0 | ||
"lines": 100 | ||
}, | ||
@@ -83,15 +76,6 @@ "lect": { | ||
] | ||
}, | ||
"req": "{ traverse }", | ||
"various": { | ||
"devDependencies": [ | ||
"@types/lodash.isplainobject", | ||
"lodash.isequal", | ||
"object-path" | ||
] | ||
} | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.16.3", | ||
"ast-monkey-util": "^2.0.7", | ||
"ast-monkey-util": "^2.0.10", | ||
"lodash.clonedeep": "^4.5.0", | ||
@@ -101,46 +85,6 @@ "lodash.isplainobject": "^4.0.6" | ||
"devDependencies": { | ||
"@babel/cli": "^7.16.0", | ||
"@babel/core": "^7.16.0", | ||
"@babel/node": "^7.16.0", | ||
"@babel/plugin-external-helpers": "^7.16.0", | ||
"@babel/plugin-proposal-class-properties": "^7.16.0", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.16.0", | ||
"@babel/plugin-proposal-optional-chaining": "^7.16.0", | ||
"@babel/plugin-transform-runtime": "^7.16.4", | ||
"@babel/preset-env": "^7.16.4", | ||
"@babel/preset-typescript": "^7.16.0", | ||
"@babel/register": "^7.16.0", | ||
"@istanbuljs/esm-loader-hook": "^0.1.2", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^13.0.6", | ||
"@rollup/plugin-strip": "^2.1.0", | ||
"@rollup/plugin-typescript": "^8.3.0", | ||
"@types/lodash.clonedeep": "^4.5.6", | ||
"@types/lodash.isplainobject": "^4.0.6", | ||
"@types/node": "^16.11.10", | ||
"@types/tap": "^15.0.5", | ||
"@typescript-eslint/eslint-plugin": "^5.5.0", | ||
"@typescript-eslint/parser": "^5.5.0", | ||
"core-js": "^3.19.2", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.3.0", | ||
"lect": "^0.18.7", | ||
"lodash.isequal": "^4.5.0", | ||
"object-path": "^0.11.8", | ||
"rollup": "^2.60.1", | ||
"rollup-plugin-ascii": "^0.0.3", | ||
"rollup-plugin-banner": "^0.2.1", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-dts": "^4.0.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"tap": "^15.1.5", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.2" | ||
}, | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
"lodash.isequal": "^4.5.0" | ||
} | ||
} |
@@ -41,2 +41,3 @@ # ast-monkey-traverse | ||
import { strict as assert } from "assert"; | ||
import { traverse } from "ast-monkey-traverse"; | ||
@@ -65,3 +66,3 @@ | ||
// if it's array, only "key" is present, "val" is undefined | ||
const current = val !== undefined ? val : key; | ||
let current = val !== undefined ? val : key; | ||
if ( | ||
@@ -85,3 +86,3 @@ // it's object (not array) | ||
Please [visit codsen.com](https://codsen.com/os/ast-monkey-traverse/) for a full description of the API and examples. | ||
Please [visit codsen.com](https://codsen.com/os/ast-monkey-traverse/) for a full description of the API. | ||
@@ -98,2 +99,4 @@ ## Contributing | ||
<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"> | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
3
-25%3
-92.5%99
3.13%25393
-17.86%10
-9.09%172
-23.21%1
Infinity%1
Infinity%- Removed
- Removed
Updated