Skip to content

Commit 98bae0c

Browse files
committed
refactor(compiler-vapor): group directive
1 parent 9a33d79 commit 98bae0c

File tree

1 file changed

+14
-8
lines changed
  • packages/compiler-vapor/src/generators

1 file changed

+14
-8
lines changed

packages/compiler-vapor/src/generators/block.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { type BlockIRNode, IRNodeTypes, type WithDirectiveIRNode } from '../ir'
1+
import {
2+
type BlockIRNode,
3+
IRNodeTypes,
4+
type OperationNode,
5+
type WithDirectiveIRNode,
6+
} from '../ir'
27
import {
38
type CodeFragment,
49
INDENT_END,
@@ -41,11 +46,7 @@ export function genBlockContent(
4146
push(...genChildren(child, context, child.id!))
4247
}
4348

44-
const directiveOps = operation.filter(
45-
(oper): oper is WithDirectiveIRNode =>
46-
oper.type === IRNodeTypes.WITH_DIRECTIVE,
47-
)
48-
for (const directives of groupDirective(directiveOps)) {
49+
for (const directives of groupDirective(operation)) {
4950
push(...genWithDirective(directives, context))
5051
}
5152

@@ -67,9 +68,14 @@ export function genBlockContent(
6768
return frag
6869
}
6970

70-
function groupDirective(ops: WithDirectiveIRNode[]): WithDirectiveIRNode[][] {
71+
function groupDirective(operation: OperationNode[]): WithDirectiveIRNode[][] {
72+
const directiveOps = operation.filter(
73+
(oper): oper is WithDirectiveIRNode =>
74+
oper.type === IRNodeTypes.WITH_DIRECTIVE,
75+
)
76+
7177
const directiveMap: Record<number, WithDirectiveIRNode[]> = {}
72-
for (const oper of ops) {
78+
for (const oper of directiveOps) {
7379
if (!directiveMap[oper.element]) directiveMap[oper.element] = []
7480
directiveMap[oper.element].push(oper)
7581
}

0 commit comments

Comments
 (0)