( node: VNodeCall | RenderSlotCall, prop: Property, context: TransformContext, )
| 388 | return [props, callPath] |
| 389 | } |
| 390 | export function injectProp( |
| 391 | node: VNodeCall | RenderSlotCall, |
| 392 | prop: Property, |
| 393 | context: TransformContext, |
| 394 | ): void { |
| 395 | let propsWithInjection: ObjectExpression | CallExpression | undefined |
| 396 | /** |
| 397 | * 1. mergeProps(...) |
| 398 | * 2. toHandlers(...) |
| 399 | * 3. normalizeProps(...) |
| 400 | * 4. normalizeProps(guardReactiveProps(...)) |
| 401 | * |
| 402 | * we need to get the real props before normalization |
| 403 | */ |
| 404 | let props = |
| 405 | node.type === NodeTypes.VNODE_CALL ? node.props : node.arguments[2] |
| 406 | let callPath: CallExpression[] = [] |
| 407 | let parentCall: CallExpression | undefined |
| 408 | if ( |
| 409 | props && |
| 410 | !isString(props) && |
| 411 | props.type === NodeTypes.JS_CALL_EXPRESSION |
| 412 | ) { |
| 413 | const ret = getUnnormalizedProps(props) |
| 414 | props = ret[0] |
| 415 | callPath = ret[1] |
| 416 | parentCall = callPath[callPath.length - 1] |
| 417 | } |
| 418 | |
| 419 | if (props == null || isString(props)) { |
| 420 | propsWithInjection = createObjectExpression([prop]) |
| 421 | } else if (props.type === NodeTypes.JS_CALL_EXPRESSION) { |
| 422 | // merged props... add ours |
| 423 | // only inject key to object literal if it's the first argument so that |
| 424 | // if doesn't override user provided keys |
| 425 | const first = props.arguments[0] as string | JSChildNode |
| 426 | if (!isString(first) && first.type === NodeTypes.JS_OBJECT_EXPRESSION) { |
| 427 | // #6631 |
| 428 | if (!hasProp(prop, first)) { |
| 429 | first.properties.unshift(prop) |
| 430 | } |
| 431 | } else { |
| 432 | if (props.callee === TO_HANDLERS) { |
| 433 | // #2366 |
| 434 | propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [ |
| 435 | createObjectExpression([prop]), |
| 436 | props, |
| 437 | ]) |
| 438 | } else { |
| 439 | props.arguments.unshift(createObjectExpression([prop])) |
| 440 | } |
| 441 | } |
| 442 | !propsWithInjection && (propsWithInjection = props) |
| 443 | } else if (props.type === NodeTypes.JS_OBJECT_EXPRESSION) { |
| 444 | if (!hasProp(prop, props)) { |
| 445 | props.properties.unshift(prop) |
| 446 | } |
| 447 | propsWithInjection = props |
no test coverage detected