@@ -261,5 +262,10 @@ describe('compile', () => {
_setText(n2, " " + _toDisplayString(_ctx.baz))`,
)
})
+
+ test('with insertionState', () => {
+ const code = compile(`
`)
+ expect(code).matchSnapshot()
+ })
})
})
diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap
index 4a8caa65948..6a353b771ff 100644
--- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap
+++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap
@@ -57,10 +57,10 @@ const t0 = _template("
x
")
export function render(_ctx) {
const n1 = t1()
- const n3 = t2()
const n0 = t0()
+ const n3 = t2()
const n2 = t2()
_insert(n0, n1)
_insert(n2, n3)
diff --git a/packages/compiler-vapor/src/generators/block.ts b/packages/compiler-vapor/src/generators/block.ts
index 30347394756..a4f98dfdffa 100644
--- a/packages/compiler-vapor/src/generators/block.ts
+++ b/packages/compiler-vapor/src/generators/block.ts
@@ -65,7 +65,9 @@ export function genBlockContent(
push(...genSelf(child, context))
}
for (const child of dynamic.children) {
- push(...genChildren(child, context, push, `n${child.id!}`))
+ if (!child.hasDynamicChild) {
+ push(...genChildren(child, context, push, `n${child.id!}`))
+ }
}
push(...genOperations(operation, context))
diff --git a/packages/compiler-vapor/src/generators/template.ts b/packages/compiler-vapor/src/generators/template.ts
index 5a066b09e9a..2b8a9ea0e04 100644
--- a/packages/compiler-vapor/src/generators/template.ts
+++ b/packages/compiler-vapor/src/generators/template.ts
@@ -24,7 +24,7 @@ export function genSelf(
context: CodegenContext,
): CodeFragment[] {
const [frag, push] = buildCodeFragment()
- const { id, template, operation } = dynamic
+ const { id, template, operation, hasDynamicChild } = dynamic
if (id !== undefined && template !== undefined) {
push(NEWLINE, `const n${id} = t${template}()`)
@@ -35,6 +35,10 @@ export function genSelf(
push(...genOperationWithInsertionState(operation, context))
}
+ if (hasDynamicChild) {
+ push(...genChildren(dynamic, context, push, `n${id}`))
+ }
+
return frag
}
@@ -50,7 +54,6 @@ export function genChildren(
let offset = 0
let prev: [variable: string, elementIndex: number] | undefined
- const childrenToGen: [IRDynamicInfo, string][] = []
for (const [index, child] of children.entries()) {
if (child.flags & DynamicFlag.NON_TEMPLATE) {
@@ -96,7 +99,7 @@ export function genChildren(
}
}
- if (id === child.anchor) {
+ if (id === child.anchor && !child.hasDynamicChild) {
push(...genSelf(child, context))
}
@@ -105,13 +108,7 @@ export function genChildren(
}
prev = [variable, elementIndex]
- childrenToGen.push([child, variable])
- }
-
- if (childrenToGen.length) {
- for (const [child, from] of childrenToGen) {
- push(...genChildren(child, context, pushBlock, from))
- }
+ push(...genChildren(child, context, pushBlock, variable))
}
return frag