@@ -9,31 +9,44 @@ import * as b from '../../../../utils/builders.js';
99 */
1010export function IfBlock ( node , context ) {
1111 context . state . template . push ( '<!>' ) ;
12+ const statements = [ ] ;
1213
1314 const consequent = /** @type {BlockStatement } */ ( context . visit ( node . consequent ) ) ;
1415 const consequent_id = context . state . scope . generate ( 'consequent' ) ;
1516
16- context . state . init . push ( b . var ( b . id ( consequent_id ) , b . arrow ( [ b . id ( '$$anchor' ) ] , consequent ) ) ) ;
17+ statements . push ( b . var ( b . id ( consequent_id ) , b . arrow ( [ b . id ( '$$anchor' ) ] , consequent ) ) ) ;
1718
1819 let alternate_id ;
1920
2021 if ( node . alternate ) {
2122 const alternate = /** @type {BlockStatement } */ ( context . visit ( node . alternate ) ) ;
2223 alternate_id = context . state . scope . generate ( 'alternate' ) ;
23- context . state . init . push ( b . var ( b . id ( alternate_id ) , b . arrow ( [ b . id ( '$$anchor' ) ] , alternate ) ) ) ;
24+ statements . push ( b . var ( b . id ( alternate_id ) , b . arrow ( [ b . id ( '$$anchor' ) ] , alternate ) ) ) ;
2425 }
2526
2627 /** @type {Expression[] } */
2728 const args = [
2829 context . state . node ,
2930 b . arrow (
30- [ b . id ( '$$branch ' ) ] ,
31+ [ b . id ( '$$render ' ) ] ,
3132 b . block ( [
3233 b . if (
3334 /** @type {Expression } */ ( context . visit ( node . test ) ) ,
34- b . stmt ( b . call ( b . id ( '$$branch' ) , b . literal ( 0 ) , b . id ( consequent_id ) ) ) ,
35+ b . stmt (
36+ b . call (
37+ b . id ( '$$render' ) ,
38+ b . id ( consequent_id ) ,
39+ node . alternate ? b . literal ( true ) : undefined
40+ )
41+ ) ,
3542 alternate_id
36- ? b . stmt ( b . call ( b . id ( '$$branch' ) , b . literal ( 1 ) , b . id ( alternate_id ) ) )
43+ ? b . stmt (
44+ b . call (
45+ b . id ( '$$render' ) ,
46+ b . id ( alternate_id ) ,
47+ node . alternate ? b . literal ( false ) : undefined
48+ )
49+ )
3750 : undefined
3851 )
3952 ] )
@@ -65,5 +78,7 @@ export function IfBlock(node, context) {
6578 args . push ( b . literal ( true ) ) ;
6679 }
6780
68- context . state . init . push ( b . stmt ( b . call ( '$.if' , ...args ) ) ) ;
81+ statements . push ( b . stmt ( b . call ( '$.if' , ...args ) ) ) ;
82+
83+ context . state . init . push ( b . block ( statements ) ) ;
6984}
0 commit comments