@mapl/router 0.5.1 → 0.5.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 +5 -1
- package/tree/compiler.js +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapl/router",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"main": "./index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/mapljs/router.git"
|
|
8
|
+
},
|
|
5
9
|
"devDependencies": {
|
|
6
10
|
"@stylistic/eslint-plugin": "latest",
|
|
7
11
|
"@types/bun": "latest",
|
package/tree/compiler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let toChar=(c)=>String.fromCharCode(+c[0]);export var compile=(node,paramCount,startIndexValue,startIndexPrefix)=>{let builder="";if(node[0]
|
|
1
|
+
let toChar=(c)=>String.fromCharCode(+c[0]);export var compile=(node,paramCount,startIndexValue,startIndexPrefix)=>{let builder="";if(node[0]!=="/"){let part=node[0];let start=startIndexPrefix+(startIndexValue+1);builder+="if(p"+(part.length===2?"["+start+']==="'+part[1]+'"':'.startsWith("'+part.slice(1)+'",'+start+")")+"){";startIndexValue+=part.length}else startIndexValue++;let currentIndex=startIndexPrefix+startIndexValue;if(node[1]!==null)builder+="if(l==="+currentIndex+"){"+node[1]+"}";if(node[2]!==null){let children=node[2];let childrenEntries=Object.entries(children);if(childrenEntries.length===1){builder+="if(p["+currentIndex+']==="'+toChar(childrenEntries[0])+'"){'+compile(childrenEntries[0][1],paramCount,startIndexValue,startIndexPrefix)+"}"}else{builder+="switch(p["+currentIndex+"]){";for(let i=0;i<childrenEntries.length;i++){builder+='case"'+toChar(childrenEntries[i])+'":{'+compile(childrenEntries[i][1],paramCount,startIndexValue,startIndexPrefix)+"break;}"}builder+="}"}}if(node[3]!==null){let params=node[3];let hasStore=params[1]!==null;let hasChild=params[0]!==null;if(paramCount>0){builder+="let i="+currentIndex+";";currentIndex="i"}let slashIndex='p.indexOf("/"'+(currentIndex==="0"?"":","+currentIndex)+")";if(hasChild||!hasStore){builder+=(paramCount>0?"":"let ")+"j="+slashIndex+";";slashIndex="j"}if(hasStore){let paramsVal=currentIndex==="0"?"p":"p.slice("+currentIndex+")";builder+="if("+slashIndex+"===-1){let q"+paramCount+"="+paramsVal+";"+params[1]+"}"}if(hasChild){let paramsVal="p.slice("+currentIndex+",j)";builder+="if(j>"+currentIndex+"){let q"+paramCount+"="+paramsVal+";"+compile(params[0],paramCount+1,0,"j+")+"}"}}if(node[4]!==null){let noStore=node[1]===null;let paramsVal=currentIndex==="0"?"p":"p.slice("+currentIndex+")";let body="let q"+paramCount+"="+paramsVal+";"+node[4];builder+=noStore?"if(l>"+currentIndex+"){"+body+"}":body}return node[0]!=="/"?builder+"}":builder};
|