Skip to content

Commit

Permalink
fix(compilre-core): dynamic v-on and static v-on should be merged (#6747
Browse files Browse the repository at this point in the history
)

fix #6742
  • Loading branch information
Dunqing committed Sep 28, 2022
1 parent cae1aa8 commit f9d43b9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/compiler-core/src/transforms/transformElement.ts
Expand Up @@ -668,7 +668,17 @@ export function buildProps(
// has built-in directive transform.
const { props, needRuntime } = directiveTransform(prop, node, context)
!ssr && props.forEach(analyzePatchFlag)
properties.push(...props)
if (isVOn && arg && !isStaticExp(arg)) {
if (properties.length) {
mergeArgs.push(
createObjectExpression(dedupeProperties(properties), elementLoc)
)
properties = []
}
mergeArgs.push(createObjectExpression(props, elementLoc))
} else {
properties.push(...props)
}
if (needRuntime) {
runtimeDirectives.push(prop)
if (isSymbol(needRuntime)) {
Expand Down
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`dynamic v-on + static v-on should merged 1`] = `
"import { toHandlerKey as _toHandlerKey, mergeProps as _mergeProps, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock(\\"input\\", _mergeProps({
onBlur: _cache[0] || (_cache[0] = (...args) => (_ctx.onBlur && _ctx.onBlur(...args)))
}, {
[_toHandlerKey(_ctx.validateEvent)]: _cache[1] || (_cache[1] = (...args) => (_ctx.onValidateEvent && _ctx.onValidateEvent(...args)))
}), null, 16 /* FULL_PROPS */))
}"
`;

exports[`should not hoist srcset URLs in SSR mode 1`] = `
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from \\"vue\\"
import { ssrRenderAttr as _ssrRenderAttr, ssrRenderComponent as _ssrRenderComponent } from \\"vue/server-renderer\\"
Expand Down
9 changes: 9 additions & 0 deletions packages/compiler-sfc/__tests__/compileTemplate.spec.ts
Expand Up @@ -174,3 +174,12 @@ test('should not hoist srcset URLs in SSR mode', () => {
})
expect(code).toMatchSnapshot()
})

// #6742
test('dynamic v-on + static v-on should merged', () => {
const source = `<input @blur="onBlur" @[validateEvent]="onValidateEvent">`

const result = compile({ filename: 'example.vue', source })

expect(result.code).toMatchSnapshot()
})

0 comments on commit f9d43b9

Please sign in to comment.