Skip to content

Commit 5bfe438

Browse files
authored
fix(compiler-core/v-on): only apply case preservation on native elements (#6902)
fix #6900
1 parent 910fa76 commit 5bfe438

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

packages/compiler-core/__tests__/transforms/vSlot.spec.ts

+52-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
VNodeCall,
1212
SlotsExpression,
1313
ObjectExpression,
14-
SimpleExpressionNode
14+
SimpleExpressionNode,
15+
RenderSlotCall
1516
} from '../../src'
1617
import { transformElement } from '../../src/transforms/transformElement'
1718
import { transformOn } from '../../src/transforms/vOn'
@@ -788,6 +789,56 @@ describe('compiler: transform component slots', () => {
788789
const { slots } = parseWithSlots(`<Comp><Comp><slot/></Comp></Comp>`)
789790
expect(slots).toMatchObject(toMatch)
790791
})
792+
793+
// # fix: #6900
794+
test('consistent behavior of @xxx:modelValue and @xxx:model-value', () => {
795+
const { root: rootUpper } = parseWithSlots(
796+
`<div><slot @foo:modelValue="handler" /></div>`
797+
)
798+
const slotNodeUpper = (rootUpper.codegenNode! as VNodeCall)
799+
.children as ElementNode[]
800+
const propertiesObjUpper = (
801+
slotNodeUpper[0].codegenNode! as RenderSlotCall
802+
).arguments[2]
803+
expect(propertiesObjUpper).toMatchObject({
804+
properties: [
805+
{
806+
key: {
807+
type: NodeTypes.SIMPLE_EXPRESSION,
808+
content: 'onFoo:modelValue'
809+
},
810+
value: {
811+
type: NodeTypes.SIMPLE_EXPRESSION,
812+
content: `handler`,
813+
isStatic: false
814+
}
815+
}
816+
]
817+
})
818+
819+
const { root } = parseWithSlots(
820+
`<div><slot @foo:model-Value="handler" /></div>`
821+
)
822+
const slotNode = (root.codegenNode! as VNodeCall)
823+
.children as ElementNode[]
824+
const propertiesObj = (slotNode[0].codegenNode! as RenderSlotCall)
825+
.arguments[2]
826+
expect(propertiesObj).toMatchObject({
827+
properties: [
828+
{
829+
key: {
830+
type: NodeTypes.SIMPLE_EXPRESSION,
831+
content: 'onFoo:modelValue'
832+
},
833+
value: {
834+
type: NodeTypes.SIMPLE_EXPRESSION,
835+
content: `handler`,
836+
isStatic: false
837+
}
838+
}
839+
]
840+
})
841+
})
791842
})
792843

793844
describe('errors', () => {

packages/compiler-core/src/transforms/vOn.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export const transformOn: DirectiveTransform = (
4848
rawName = `vnode-${rawName.slice(4)}`
4949
}
5050
const eventString =
51-
node.tagType === ElementTypes.COMPONENT ||
51+
node.tagType !== ElementTypes.ELEMENT ||
5252
rawName.startsWith('vnode') ||
5353
!/[A-Z]/.test(rawName)
54-
? // for component and vnode lifecycle event listeners, auto convert
54+
? // for non-element and vnode lifecycle event listeners, auto convert
5555
// it to camelCase. See issue #2249
5656
toHandlerKey(camelize(rawName))
5757
: // preserve case for plain element listeners that have uppercase

0 commit comments

Comments
 (0)