( comp: ConcreteComponent, appContext: AppContext, asMixin = false, )
| 236 | |
| 237 | const mixinEmitsCache = new WeakMap<ConcreteComponent, ObjectEmitsOptions>() |
| 238 | export function normalizeEmitsOptions( |
| 239 | comp: ConcreteComponent, |
| 240 | appContext: AppContext, |
| 241 | asMixin = false, |
| 242 | ): ObjectEmitsOptions | null { |
| 243 | const cache = |
| 244 | __FEATURE_OPTIONS_API__ && asMixin ? mixinEmitsCache : appContext.emitsCache |
| 245 | const cached = cache.get(comp) |
| 246 | if (cached !== undefined) { |
| 247 | return cached |
| 248 | } |
| 249 | |
| 250 | const raw = comp.emits |
| 251 | let normalized: ObjectEmitsOptions = {} |
| 252 | |
| 253 | // apply mixin/extends props |
| 254 | let hasExtends = false |
| 255 | if (__FEATURE_OPTIONS_API__ && !isFunction(comp)) { |
| 256 | const extendEmits = (raw: ComponentOptions) => { |
| 257 | const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true) |
| 258 | if (normalizedFromExtend) { |
| 259 | hasExtends = true |
| 260 | extend(normalized, normalizedFromExtend) |
| 261 | } |
| 262 | } |
| 263 | if (!asMixin && appContext.mixins.length) { |
| 264 | appContext.mixins.forEach(extendEmits) |
| 265 | } |
| 266 | if (comp.extends) { |
| 267 | extendEmits(comp.extends) |
| 268 | } |
| 269 | if (comp.mixins) { |
| 270 | comp.mixins.forEach(extendEmits) |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | if (!raw && !hasExtends) { |
| 275 | if (isObject(comp)) { |
| 276 | cache.set(comp, null) |
| 277 | } |
| 278 | return null |
| 279 | } |
| 280 | |
| 281 | if (isArray(raw)) { |
| 282 | raw.forEach(key => (normalized[key] = null)) |
| 283 | } else { |
| 284 | extend(normalized, raw) |
| 285 | } |
| 286 | |
| 287 | if (isObject(comp)) { |
| 288 | cache.set(comp, normalized) |
| 289 | } |
| 290 | return normalized |
| 291 | } |
| 292 | |
| 293 | // Check if an incoming prop key is a declared emit event listener. |
| 294 | // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are |
no test coverage detected