Skip to content

Commit f9d43b9

Browse files
authoredSep 28, 2022
fix(compilre-core): dynamic v-on and static v-on should be merged (#6747)
fix #6742
1 parent cae1aa8 commit f9d43b9

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
 

‎packages/compiler-core/src/transforms/transformElement.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,17 @@ export function buildProps(
668668
// has built-in directive transform.
669669
const { props, needRuntime } = directiveTransform(prop, node, context)
670670
!ssr && props.forEach(analyzePatchFlag)
671-
properties.push(...props)
671+
if (isVOn && arg && !isStaticExp(arg)) {
672+
if (properties.length) {
673+
mergeArgs.push(
674+
createObjectExpression(dedupeProperties(properties), elementLoc)
675+
)
676+
properties = []
677+
}
678+
mergeArgs.push(createObjectExpression(props, elementLoc))
679+
} else {
680+
properties.push(...props)
681+
}
672682
if (needRuntime) {
673683
runtimeDirectives.push(prop)
674684
if (isSymbol(needRuntime)) {

‎packages/compiler-sfc/__tests__/__snapshots__/compileTemplate.spec.ts.snap

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`dynamic v-on + static v-on should merged 1`] = `
4+
"import { toHandlerKey as _toHandlerKey, mergeProps as _mergeProps, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
5+
6+
export function render(_ctx, _cache) {
7+
return (_openBlock(), _createElementBlock(\\"input\\", _mergeProps({
8+
onBlur: _cache[0] || (_cache[0] = (...args) => (_ctx.onBlur && _ctx.onBlur(...args)))
9+
}, {
10+
[_toHandlerKey(_ctx.validateEvent)]: _cache[1] || (_cache[1] = (...args) => (_ctx.onValidateEvent && _ctx.onValidateEvent(...args)))
11+
}), null, 16 /* FULL_PROPS */))
12+
}"
13+
`;
14+
315
exports[`should not hoist srcset URLs in SSR mode 1`] = `
416
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from \\"vue\\"
517
import { ssrRenderAttr as _ssrRenderAttr, ssrRenderComponent as _ssrRenderComponent } from \\"vue/server-renderer\\"

‎packages/compiler-sfc/__tests__/compileTemplate.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,12 @@ test('should not hoist srcset URLs in SSR mode', () => {
174174
})
175175
expect(code).toMatchSnapshot()
176176
})
177+
178+
// #6742
179+
test('dynamic v-on + static v-on should merged', () => {
180+
const source = `<input @blur="onBlur" @[validateEvent]="onValidateEvent">`
181+
182+
const result = compile({ filename: 'example.vue', source })
183+
184+
expect(result.code).toMatchSnapshot()
185+
})

0 commit comments

Comments
 (0)
Please sign in to comment.