@mapl/router 0.8.4 → 0.8.5
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 +1 -1
- package/tree/compiler.js +1 -1
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@mapl/router","version":"0.8.
|
|
1
|
+
{"name":"@mapl/router","version":"0.8.5","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","./method/compiler":"./method/compiler.js","./constants":"./constants.js","./path/compiler":"./path/compiler.js","./tree/compiler":"./tree/compiler.js","./tree/node":"./tree/node.js","./path":"./path/index.js","./method":"./method/index.js"}}
|
package/tree/compiler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
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+=(childNode[1]==null?(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`}
|
|
1
|
+
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+=(childNode[1]==null&&(childNode[3]!=null||childNode[4]!=null)?(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];let nodePath=childNode[0];builder+=(hasStore?`else if(`:`if(`)+`j>`+currentIdx+`){let q`+paramCount+`=p.slice(`+currentIdx+`,j);`+(childNode[1]==null?`if(l>j+`+nodePath.length+`)`:``)+(nodePath.length>1?`if(p.startsWith("`+nodePath.slice(1)+`",j+1)){`:`{`)+compile(childNode,paramCount+1,nodePath.length,`j+`)+`}}`}}node[4]==null||(builder+=`let q`+paramCount+`=`+(currentIdx===`0`?`p`:`p.slice(`+currentIdx+`)`)+`;`+node[4]);return builder};
|