@mapl/router 0.3.1 → 0.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/tree/compiler.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapl/router",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "main": "./index.js",
5
5
  "devDependencies": {
6
6
  "@stylistic/eslint-plugin": "latest",
package/tree/compiler.js CHANGED
@@ -1 +1 @@
1
- let f=(node,hasParam,hasMultipleParams,startIndexValue,startIndexPrefix)=>{let builder="";if(node[0].length!==1){let part=node[0];let len=part.length;builder+=`if(l>${startIndexPrefix}${startIndexValue+len-1})`;for(let i=1;i<len;i++)builder+=`if(p.charCodeAt(${startIndexPrefix}${startIndexValue+i})===${part.charCodeAt(i)})`;builder+="{";startIndexValue+=len}else startIndexValue++;if(node[1]!==null)builder+=`if(l===${startIndexPrefix}${startIndexValue}){${node[1]}}`;if(node[2]!==null){let children=node[2];let childrenEntries=Object.entries(children);if(childrenEntries.length===1){builder+=`if(p.charCodeAt(${startIndexPrefix}${startIndexValue})===${childrenEntries[0][0]}){${f(childrenEntries[0][1],hasParam,hasMultipleParams,startIndexValue,startIndexPrefix)}}`}else{builder+=`switch(p.charCodeAt(${startIndexPrefix}${startIndexValue})){`;for(let i=0,l=childrenEntries.length;i<l;i++){builder+=`case ${childrenEntries[i][0]}:${f(childrenEntries[i][1],hasParam,hasMultipleParams,startIndexValue,startIndexPrefix)}break;`}builder+="}"}}if(node[3]!==null){let params=node[3];let hasStore=params[1]!==null;let hasChild=params[0]!==null;let requireAllocation=hasParam?hasMultipleParams:hasChild||!hasStore;if(requireAllocation)builder+="{";if(hasParam)builder+=`${hasMultipleParams?"":"let "}i=${startIndexPrefix}${startIndexValue};`;let currentIndex=hasParam?"i":startIndexPrefix+startIndexValue;let slashIndex=`p.indexOf('/'${currentIndex==="0"?"":","+currentIndex})`;if(hasChild||!hasStore)builder+=`${hasParam?"":"let "}j=${slashIndex};`;if(hasStore){let paramsVal=currentIndex==="0"?"p":`p.slice(${currentIndex})`;builder+=`if(${hasChild?"j":slashIndex}===-1){${hasParam?`q.push(${paramsVal})`:`let q=[${paramsVal}]`};${params[1]}}`}if(hasChild){let paramsVal=`p.substring(${currentIndex},j)`;builder+=`if(j${hasStore?"!==":">"}${currentIndex}){${hasParam?`q.push(${paramsVal})`:`let q=[${paramsVal}]`};${f(params[0],true,hasParam,0,"j+")}${requireAllocation?"":"q.pop();"}}`}if(requireAllocation)builder+="}"}if(node[4]!==null){let noStore=node[1]===null;let currentIndex=startIndexPrefix+startIndexValue;let paramsVal=currentIndex==="0"?"p":`p.slice(${currentIndex})`;let body=`${hasParam?`q.push(${paramsVal})`:`let q=[${paramsVal}]`};${node[4]}`;builder+=noStore?`if(l!==${currentIndex}){${body}}`:body}return node[0].length===1?builder:builder+"}"};export default f;
1
+ let f=(node,hasParam,hasMultipleParams,startIndexValue,startIndexPrefix)=>{let builder="";if(node[0].length!==1){let part=node[0];let len=part.length;builder+=`if(l>${startIndexPrefix}${startIndexValue+len-1})`;for(let i=1;i<len;i++)builder+=`if(p.charCodeAt(${startIndexPrefix}${startIndexValue+i})===${part.charCodeAt(i)})`;builder+="{";startIndexValue+=len}else startIndexValue++;if(node[1]!==null)builder+=`if(l===${startIndexPrefix}${startIndexValue}){${node[1]}}`;if(node[2]!==null){let children=node[2];let childrenEntries=Object.entries(children);if(childrenEntries.length===1){builder+=`if(p.charCodeAt(${startIndexPrefix}${startIndexValue})===${childrenEntries[0][0]}){${f(childrenEntries[0][1],hasParam,hasMultipleParams,startIndexValue,startIndexPrefix)}}`}else{builder+=`switch(p.charCodeAt(${startIndexPrefix}${startIndexValue})){`;for(let i=0;i<childrenEntries.length;i++){builder+=`case ${childrenEntries[i][0]}:${f(childrenEntries[i][1],hasParam,hasMultipleParams,startIndexValue,startIndexPrefix)}break;`}builder+="}"}}if(node[3]!==null){let params=node[3];let hasStore=params[1]!==null;let hasChild=params[0]!==null;let requireAllocation=hasParam?hasMultipleParams:hasChild||!hasStore;if(requireAllocation)builder+="{";if(hasParam)builder+=`${hasMultipleParams?"":"let "}i=${startIndexPrefix}${startIndexValue};`;let currentIndex=hasParam?"i":startIndexPrefix+startIndexValue;let slashIndex=`p.indexOf('/'${currentIndex==="0"?"":","+currentIndex})`;if(hasChild||!hasStore)builder+=`${hasParam?"":"let "}j=${slashIndex};`;if(hasStore){let paramsVal=currentIndex==="0"?"p":`p.slice(${currentIndex})`;builder+=`if(${hasChild?"j":slashIndex}===-1){${hasParam?`q.push(${paramsVal})`:`let q=[${paramsVal}]`};${params[1]}}`}if(hasChild){let paramsVal=`p.substring(${currentIndex},j)`;builder+=`if(j${hasStore?"!==":">"}${currentIndex}){${hasParam?`q.push(${paramsVal})`:`let q=[${paramsVal}]`};${f(params[0],true,hasParam,0,"j+")}${requireAllocation?"":"q.pop();"}}`}if(requireAllocation)builder+="}"}if(node[4]!==null){let noStore=node[1]===null;let currentIndex=startIndexPrefix+startIndexValue;let paramsVal=currentIndex==="0"?"p":`p.slice(${currentIndex})`;let body=`${hasParam?`q.push(${paramsVal})`:`let q=[${paramsVal}]`};${node[4]}`;builder+=noStore?`if(l!==${currentIndex}){${body}}`:body}return node[0].length===1?builder:builder+"}"};export default f;