فهرست منبع

fix(runtime-vapor): skip nullish dynamic emit sources

daiwei 1 روز پیش
والد
کامیت
ffd671c833
2فایلهای تغییر یافته به همراه19 افزوده شده و 2 حذف شده
  1. 18 1
      packages/runtime-vapor/__tests__/componentEmits.spec.ts
  2. 1 1
      packages/runtime-vapor/src/componentEmits.ts

+ 18 - 1
packages/runtime-vapor/__tests__/componentEmits.spec.ts

@@ -16,7 +16,7 @@ import {
   defineVaporComponent,
   template,
 } from '../src'
-import { makeRender } from './_utils'
+import { compile, makeRender } from './_utils'
 
 const define = makeRender()
 
@@ -67,6 +67,23 @@ describe('component: emit', () => {
     expect(onBaz).toHaveBeenCalled()
   })
 
+  test('should ignore nullish object v-bind sources when emitting', () => {
+    const Child = defineVaporComponent({
+      emits: ['ready'],
+      setup(_, { emit }) {
+        emit('ready')
+        return []
+      },
+    })
+    const Parent = compile(
+      `<template><components.Child v-bind="data.attrs" /></template>`,
+      ref({ attrs: null }),
+      { Child },
+    )
+
+    expect(() => define(Parent).render()).not.toThrow()
+  })
+
   test('trigger camelCase handler', () => {
     const { render } = define({
       setup(_, { emit }) {

+ 1 - 1
packages/runtime-vapor/src/componentEmits.ts

@@ -47,7 +47,7 @@ function propGetter(rawProps: RawProps, key: string) {
     let i = dynamicSources.length
     while (i--) {
       const source = resolveSource(dynamicSources[i])
-      if (hasOwn(source, key))
+      if (source && hasOwn(source, key))
         // for props passed from VDOM component, no need to resolve
         return (isInteropEnabled && dynamicSources[interopKey]) ||
           (isOn(key) && isFunction(dynamicSources[i]))