Skip to content

Commit

Permalink
refactor(compiler-vapor): group directive
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Apr 7, 2024
1 parent 9a33d79 commit 98bae0c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/compiler-vapor/src/generators/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type BlockIRNode, IRNodeTypes, type WithDirectiveIRNode } from '../ir'
import {
type BlockIRNode,
IRNodeTypes,
type OperationNode,
type WithDirectiveIRNode,
} from '../ir'
import {
type CodeFragment,
INDENT_END,
Expand Down Expand Up @@ -41,11 +46,7 @@ export function genBlockContent(
push(...genChildren(child, context, child.id!))
}

const directiveOps = operation.filter(
(oper): oper is WithDirectiveIRNode =>
oper.type === IRNodeTypes.WITH_DIRECTIVE,
)
for (const directives of groupDirective(directiveOps)) {
for (const directives of groupDirective(operation)) {
push(...genWithDirective(directives, context))
}

Expand All @@ -67,9 +68,14 @@ export function genBlockContent(
return frag
}

function groupDirective(ops: WithDirectiveIRNode[]): WithDirectiveIRNode[][] {
function groupDirective(operation: OperationNode[]): WithDirectiveIRNode[][] {
const directiveOps = operation.filter(
(oper): oper is WithDirectiveIRNode =>
oper.type === IRNodeTypes.WITH_DIRECTIVE,
)

const directiveMap: Record<number, WithDirectiveIRNode[]> = {}
for (const oper of ops) {
for (const oper of directiveOps) {
if (!directiveMap[oper.element]) directiveMap[oper.element] = []
directiveMap[oper.element].push(oper)
}
Expand Down

0 comments on commit 98bae0c

Please sign in to comment.