Przeglądaj źródła

fix(runtime-vapor): exclude declared emit listeners from attrs (#14753)

Jack 1 miesiąc temu
rodzic
commit
266870357e

+ 23 - 0
packages/runtime-vapor/__tests__/componentAttrs.spec.ts

@@ -505,6 +505,29 @@ describe('attribute fallthrough', () => {
     expect(html()).toBe(`<div></div><div></div>`)
   })
 
+  it('should not warn when only emits is defined', () => {
+    const Parent = {
+      render() {
+        return createComponent(Child, {
+          onBar: () => () => {},
+        })
+      },
+    }
+
+    const Child = defineVaporComponent({
+      emits: ['bar'],
+      render() {
+        const n0 = template('<div></div>')() as Element
+        const n1 = template('<div></div>')() as Element
+
+        return [n0, n1]
+      },
+    })
+
+    define(Parent).render()
+    expect(`Extraneous non-emits event listeners`).not.toHaveBeenWarned()
+  })
+
   it('should not let listener fallthrough when declared in emits (stateful)', () => {
     const Child = defineVaporComponent({
       emits: ['click'],

+ 8 - 7
packages/runtime-vapor/src/componentProps.ts

@@ -124,13 +124,14 @@ export function getPropsProxyHandlers(
           isString(key) && hasOwn(propsOptions, camelize(key))
       : NO
   ) as (key: string | symbol) => key is string
-  const isAttr = propsOptions
-    ? (key: string | symbol) =>
-        isString(key) &&
-        key !== '$' &&
-        !isProp(key) &&
-        !isEmitListener(emitsOptions, key)
-    : (key: string | symbol) => isString(key)
+  const isAttr =
+    propsOptions || emitsOptions
+      ? (key: string | symbol) =>
+          isString(key) &&
+          key !== '$' &&
+          !isProp(key) &&
+          !isEmitListener(emitsOptions, key)
+      : (key: string | symbol) => isString(key)
 
   const getProp = (instance: VaporComponentInstance, key: string | symbol) => {
     // this enables direct watching of props and prevents `Invalid watch source` DEV warnings.