diff --git a/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap b/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap index 62465315737..c681811dd93 100644 --- a/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap @@ -42,7 +42,7 @@ export function render(_ctx) { const n2 = _createComponentWithFallback(_component_Bar) _withVaporDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]]) return n3 - }) + }, null, true) return n0 }) }, true) @@ -230,7 +230,7 @@ export function render(_ctx) { const n1 = _createIf(() => (true), () => { const n3 = t0() return n3 - }) + }, null, true) _renderEffect(() => _setProp(n4, "disabled", _ctx.foo)) return n6 }" diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snap index 15db96b6ace..851c529bd06 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snap @@ -58,7 +58,7 @@ export function render(_ctx) { const n2 = t0() _setTemplateRef(n2, "foo") return n2 - }) + }, null, true) return n0 }" `; diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap index a8dc5aa4590..0d6e13301c8 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap @@ -110,10 +110,13 @@ export function render(_ctx) { }, () => _createIf(() => (_ctx.orNot), () => { const n4 = t1() return n4 - }, () => { - const n7 = t2() + }, () => _createIf(() => (false), () => { + const n7 = t1() return n7 - })) + }, () => { + const n10 = t2() + return n10 + }, true))) return n0 }" `; diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap index 1cca9e6bb2a..9b66bb6c869 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap @@ -356,7 +356,7 @@ export function render(_ctx) { }, () => { const n5 = _createComponentWithFallback(_component_Bar) return n5 - }) + }, true) return n6 }" `; diff --git a/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts b/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts index e5fd61add2e..6a8148b7c18 100644 --- a/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/vIf.spec.ts @@ -182,7 +182,7 @@ describe('compiler: v-if', () => { test('v-if + v-else-if + v-else', () => { const { code, ir } = compileWithVIf( - `

`, + `

`, ) expect(code).matchSnapshot() expect(ir.template).toEqual(['

', '

', 'fine']) @@ -206,9 +206,12 @@ describe('compiler: v-if', () => { }, }, negative: { - type: IRNodeTypes.BLOCK, - dynamic: { - children: [{ template: 2 }], + type: IRNodeTypes.IF, + negative: { + type: IRNodeTypes.BLOCK, + dynamic: { + children: [{ template: 2 }], + }, }, }, }, diff --git a/packages/compiler-vapor/src/transforms/vIf.ts b/packages/compiler-vapor/src/transforms/vIf.ts index 531d29b055c..f6fed605f3a 100644 --- a/packages/compiler-vapor/src/transforms/vIf.ts +++ b/packages/compiler-vapor/src/transforms/vIf.ts @@ -119,7 +119,9 @@ export function processIf( id: -1, condition: dir.exp!, positive: branch, - once: context.inVOnce, + once: + context.inVOnce || + isStaticExpression(dir.exp!, context.options.bindingMetadata), } } diff --git a/packages/compiler-vapor/src/utils.ts b/packages/compiler-vapor/src/utils.ts index 955273b1eda..2f40d4ecd72 100644 --- a/packages/compiler-vapor/src/utils.ts +++ b/packages/compiler-vapor/src/utils.ts @@ -56,6 +56,12 @@ export function isStaticExpression( if (node.ast) { return isConstantNode(node.ast, bindings) } else if (node.ast === null) { + if ( + !node.isStatic && + (node.content === 'true' || node.content === 'false') + ) { + return true + } const type = bindings[node.content] return type === BindingTypes.LITERAL_CONST }