Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(compiler-core/v-on): only apply case preservation on native eleme…
…nts (#6902)

fix #6900
  • Loading branch information
baiwusanyu-c committed Nov 9, 2022
1 parent 910fa76 commit 5bfe438
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
53 changes: 52 additions & 1 deletion packages/compiler-core/__tests__/transforms/vSlot.spec.ts
Expand Up @@ -11,7 +11,8 @@ import {
VNodeCall,
SlotsExpression,
ObjectExpression,
SimpleExpressionNode
SimpleExpressionNode,
RenderSlotCall
} from '../../src'
import { transformElement } from '../../src/transforms/transformElement'
import { transformOn } from '../../src/transforms/vOn'
Expand Down Expand Up @@ -788,6 +789,56 @@ describe('compiler: transform component slots', () => {
const { slots } = parseWithSlots(`<Comp><Comp><slot/></Comp></Comp>`)
expect(slots).toMatchObject(toMatch)
})

// # fix: #6900
test('consistent behavior of @xxx:modelValue and @xxx:model-value', () => {
const { root: rootUpper } = parseWithSlots(
`<div><slot @foo:modelValue="handler" /></div>`
)
const slotNodeUpper = (rootUpper.codegenNode! as VNodeCall)
.children as ElementNode[]
const propertiesObjUpper = (
slotNodeUpper[0].codegenNode! as RenderSlotCall
).arguments[2]
expect(propertiesObjUpper).toMatchObject({
properties: [
{
key: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'onFoo:modelValue'
},
value: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `handler`,
isStatic: false
}
}
]
})

const { root } = parseWithSlots(
`<div><slot @foo:model-Value="handler" /></div>`
)
const slotNode = (root.codegenNode! as VNodeCall)
.children as ElementNode[]
const propertiesObj = (slotNode[0].codegenNode! as RenderSlotCall)
.arguments[2]
expect(propertiesObj).toMatchObject({
properties: [
{
key: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'onFoo:modelValue'
},
value: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `handler`,
isStatic: false
}
}
]
})
})
})

describe('errors', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transforms/vOn.ts
Expand Up @@ -48,10 +48,10 @@ export const transformOn: DirectiveTransform = (
rawName = `vnode-${rawName.slice(4)}`
}
const eventString =
node.tagType === ElementTypes.COMPONENT ||
node.tagType !== ElementTypes.ELEMENT ||
rawName.startsWith('vnode') ||
!/[A-Z]/.test(rawName)
? // for component and vnode lifecycle event listeners, auto convert
? // for non-element and vnode lifecycle event listeners, auto convert
// it to camelCase. See issue #2249
toHandlerKey(camelize(rawName))
: // preserve case for plain element listeners that have uppercase
Expand Down

0 comments on commit 5bfe438

Please sign in to comment.