@mapl/router 0.8.5 → 0.8.7
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.d.ts +1 -0
- 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.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"}}
|
package/tree/compiler.d.ts
CHANGED
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+=(
|
|
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};
|