( legacyProps: LegacyVNodeProps | undefined, type: any, )
| 177 | ) |
| 178 | |
| 179 | function convertLegacyProps( |
| 180 | legacyProps: LegacyVNodeProps | undefined, |
| 181 | type: any, |
| 182 | ): (Data & VNodeProps) | null { |
| 183 | if (!legacyProps) { |
| 184 | return null |
| 185 | } |
| 186 | |
| 187 | const converted: Data & VNodeProps = {} |
| 188 | |
| 189 | for (const key in legacyProps) { |
| 190 | if (key === 'attrs' || key === 'domProps' || key === 'props') { |
| 191 | extend(converted, legacyProps[key]) |
| 192 | } else if (key === 'on' || key === 'nativeOn') { |
| 193 | const listeners = legacyProps[key] |
| 194 | for (const event in listeners) { |
| 195 | let handlerKey = convertLegacyEventKey(event) |
| 196 | if (key === 'nativeOn') handlerKey += `Native` |
| 197 | const existing = converted[handlerKey] |
| 198 | const incoming = listeners[event] |
| 199 | if (existing !== incoming) { |
| 200 | if (existing) { |
| 201 | converted[handlerKey] = [].concat(existing as any, incoming as any) |
| 202 | } else { |
| 203 | converted[handlerKey] = incoming |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | } else if (!skipLegacyRootLevelProps(key)) { |
| 208 | converted[key] = legacyProps[key as keyof LegacyVNodeProps] |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | if (legacyProps.staticClass) { |
| 213 | converted.class = normalizeClass([legacyProps.staticClass, converted.class]) |
| 214 | } |
| 215 | if (legacyProps.staticStyle) { |
| 216 | converted.style = normalizeStyle([legacyProps.staticStyle, converted.style]) |
| 217 | } |
| 218 | |
| 219 | if (legacyProps.model && isObject(type)) { |
| 220 | // v2 compiled component v-model |
| 221 | const { prop = 'value', event = 'input' } = (type as any).model || {} |
| 222 | converted[prop] = legacyProps.model.value |
| 223 | converted[compatModelEventPrefix + event] = legacyProps.model.callback |
| 224 | } |
| 225 | |
| 226 | return converted |
| 227 | } |
| 228 | |
| 229 | function convertLegacyEventKey(event: string): string { |
| 230 | // normalize v2 event prefixes |
no test coverage detected