File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,17 +13,21 @@ export const router_compile_to_code = (
1313
1414 if ( matchAllIdx !== - 1 ) linear_map_swap ( router , matchAllIdx , trees . length - 1 ) ;
1515
16- let str = `switch( ${ methodId } ){` ;
16+ let str = '' ;
1717 for (
18- let i = 0 , methods = router [ 0 ] , treesLen = trees . length - ( matchAllIdx !== - 1 ? 1 : 0 ) ;
18+ let i = 0 ,
19+ methods = router [ 0 ] ,
20+ treesLen = trees . length - ( matchAllIdx !== - 1 ? 1 : 0 ) ,
21+ prefix = `if(${ methodId } ===` ;
1922 i < treesLen ;
2023 i ++
21- )
24+ ) {
2225 str +=
23- `case${ JSON . stringify ( methods [ i ] ) } :` +
24- tree_compile_to_code ( trees [ i ] , resultId , pathId ) +
25- 'break;' ;
26- str += '}' ;
26+ prefix +
27+ JSON . stringify ( methods [ i ] ) +
28+ `){${ tree_compile_to_code ( trees [ i ] , resultId , pathId ) } }` ;
29+ if ( i === 0 ) prefix = 'else ' + prefix ;
30+ }
2731
2832 return matchAllIdx !== - 1
2933 ? str + tree_compile_to_code ( trees [ trees . length - 1 ] , resultId , pathId )
Original file line number Diff line number Diff line change @@ -10,11 +10,11 @@ export const tree_compile_to_code = (
1010 keys = tree [ 0 ] ,
1111 values = tree [ 1 ] ;
1212
13- if ( keys . length > 0 ) {
14- str = `switch (${ pathId } ){` ;
15- for ( let i = 0 ; i < keys . length ; i ++ ) str += `case ${ JSON . stringify ( keys [ i ] ) } : {${ values [ i ] } }`;
16- str += '}' ;
17- }
13+ if ( keys . length > 0 )
14+ for ( let i = 0 , prefix = `if (${ pathId } ===` ; i < keys . length ; i ++ ) {
15+ str += prefix + JSON . stringify ( keys [ i ] ) + `) {${ values [ i ] } }`;
16+ if ( i === 0 ) prefix = 'else ' + prefix ;
17+ }
1818
1919 if ( tree [ 2 ] !== null ) {
2020 // console.log(JSON.stringify(tree[2]!, null, 2));
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments