Skip to content

Commit f402d41

Browse files
committed
refactor(compiler-core): extract props merging helper
1 parent f9d43b9 commit f402d41

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

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

+16-19
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,16 @@ export function buildProps(
413413
let hasVnodeHook = false
414414
const dynamicPropNames: string[] = []
415415

416+
const pushMergeArg = (arg?: PropsExpression) => {
417+
if (properties.length) {
418+
mergeArgs.push(
419+
createObjectExpression(dedupeProperties(properties), elementLoc)
420+
)
421+
properties = []
422+
}
423+
if (arg) mergeArgs.push(arg)
424+
}
425+
416426
const analyzePatchFlag = ({ key, value }: Property) => {
417427
if (isStaticExp(key)) {
418428
const name = key.content
@@ -590,13 +600,9 @@ export function buildProps(
590600
if (!arg && (isVBind || isVOn)) {
591601
hasDynamicKeys = true
592602
if (exp) {
593-
if (properties.length) {
594-
mergeArgs.push(
595-
createObjectExpression(dedupeProperties(properties), elementLoc)
596-
)
597-
properties = []
598-
}
599603
if (isVBind) {
604+
// have to merge early for compat build check
605+
pushMergeArg()
600606
if (__COMPAT__) {
601607
// 2.x v-bind object order compat
602608
if (__DEV__) {
@@ -643,7 +649,7 @@ export function buildProps(
643649
mergeArgs.push(exp)
644650
} else {
645651
// v-on="obj" -> toHandlers(obj)
646-
mergeArgs.push({
652+
pushMergeArg({
647653
type: NodeTypes.JS_CALL_EXPRESSION,
648654
loc,
649655
callee: context.helper(TO_HANDLERS),
@@ -669,13 +675,7 @@ export function buildProps(
669675
const { props, needRuntime } = directiveTransform(prop, node, context)
670676
!ssr && props.forEach(analyzePatchFlag)
671677
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))
678+
pushMergeArg(createObjectExpression(props, elementLoc))
679679
} else {
680680
properties.push(...props)
681681
}
@@ -701,11 +701,8 @@ export function buildProps(
701701

702702
// has v-bind="object" or v-on="object", wrap with mergeProps
703703
if (mergeArgs.length) {
704-
if (properties.length) {
705-
mergeArgs.push(
706-
createObjectExpression(dedupeProperties(properties), elementLoc)
707-
)
708-
}
704+
// close up any not-yet-merged props
705+
pushMergeArg()
709706
if (mergeArgs.length > 1) {
710707
propsExpression = createCallExpression(
711708
context.helper(MERGE_PROPS),

0 commit comments

Comments
 (0)