-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.js
1 lines (1 loc) · 1.37 KB
/
json.js
1
var t=(0,Object.freeze)([]);class e{static ATTRIBUTE=1;static COMPONENT=2;static ELEMENT=3;static FRAGMENT=4;static INTERPOLATION=5;static STATIC=6;get properties(){const{attributes:t}=this;if(t.length){const e={};for(const s of t)s.type<2?e[s.name]=s.value:Object.assign(e,s.value);return e}return null}}var s=(t,e)=>t[e];function i(t,e,...s){const i=(this||JSON).parse(t,...s);return a.call({ids:i,nmsp:e||globalThis},i.pop())}function n(t,...e){const s=[],i=c.call(s,t);return s.push(i),(this||JSON).stringify(s,...e)}function a(i){const{type:n}=i;switch(n){case e.COMPONENT:i.value=i.name.split(".").reduce(s,this.nmsp);case e.ELEMENT:case e.FRAGMENT:return i.attributes=(i.attributes||t).map(a,this),i.children=(i.children||t).map(a,this),i.hasOwnProperty("id")&&(i.id=this.ids[i.id]),Object.setPrototypeOf(i,e.prototype);case e.INTERPOLATION:{const{value:t}=i;return{type:e.INTERPOLATION,value:t&&(t.i||a.call(this,t))}}}return i}function c(t){const{type:s}=t;switch(s){case e.COMPONENT:case e.ELEMENT:case e.FRAGMENT:{const i=new e;if(i.type=s,t.hasOwnProperty("id")){const e=this.indexOf(t.id);i.id=e<0?this.push(t.id)-1:e}const{attributes:n,children:a}=t;return n.length&&(i.attributes=n),a.length&&(i.children=a.map(c,this)),t.name&&(i.name=t.name),i}case e.INTERPOLATION:const{value:i}=t;return{...t,value:i instanceof e?c.call(this,i):{i:i}}}return t}export{i as parse,n as stringify};