koa-tree-router
Advanced tools
Comparing version 0.4.4 to 0.4.5
{ | ||
"name": "koa-tree-router", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"description": "A high performance koa router", | ||
@@ -36,6 +36,6 @@ "main": "router.js", | ||
"devDependencies": { | ||
"expect": "^23.6.0", | ||
"koa": "^2.6.2", | ||
"mocha": "^5.2.0", | ||
"supertest": "^3.3.0" | ||
"expect": "^24.1.0", | ||
"koa": "^2.7.0", | ||
"mocha": "^6.0.1", | ||
"supertest": "^3.4.2" | ||
}, | ||
@@ -42,0 +42,0 @@ "dependencies": { |
29
tree.js
@@ -25,3 +25,2 @@ const STATIC = 0; | ||
* @param {number} type | ||
* @param {number} maxParams | ||
* @param {string} indices | ||
@@ -36,3 +35,2 @@ * @param {Node[]} children | ||
type = STATIC, | ||
maxParams = 0, | ||
indices = "", | ||
@@ -46,3 +44,2 @@ children = [], | ||
this.type = type; | ||
this.maxParams = maxParams; | ||
this.indices = indices; | ||
@@ -96,7 +93,2 @@ this.children = children; | ||
walk: while (true) { | ||
// Update maxParams of the current node | ||
if (numParams > n.maxParams) { | ||
n.maxParams = numParams; | ||
} | ||
// Find the longest common prefix | ||
@@ -117,3 +109,2 @@ // This also implies that the common prefix contains no ':' or '*' | ||
STATIC, | ||
0, | ||
n.indices, | ||
@@ -125,9 +116,2 @@ n.children, | ||
// Update maxParams (max of all children) | ||
child.children.forEach(grandChild => { | ||
if (grandChild.maxParams > child.maxParams) { | ||
child.maxParams = grandChild.maxParams; | ||
} | ||
}); | ||
n.children = [child]; | ||
@@ -148,6 +132,2 @@ n.indices = n.path[i]; | ||
// Update maxParams of the child node | ||
if (numParams > n.maxParams) { | ||
n.maxParams = numParams; | ||
} | ||
numParams--; | ||
@@ -204,4 +184,3 @@ | ||
false, | ||
STATIC, | ||
numParams | ||
STATIC | ||
); | ||
@@ -293,3 +272,3 @@ n.children.push(child); | ||
const child = new Node("", false, PARAM, numParams); | ||
const child = new Node("", false, PARAM); | ||
n.children = [child]; | ||
@@ -308,3 +287,2 @@ n.wildChild = true; | ||
STATIC, | ||
numParams, | ||
"", | ||
@@ -343,3 +321,3 @@ [], | ||
// first node: catchAll node with empty path | ||
const catchAllChild = new Node("", true, CATCH_ALL, 1); | ||
const catchAllChild = new Node("", true, CATCH_ALL); | ||
n.children = [catchAllChild]; | ||
@@ -355,3 +333,2 @@ n.indices = path[i]; | ||
CATCH_ALL, | ||
1, | ||
"", | ||
@@ -358,0 +335,0 @@ [], |
20728
556