Skip to content

Commit 313d172

Browse files
authored
fix(compiler-vapor): prevent _camelize from receiving nullish value for dynamic v-bind keys with .camel modifier. (#14138)
1 parent 74a8bae commit 313d172

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,24 @@ export function render(_ctx) {
361361
}"
362362
`;
363363
364+
exports[`compiler v-bind > .camel modifier w/ dynamic arg + prefixIdentifiers 1`] = `
365+
"import { camelize as _camelize, setDynamicProps as _setDynamicProps, renderEffect as _renderEffect, template as _template } from 'vue';
366+
const t0 = _template("<div></div>", true)
367+
368+
export function render(_ctx) {
369+
const n0 = t0()
370+
_renderEffect(() => _setDynamicProps(n0, [{ [_camelize(_ctx.foo(_ctx.bar) || "")]: _ctx.id }]))
371+
return n0
372+
}"
373+
`;
374+
364375
exports[`compiler v-bind > .camel modifier w/ dynamic arg 1`] = `
365376
"import { camelize as _camelize, setDynamicProps as _setDynamicProps, renderEffect as _renderEffect, template as _template } from 'vue';
366377
const t0 = _template("<div></div>", true)
367378
368379
export function render(_ctx) {
369380
const n0 = t0()
370-
_renderEffect(() => _setDynamicProps(n0, [{ [_camelize(_ctx.foo)]: _ctx.id }]))
381+
_renderEffect(() => _setDynamicProps(n0, [{ [_camelize(_ctx.foo || "")]: _ctx.id }]))
371382
return n0
372383
}"
373384
`;

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,40 @@ describe('compiler v-bind', () => {
341341
expect(code).matchSnapshot()
342342
expect(code).contains('renderEffect')
343343
expect(code).contains(
344-
`_setDynamicProps(n0, [{ [_camelize(_ctx.foo)]: _ctx.id }])`,
344+
`_setDynamicProps(n0, [{ [_camelize(_ctx.foo || "")]: _ctx.id }])`,
345345
)
346346
})
347347

348-
test.todo('.camel modifier w/ dynamic arg + prefixIdentifiers')
348+
test('.camel modifier w/ dynamic arg + prefixIdentifiers', () => {
349+
const { ir, code } = compileWithVBind(
350+
`<div v-bind:[foo(bar)].camel="id"/>`,
351+
{
352+
prefixIdentifiers: true,
353+
},
354+
)
355+
expect(code).matchSnapshot()
356+
expect(ir.block.effect[0].operations[0]).toMatchObject({
357+
type: IRNodeTypes.SET_DYNAMIC_PROPS,
358+
props: [
359+
[
360+
{
361+
key: {
362+
content: `foo(bar)`,
363+
isStatic: false,
364+
},
365+
values: [
366+
{
367+
content: `id`,
368+
isStatic: false,
369+
},
370+
],
371+
runtimeCamelize: true,
372+
modifier: undefined,
373+
},
374+
],
375+
],
376+
})
377+
})
349378

350379
test('.prop modifier', () => {
351380
const { ir, code } = compileWithVBind(`<div v-bind:fooBar.prop="id"/>`)

packages/compiler-vapor/src/generators/prop.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export function genPropKey(
138138

139139
let key = genExpression(node, context)
140140
if (runtimeCamelize) {
141+
key.push(' || ""')
141142
key = genCall(helper('camelize'), key)
142143
}
143144
if (handler) {

0 commit comments

Comments
 (0)