(vnode: VNode)
| 15 | const warnedTypes = new WeakSet() |
| 16 | |
| 17 | export function convertLegacyVModelProps(vnode: VNode): void { |
| 18 | const { type, shapeFlag, props, dynamicProps } = vnode |
| 19 | const comp = type as ComponentOptions |
| 20 | if (shapeFlag & ShapeFlags.COMPONENT && props && 'modelValue' in props) { |
| 21 | if ( |
| 22 | !isCompatEnabled( |
| 23 | DeprecationTypes.COMPONENT_V_MODEL, |
| 24 | // this is a special case where we want to use the vnode component's |
| 25 | // compat config instead of the current rendering instance (which is the |
| 26 | // parent of the component that exposes v-model) |
| 27 | { type } as any, |
| 28 | ) |
| 29 | ) { |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | if (__DEV__ && !warnedTypes.has(comp)) { |
| 34 | pushWarningContext(vnode) |
| 35 | warnDeprecation( |
| 36 | DeprecationTypes.COMPONENT_V_MODEL, |
| 37 | { |
| 38 | type, |
| 39 | appContext: (vnode.ctx && vnode.ctx.appContext) || createAppContext(), |
| 40 | } as any, |
| 41 | comp, |
| 42 | ) |
| 43 | popWarningContext() |
| 44 | warnedTypes.add(comp) |
| 45 | } |
| 46 | |
| 47 | // v3 compiled model code -> v2 compat props |
| 48 | // modelValue -> value |
| 49 | // onUpdate:modelValue -> onModelCompat:input |
| 50 | const model = comp.model || {} |
| 51 | applyModelFromMixins(model, comp.mixins) |
| 52 | const { prop = 'value', event = 'input' } = model |
| 53 | if (prop !== 'modelValue') { |
| 54 | props[prop] = props.modelValue |
| 55 | delete props.modelValue |
| 56 | } |
| 57 | // important: update dynamic props |
| 58 | if (dynamicProps) { |
| 59 | dynamicProps[dynamicProps.indexOf('modelValue')] = prop |
| 60 | } |
| 61 | props[compatModelEventPrefix + event] = props['onUpdate:modelValue'] |
| 62 | delete props['onUpdate:modelValue'] |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | function applyModelFromMixins(model: any, mixins?: ComponentOptions[]) { |
| 67 | if (mixins) { |
no test coverage detected