Skip to content

Commit 48d2aa3

Browse files
committed
fix(compiler-vapor): handle no template
1 parent ed9368c commit 48d2aa3

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

Diff for: packages/compiler-vapor/src/generate.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import {
1111
type BlockFunctionIRNode,
1212
DynamicFlag,
13-
type IRDynamicChildren,
13+
type IRDynamicInfo,
1414
IRNodeTypes,
1515
type OperationNode,
1616
type RootIRNode,
@@ -313,20 +313,23 @@ export function generate(
313313
}
314314
}
315315

316-
function genChildren(children: IRDynamicChildren) {
316+
function genChildren(children: IRDynamicInfo[]) {
317317
let code = ''
318318
let offset = 0
319-
for (const [index, child] of Object.entries(children)) {
320-
const childrenLength = Object.keys(child.children).length
319+
320+
for (const [index, child] of children.entries()) {
321321
if (child.dynamicFlags & DynamicFlag.NON_TEMPLATE) {
322322
offset--
323-
continue
324323
}
325324

326325
const idx = Number(index) + offset
327326
const id =
328-
child.dynamicFlags & DynamicFlag.INSERT ? child.placeholder : child.id
329-
const childrenString = childrenLength && genChildren(child.children)
327+
child.dynamicFlags & DynamicFlag.REFERENCED
328+
? child.dynamicFlags & DynamicFlag.INSERT
329+
? child.anchor
330+
: child.id
331+
: null
332+
const childrenString = genChildren(child.children)
330333

331334
if (id !== null || childrenString) {
332335
code += ` ${idx}: [`

Diff for: packages/compiler-vapor/src/ir.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export enum DynamicFlag {
199199
export interface IRDynamicInfo {
200200
id: number | null
201201
dynamicFlags: DynamicFlag
202-
placeholder: number | null
202+
anchor: number | null
203203
children: IRDynamicInfo[]
204204
}
205205

Diff for: packages/compiler-vapor/src/transform.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const defaultOptions = {
102102
export const genDefaultDynamic = (): IRDynamicInfo => ({
103103
id: null,
104104
dynamicFlags: 0,
105-
placeholder: null,
105+
anchor: null,
106106
children: [],
107107
})
108108

@@ -335,7 +335,9 @@ function processDynamicChildren(ctx: TransformContext<RootNode | ElementNode>) {
335335
if (prevChildren.length) {
336336
if (hasStatic) {
337337
ctx.childrenTemplate[index - prevChildren.length] = `<!>`
338-
const anchor = (prevChildren[0].placeholder = ctx.increaseId())
338+
339+
prevChildren[0].dynamicFlags -= DynamicFlag.NON_TEMPLATE
340+
const anchor = (prevChildren[0].anchor = ctx.increaseId())
339341

340342
ctx.registerOperation({
341343
type: IRNodeTypes.INSERT_NODE,

0 commit comments

Comments
 (0)