@mapl/router 0.8.7 → 0.8.8

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/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@mapl/router","version":"0.8.7","description":"The fastest possible JS router","repository":{"type":"git","url":"git+https://github.com/mapljs/router.git"},"license":"MIT","type":"module","exports":{"./utils":"./utils.js","./path/compiler":"./path/compiler.js","./constants":"./constants.js","./tree/node":"./tree/node.js","./path":"./path/index.js","./method/compiler":"./method/compiler.js","./tree/compiler":"./tree/compiler.js","./method":"./method/index.js"}}
1
+ {"name":"@mapl/router","version":"0.8.8","description":"The fastest possible JS router","repository":{"type":"git","url":"git+https://github.com/mapljs/router.git"},"license":"MIT","type":"module","exports":{"./utils":"./utils.js","./constants":"./constants.js","./path/compiler":"./path/compiler.js","./method":"./method/index.js","./method/compiler":"./method/compiler.js","./tree/compiler":"./tree/compiler.js","./tree/node":"./tree/node.js","./path":"./path/index.js"}}
package/path/compiler.js CHANGED
@@ -1 +1 @@
1
- import{compile}from"../tree/compiler.js";import{isEmptyNode}from"../tree/node.js";export default (router,startIndex)=>{let str=``;for(let i=1;i<router.length;i+=2)str+=(str===``?`if(`:`else if(`)+`p==="`+(startIndex===1?router[i]:router[i].slice(1))+`"){`+router[i+1]+`}`;return str+(isEmptyNode(router[0])?``:`let l=p.length;`+compile(router[0],0,startIndex,``))};
1
+ import{compile}from"../tree/compiler.js";import{isEmptyNode}from"../tree/node.js";export default (router,startIndex)=>{let str=``;if(router.length>1){str=`if(p==="`+(startIndex===1?router[1]:router[1].slice(1))+`"){`+router[2]+`}`;for(let i=3;i<router.length;i+=2)str+=`else if(p==="`+(startIndex===1?router[i]:router[i].slice(1))+`"){`+router[i+1]+`}`}return isEmptyNode(router[0])?str:str+`let l=p.length;`+compile(router[0],0,startIndex,``)};
package/tree/compiler.js CHANGED
@@ -1 +1 @@
1
- export let shouldBoundCheck=node=>node[1]==null&&node[4]!=null;export let compile=(node,paramCount,idx,idxPrefix)=>{let builder=``;let currentIdx=idxPrefix+idx;node[1]==null||(builder+=`if(l===`+currentIdx+`){`+node[1]+`}`);if(node[2]!=null)for(let i=0,children=Object.values(node[2]);i<children.length;i++){let childNode=children[i];let nodePath=childNode[0];let nextIdx=idx+nodePath.length;builder+=(shouldBoundCheck(childNode)?(i>0?`else if(`:`if(`)+`l>`+idxPrefix+nextIdx+`&&`:i>0?`else if(`:`if(`)+`p.startsWith("`+nodePath+`",`+currentIdx+`)){`+compile(childNode,paramCount,nextIdx,idxPrefix)+`}`}if(node[3]!=null){let params=node[3];let hasStore=params[1]!=null;let hasChild=params[0]!=null;if(paramCount>0){builder+=`let i=`+currentIdx+`;`;currentIdx=`i`}(hasChild||!hasStore)&&(builder+=(paramCount>0?``:`let `)+`j=p.indexOf("/",`+currentIdx+`);`);hasStore&&(builder+=`if(`+(hasChild?`j===-1){let `:`!p.includes("/",`+currentIdx+`)){let `)+`q`+paramCount+`=`+(currentIdx===`0`?`p;`:`p.slice(`+currentIdx+`);`)+params[1]+`}`);if(hasChild){let childNode=params[0];builder+=(hasStore?`else if(`:`if(`)+`j>`+currentIdx+`){let q`+paramCount+`=p.slice(`+currentIdx+`,j`+(shouldBoundCheck(childNode)?`);if(l>j+1){`+compile(childNode,paramCount+1,1,`j+`)+`}}`:`);`+compile(childNode,paramCount+1,1,`j+`)+`}`)}}node[4]==null||(builder+=`let q`+paramCount+`=`+(currentIdx===`0`?`p`:`p.slice(`+currentIdx+`)`)+`;`+node[4]);return builder};
1
+ export let shouldBoundCheck=node=>node[1]==null;export let compile=(node,paramCount,idx,idxPrefix)=>{let builder=``;let currentIdx=idxPrefix+idx;node[1]==null||(builder+=`if(l===`+currentIdx+`){`+node[1]+`}`);if(node[2]!=null){let children=Object.values(node[2]);if(children.length>1){builder+=`switch(p.charCodeAt(`+currentIdx+`)){`;for(let i=0;i<children.length;i++){let childNode=children[i];let nodePath=childNode[0];let nextIdx=idx+nodePath.length;builder+=`case `+nodePath.charCodeAt(0)+(shouldBoundCheck(childNode)?`:if(l>`+idxPrefix+nextIdx+`)`:`:`)+(nodePath.length>1?`if(p.startsWith("`+nodePath.slice(1)+`",`+idxPrefix+(idx+1)+`)){`:`{`)+compile(childNode,paramCount,nextIdx,idxPrefix)+`}`}builder+=`}`}else{let childNode=children[0];let nodePath=childNode[0];let nextIdx=idx+nodePath.length;builder+=(shouldBoundCheck(childNode)?`if(l>`+idxPrefix+nextIdx+`)if(p.startsWith("`:`if(p.startsWith("`)+nodePath+`",`+currentIdx+`)){`+compile(childNode,paramCount,nextIdx,idxPrefix)+`}`}}if(node[3]!=null){let params=node[3];let hasStore=params[1]!=null;let hasChild=params[0]!=null;if(paramCount>0){builder+=`let i=`+currentIdx+`;`;currentIdx=`i`}(hasChild||!hasStore)&&(builder+=(paramCount>0?`j=p.indexOf("/",`:`let j=p.indexOf("/",`)+currentIdx+`);`);hasStore&&(builder+=(hasChild?`if(j===-1){let q`:`if(!p.includes("/",`+currentIdx+`)){let q`)+paramCount+(currentIdx===`0`?`=p;`:`=p.slice(`+currentIdx+`);`)+params[1]+`}`);if(hasChild){let childNode=params[0];builder+=(hasStore?`else if(j>`:`if(j>`)+currentIdx+`){let q`+paramCount+`=p.slice(`+currentIdx+(shouldBoundCheck(childNode)?`,j);if(l>j+1){`+compile(childNode,paramCount+1,1,`j+`)+`}}`:`,j);`+compile(childNode,paramCount+1,1,`j+`)+`}`)}}node[4]==null||(builder+=`let q`+paramCount+(currentIdx===`0`?`=p;`:`=p.slice(`+currentIdx+`);`)+node[4]);return builder};