Permit use of _$ as a capture-of-wild - terser than _$()

This commit is contained in:
Tony Garnock-Jones 2014-05-25 13:27:30 -04:00
parent 74acc78aab
commit a8f4c74de9
1 changed files with 6 additions and 3 deletions

View File

@ -21,6 +21,9 @@ function Routing(exports) {
return new $Capture(pattern); return new $Capture(pattern);
} }
function isCapture(x) { return x instanceof $Capture || x === _$; }
function capturePattern(x) { return x instanceof $Capture ? x.pattern : __; }
var SOC = "__{{"; // start of capture var SOC = "__{{"; // start of capture
var EOC = "__}}"; // end of capture var EOC = "__}}"; // end of capture
@ -694,9 +697,9 @@ function Routing(exports) {
return acc; return acc;
function walk(p) { function walk(p) {
if (p instanceof $Capture) { if (isCapture(p)) {
acc.push(SOC); acc.push(SOC);
walk(p.pattern); walk(capturePattern(p));
acc.push(EOC); acc.push(EOC);
return; return;
} }
@ -722,7 +725,7 @@ function Routing(exports) {
return walk(p); return walk(p);
function walk(p) { function walk(p) {
if (p instanceof $Capture) return walk(p.pattern); if (isCapture(p)) return walk(capturePattern(p));
if (Array.isArray(p)) { if (Array.isArray(p)) {
var result = []; var result = [];