@mapl/router 0.10.0 → 0.10.2
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.10.
|
|
1
|
+
{"name":"@mapl/router","version":"0.10.2","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","./method":"./method/index.js","./tree/match":"./tree/match.js","./tree/compiler":"./tree/compiler.js","./tree/node":"./tree/node.js"}}
|
package/tree/compiler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export let shouldBoundCheck=node=>node[1]==null&&(node[2].length!==1||node[3][0][0].length===1||node[4]!==null||node[5]!==null);export let compile=(node,paramCount,idx,idxPrefix)=>{let builder=``;let currentIdx=idxPrefix+idx;node[1]
|
|
1
|
+
export let shouldBoundCheck=node=>node[1]==null&&(node[2].length!==1||node[3][0][0].length===1||node[4]!==null||node[5]!==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].length>0){let childrenFirstChar=node[2];let children=node[3];if(children.length>1){builder+=`switch(p.charCodeAt(${currentIdx})){`;for(let i=0,checkIdx=idxPrefix+(idx+1);i<children.length;i++){let childNode=children[i],nodePart=childNode[0],nextIdx=idx+nodePart.length;builder+=`case `+childrenFirstChar[i]+(shouldBoundCheck(childNode)?`:if(l>${idxPrefix+nextIdx})`:`:`)+(nodePart.length>2?`if(p.startsWith("${nodePart.slice(1)}",${checkIdx})){`:nodePart.length>1?`if(p.charCodeAt(${checkIdx})===${nodePart.charCodeAt(1)}){`:`{`)+compile(childNode,paramCount,nextIdx,idxPrefix)+`}`}builder+=`}`}else{let childNode=children[0],nodePart=childNode[0],nodePartLen=nodePart.length;shouldBoundCheck(childNode)&&(builder+=`if(l>${idxPrefix+(idx+nodePartLen)})`);builder+=(nodePartLen>1?`if(p.startsWith("${nodePart}",${currentIdx})){`:`if(p.charCodeAt(${currentIdx})===${childrenFirstChar[0]}){`)+compile(childNode,paramCount,idx+nodePartLen,idxPrefix)+`}`}}if(node[4]!==null){let params=node[4],hasChild=params[0]!==null;if(hasChild){let childNode=params[0];if(paramCount>0){builder+=`let i=${currentIdx};j=p.indexOf("/",`;currentIdx=`i`}else builder+=`let j=p.indexOf("/",`;let needBoundCheck=shouldBoundCheck(childNode);builder+=currentIdx+`);if(j>`+currentIdx+(needBoundCheck?`){if(l>j+1){let q`:`){let q`)+paramCount+`=p.slice(${currentIdx},j);`+compile(childNode,paramCount+1,1,`j+`)+(needBoundCheck?`}}`:`}`)}params[1]!==null&&(builder+=(hasChild?`else if(j===-1){let q`:`if(!p.includes("/",${currentIdx})){let q`)+paramCount+(currentIdx===`0`?`=p;`:`=p.slice(${currentIdx});`)+params[1]+`}`)}node[5]===null||(builder+=`let q`+paramCount+(currentIdx===`0`?`=p;`:`=p.slice(${currentIdx});`)+node[5]);return builder};
|