1- import {
2- type BlockIRNode ,
3- IRNodeTypes ,
4- type OperationNode ,
5- type WithDirectiveIRNode ,
6- } from '../ir'
1+ import type { BlockIRNode } from '../ir'
72import {
83 type CodeFragment ,
94 INDENT_END ,
@@ -13,7 +8,6 @@ import {
138 genCall ,
149} from './utils'
1510import type { CodegenContext } from '../generate'
16- import { genWithDirective } from './directive'
1711import { genEffects , genOperations } from './operation'
1812import { genChildren } from './template'
1913import { genMulti } from './utils'
@@ -38,12 +32,14 @@ export function genBlock(
3832}
3933
4034export function genBlockContent (
41- { dynamic , effect , operation , returns } : BlockIRNode ,
35+ block : BlockIRNode ,
4236 context : CodegenContext ,
4337 root ?: boolean ,
4438 customReturns ?: ( returns : CodeFragment [ ] ) => CodeFragment [ ] ,
4539) : CodeFragment [ ] {
4640 const [ frag , push ] = buildCodeFragment ( )
41+ const { dynamic, effect, operation, returns } = block
42+ const resetBlock = context . enterBlock ( block )
4743
4844 if ( root )
4945 for ( const name of context . ir . component ) {
@@ -61,10 +57,6 @@ export function genBlockContent(
6157 push ( ...genChildren ( child , context , child . id ! ) )
6258 }
6359
64- for ( const directives of groupDirective ( operation ) ) {
65- push ( ...genWithDirective ( directives , context ) )
66- }
67-
6860 push ( ...genOperations ( operation , context ) )
6961 push (
7062 ...( context . genEffects . length
@@ -80,19 +72,6 @@ export function genBlockContent(
8072 : [ `n${ returns [ 0 ] } ` ]
8173 push ( ...( customReturns ? customReturns ( returnsCode ) : returnsCode ) )
8274
75+ resetBlock ( )
8376 return frag
8477}
85-
86- function groupDirective ( operation : OperationNode [ ] ) : WithDirectiveIRNode [ ] [ ] {
87- const directiveOps = operation . filter (
88- ( oper ) : oper is WithDirectiveIRNode =>
89- oper . type === IRNodeTypes . WITH_DIRECTIVE ,
90- )
91-
92- const directiveMap : Record < number , WithDirectiveIRNode [ ] > = { }
93- for ( const oper of directiveOps ) {
94- if ( ! directiveMap [ oper . element ] ) directiveMap [ oper . element ] = [ ]
95- directiveMap [ oper . element ] . push ( oper )
96- }
97- return Object . values ( directiveMap )
98- }
0 commit comments