Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-core):Make sure update:modelValue and update:model-value behave the same on slot #6902

Merged
merged 20 commits into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9cb32d8
fix(compiler-core):consistent behavior of @update:modelValue and @upd…
Oct 18, 2022
1807ed9
fix(compiler-core): update
Oct 18, 2022
4abb522
fix(compiler-core): added code comments
Oct 18, 2022
3694df4
fix(compiler-core):avoid removing/adding empty linves
baiwusanyu-c Oct 18, 2022
563ef08
fix(compiler-core):update
baiwusanyu-c Oct 18, 2022
73bd5a1
fix(compiler-core):added code comments
baiwusanyu-c Oct 18, 2022
22150c9
fix(compiler-core): format code
Oct 19, 2022
d3de83a
fix(compiler-core): move unit test
Oct 19, 2022
b4a559a
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Oct 21, 2022
87d9b8f
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Oct 25, 2022
42fbc16
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Oct 26, 2022
8e17471
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Oct 26, 2022
84989d5
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Oct 29, 2022
c170254
Update packages/compiler-core/src/transforms/vOn.ts
baiwusanyu-c Oct 29, 2022
211cd06
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Nov 1, 2022
b956d94
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Nov 8, 2022
20d9ca3
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Nov 8, 2022
f065f6a
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Nov 8, 2022
f761224
Merge branch 'vuejs:main' into bwsy/fix/modelvalue
baiwusanyu-c Nov 8, 2022
ad4df71
Update vOn.ts
yyx990803 Nov 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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