Skip to content

Commit c1f2289

Browse files
authored
fix(compiler-vapor): handle boolean as constant node (#13994)
1 parent 4b9399a commit c1f2289

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function render(_ctx) {
4242
const n2 = _createComponentWithFallback(_component_Bar)
4343
_withVaporDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]])
4444
return n3
45-
})
45+
}, null, true)
4646
return n0
4747
})
4848
}, true)
@@ -230,7 +230,7 @@ export function render(_ctx) {
230230
const n1 = _createIf(() => (true), () => {
231231
const n3 = t0()
232232
return n3
233-
})
233+
}, null, true)
234234
_renderEffect(() => _setProp(n4, "disabled", _ctx.foo))
235235
return n6
236236
}"

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformTemplateRef.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function render(_ctx) {
5858
const n2 = t0()
5959
_setTemplateRef(n2, "foo")
6060
return n2
61-
})
61+
}, null, true)
6262
return n0
6363
}"
6464
`;

packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ export function render(_ctx) {
110110
}, () => _createIf(() => (_ctx.orNot), () => {
111111
const n4 = t1()
112112
return n4
113-
}, () => {
114-
const n7 = t2()
113+
}, () => _createIf(() => (false), () => {
114+
const n7 = t1()
115115
return n7
116-
}))
116+
}, () => {
117+
const n10 = t2()
118+
return n10
119+
}, true)))
117120
return n0
118121
}"
119122
`;

packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export function render(_ctx) {
356356
}, () => {
357357
const n5 = _createComponentWithFallback(_component_Bar)
358358
return n5
359-
})
359+
}, true)
360360
return n6
361361
}"
362362
`;

packages/compiler-vapor/__tests__/transforms/vIf.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe('compiler: v-if', () => {
182182

183183
test('v-if + v-else-if + v-else', () => {
184184
const { code, ir } = compileWithVIf(
185-
`<div v-if="ok"/><p v-else-if="orNot"/><template v-else>fine</template>`,
185+
`<div v-if="ok"/><p v-else-if="orNot"/><p v-else-if="false"/><template v-else>fine</template>`,
186186
)
187187
expect(code).matchSnapshot()
188188
expect(ir.template).toEqual(['<div></div>', '<p></p>', 'fine'])
@@ -206,9 +206,12 @@ describe('compiler: v-if', () => {
206206
},
207207
},
208208
negative: {
209-
type: IRNodeTypes.BLOCK,
210-
dynamic: {
211-
children: [{ template: 2 }],
209+
type: IRNodeTypes.IF,
210+
negative: {
211+
type: IRNodeTypes.BLOCK,
212+
dynamic: {
213+
children: [{ template: 2 }],
214+
},
212215
},
213216
},
214217
},

packages/compiler-vapor/src/transforms/vIf.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ export function processIf(
119119
id: -1,
120120
condition: dir.exp!,
121121
positive: branch,
122-
once: context.inVOnce,
122+
once:
123+
context.inVOnce ||
124+
isStaticExpression(dir.exp!, context.options.bindingMetadata),
123125
}
124126
}
125127

packages/compiler-vapor/src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ export function isStaticExpression(
5555
if (node.ast) {
5656
return isConstantNode(node.ast, bindings)
5757
} else if (node.ast === null) {
58+
if (
59+
!node.isStatic &&
60+
(node.content === 'true' || node.content === 'false')
61+
) {
62+
return true
63+
}
5864
const type = bindings[node.content]
5965
return type === BindingTypes.LITERAL_CONST
6066
}

0 commit comments

Comments
 (0)