]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix erraneous emits warnings w/ mixins
authorEvan You <yyx990803@gmail.com>
Fri, 26 Mar 2021 20:29:40 +0000 (16:29 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 26 Mar 2021 20:29:40 +0000 (16:29 -0400)
fix #2651

packages/runtime-core/__tests__/componentEmits.spec.ts
packages/runtime-core/src/componentEmits.ts

index 1eb216d9f098e73b3f3327e9d2187a6b834ee713..a02cbb880c13e90817e6fa67faad3de0e7105e76 100644 (file)
@@ -175,6 +175,21 @@ describe('component: emit', () => {
     expect(`event validation failed for event "foo"`).toHaveBeenWarned()
   })
 
+  // #2651
+  test('should not attach normalized object when mixins do not contain emits', () => {
+    const Foo = defineComponent({
+      mixins: [{}],
+      render() {},
+      created() {
+        this.$emit('foo')
+      }
+    })
+    render(h(Foo), nodeOps.createElement('div'))
+    expect(
+      `Component emitted event "foo" but it is neither declared`
+    ).not.toHaveBeenWarned()
+  })
+
   test('.once', () => {
     const Foo = defineComponent({
       render() {},
index 81af34e6708905028d1ed3b874708dd017dda188..6d6ca4aaed87afe5e598bbbca8c001a860ec9063 100644 (file)
@@ -165,8 +165,11 @@ export function normalizeEmitsOptions(
   let hasExtends = false
   if (__FEATURE_OPTIONS_API__ && !isFunction(comp)) {
     const extendEmits = (raw: ComponentOptions) => {
-      hasExtends = true
-      extend(normalized, normalizeEmitsOptions(raw, appContext, true))
+      const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true)
+      if (normalizedFromExtend) {
+        hasExtends = true
+        extend(normalized, normalizedFromExtend)
+      }
     }
     if (!asMixin && appContext.mixins.length) {
       appContext.mixins.forEach(extendEmits)