@@ -61,7 +61,6 @@ export interface CompileOptions extends PathOptions {
61
61
type TokenType =
62
62
| "{"
63
63
| "}"
64
- | ","
65
64
| "WILDCARD"
66
65
| "PARAM"
67
66
| "CHAR"
@@ -89,7 +88,6 @@ const SIMPLE_TOKENS: Record<string, TokenType> = {
89
88
// Groups.
90
89
"{" : "{" ,
91
90
"}" : "}" ,
92
- "," : "," ,
93
91
// Reserved.
94
92
"(" : "(" ,
95
93
")" : ")" ,
@@ -248,7 +246,7 @@ export interface Wildcard {
248
246
*/
249
247
export interface Group {
250
248
type : "group" ;
251
- children : Array < Token [ ] > ;
249
+ tokens : Token [ ] ;
252
250
}
253
251
254
252
/**
@@ -284,7 +282,7 @@ export function parse(str: string, options: ParseOptions = {}): TokenData {
284
282
options ;
285
283
const it = new Iter ( lexer ( str ) ) ;
286
284
287
- function consume ( brace : boolean ) : [ end : boolean , tokens : Token [ ] ] {
285
+ function consume ( endType : TokenType ) : Token [ ] {
288
286
const tokens : Token [ ] = [ ] ;
289
287
290
288
while ( true ) {
@@ -311,34 +309,19 @@ export function parse(str: string, options: ParseOptions = {}): TokenData {
311
309
312
310
const open = it . tryConsume ( "{" ) ;
313
311
if ( open ) {
314
- const children : Array < Token [ ] > = [ ] ;
315
-
316
- while ( true ) {
317
- const [ end , tokens ] = consume ( true ) ;
318
- children . push ( tokens ) ;
319
- if ( end ) break ;
320
- }
321
-
322
312
tokens . push ( {
323
313
type : "group" ,
324
- children : children ,
314
+ tokens : consume ( "}" ) ,
325
315
} ) ;
326
316
continue ;
327
317
}
328
318
329
- if ( brace ) {
330
- const comma = it . tryConsume ( "," ) ;
331
- if ( comma ) return [ false , tokens ] ;
332
- it . consume ( "}" ) ;
333
- } else {
334
- it . consume ( "END" ) ;
335
- }
336
-
337
- return [ true , tokens ] ;
319
+ it . consume ( endType ) ;
320
+ return tokens ;
338
321
}
339
322
}
340
323
341
- const [ , tokens ] = consume ( false ) ;
324
+ const tokens = consume ( "END" ) ;
342
325
return new TokenData ( tokens , delimiter ) ;
343
326
}
344
327
@@ -408,19 +391,7 @@ function tokenToFunction(
408
391
if ( token . type === "text" ) return ( ) => [ token . value ] ;
409
392
410
393
if ( token . type === "group" ) {
411
- const fns = token . children . map ( ( child ) =>
412
- tokensToFunction ( child , delimiter , encode ) ,
413
- ) ;
414
-
415
- return ( data ) => {
416
- const allMissing : string [ ] = [ ] ;
417
- for ( const fn of fns ) {
418
- const [ value , ...missing ] = fn ( data ) ;
419
- if ( ! missing . length ) return [ value ] ;
420
- allMissing . push ( ...missing ) ;
421
- }
422
- return [ "" , ...allMissing ] ;
423
- } ;
394
+ return tokensToFunction ( token . tokens , delimiter , encode ) ;
424
395
}
425
396
426
397
const encodeValue = encode || NOOP_VALUE ;
@@ -569,14 +540,10 @@ function* flatten(
569
540
const token = tokens [ index ] ;
570
541
571
542
if ( token . type === "group" ) {
572
- for ( const child of token . children ) {
573
- const fork = init . slice ( ) ;
574
- for ( const seq of flatten ( child , 0 , fork ) ) {
575
- yield * flatten ( tokens , index + 1 , seq ) ;
576
- }
543
+ const fork = init . slice ( ) ;
544
+ for ( const seq of flatten ( token . tokens , 0 , fork ) ) {
545
+ yield * flatten ( tokens , index + 1 , seq ) ;
577
546
}
578
-
579
- if ( token . children . length ) return ;
580
547
} else {
581
548
init . push ( token ) ;
582
549
}
0 commit comments