]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compat): copy additional properties for functions bound via globalProperties...
authorThorsten Lünborg <t.luenborg@googlemail.com>
Wed, 13 Apr 2022 09:53:07 +0000 (11:53 +0200)
committerGitHub <noreply@github.com>
Wed, 13 Apr 2022 09:53:07 +0000 (05:53 -0400)
close #4403

packages/runtime-core/src/componentPublicInstance.ts
packages/vue-compat/__tests__/global.spec.ts

index c2d36e7715100a1a44d8c5a32f5816f2298e7148..018187fc64276868d9cf0acfe902ca040f72024a 100644 (file)
@@ -356,7 +356,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
           return desc.get.call(instance.proxy)
         } else {
           const val = globalProperties[key]
-          return isFunction(val) ? val.bind(instance.proxy) : val
+          return isFunction(val)
+            ? Object.assign(val.bind(instance.proxy), val)
+            : val
         }
       } else {
         return globalProperties[key]
index 86bb4391092829b49a7ee3d785ed24ec537727fa..06109a67f646ad2088e11607c7274b3fdfc61276 100644 (file)
@@ -285,6 +285,28 @@ describe('GLOBAL_PROTOTYPE', () => {
     delete Vue.prototype.$test
   })
 
+  test.only('functions keeps additional properties', () => {
+    function test(this: any) {
+      return this.msg
+    }
+    test.additionalFn = () => {
+      return 'additional fn'
+    }
+
+    Vue.prototype.$test = test
+    const vm = new Vue({
+      data() {
+        return {
+          msg: 'test'
+        }
+      }
+    }) as any
+    expect(typeof vm.$test).toBe('function')
+    expect(typeof vm.$test.additionalFn).toBe('function')
+    expect(vm.$test.additionalFn()).toBe('additional fn')
+    delete Vue.prototype.$test
+  })
+
   test('extended prototype', async () => {
     const Foo = Vue.extend()
     Foo.prototype.$test = 1