@@ -397,7 +397,10 @@ export function injectProp(
397
397
// if doesn't override user provided keys
398
398
const first = props . arguments [ 0 ] as string | JSChildNode
399
399
if ( ! isString ( first ) && first . type === NodeTypes . JS_OBJECT_EXPRESSION ) {
400
- first . properties . unshift ( prop )
400
+ // #6631
401
+ if ( ! hasProp ( prop , first ) ) {
402
+ first . properties . unshift ( prop )
403
+ }
401
404
} else {
402
405
if ( props . callee === TO_HANDLERS ) {
403
406
// #2366
@@ -411,17 +414,7 @@ export function injectProp(
411
414
}
412
415
! propsWithInjection && ( propsWithInjection = props )
413
416
} else if ( props . type === NodeTypes . JS_OBJECT_EXPRESSION ) {
414
- let alreadyExists = false
415
- // check existing key to avoid overriding user provided keys
416
- if ( prop . key . type === NodeTypes . SIMPLE_EXPRESSION ) {
417
- const propKeyName = prop . key . content
418
- alreadyExists = props . properties . some (
419
- p =>
420
- p . key . type === NodeTypes . SIMPLE_EXPRESSION &&
421
- p . key . content === propKeyName
422
- )
423
- }
424
- if ( ! alreadyExists ) {
417
+ if ( ! hasProp ( prop , props ) ) {
425
418
props . properties . unshift ( prop )
426
419
}
427
420
propsWithInjection = props
@@ -453,6 +446,20 @@ export function injectProp(
453
446
}
454
447
}
455
448
449
+ // check existing key to avoid overriding user provided keys
450
+ function hasProp ( prop : Property , props : ObjectExpression ) {
451
+ let result = false
452
+ if ( prop . key . type === NodeTypes . SIMPLE_EXPRESSION ) {
453
+ const propKeyName = prop . key . content
454
+ result = props . properties . some (
455
+ p =>
456
+ p . key . type === NodeTypes . SIMPLE_EXPRESSION &&
457
+ p . key . content === propKeyName
458
+ )
459
+ }
460
+ return result
461
+ }
462
+
456
463
export function toValidAssetId (
457
464
name : string ,
458
465
type : 'component' | 'directive' | 'filter'
0 commit comments