]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(provide): support symbols in applyOptions (#2616)
authorhiroki <hiroki.osame@gmail.com>
Mon, 30 Nov 2020 21:36:02 +0000 (16:36 -0500)
committerGitHub <noreply@github.com>
Mon, 30 Nov 2020 21:36:02 +0000 (16:36 -0500)
fix #2615

packages/runtime-core/__tests__/apiOptions.spec.ts
packages/runtime-core/src/apiInject.ts
packages/runtime-core/src/componentOptions.ts

index ab60ac7ca8275c02693e36d7e8437f9c6ee2657e..d60842db450bf03356be755a09471fb3e4c20ef6 100644 (file)
@@ -251,6 +251,7 @@ describe('api: options', () => {
   })
 
   test('provide/inject', () => {
+    const symbolKey = Symbol()
     const Root = defineComponent({
       data() {
         return {
@@ -259,7 +260,8 @@ describe('api: options', () => {
       },
       provide() {
         return {
-          a: this.a
+          a: this.a,
+          [symbolKey]: 2
         }
       },
       render() {
@@ -271,7 +273,9 @@ describe('api: options', () => {
           h(ChildE),
           h(ChildF),
           h(ChildG),
-          h(ChildH)
+          h(ChildH),
+          h(ChildI),
+          h(ChildJ)
         ]
       }
     })
@@ -321,7 +325,15 @@ describe('api: options', () => {
         default: () => 5
       }
     })
-    expect(renderToString(h(Root))).toBe(`11112345`)
+    const ChildI = defineChild({
+      b: symbolKey
+    })
+    const ChildJ = defineChild({
+      b: {
+        from: symbolKey
+      }
+    })
+    expect(renderToString(h(Root))).toBe(`1111234522`)
   })
 
   test('provide accessing data in extends', () => {
index 186b411b24148f38e0df9515682f977070fe92f5..402113cd1b1c7d446b80bebff223493435827bc4 100644 (file)
@@ -5,7 +5,7 @@ import { warn } from './warning'
 
 export interface InjectionKey<T> extends Symbol {}
 
-export function provide<T>(key: InjectionKey<T> | string, value: T) {
+export function provide<T>(key: InjectionKey<T> | string | number, value: T) {
   if (!currentInstance) {
     if (__DEV__) {
       warn(`provide() can only be used inside setup().`)
index 89bd8c060536cc0b922a7264c76ef33a71db6e45..76e61a44ed4f0d86e27e2b8f3aa04b563ccd3ea1 100644 (file)
@@ -667,9 +667,9 @@ export function applyOptions(
       const provides = isFunction(provideOptions)
         ? provideOptions.call(publicThis)
         : provideOptions
-      for (const key in provides) {
+      Reflect.ownKeys(provides).forEach(key => {
         provide(key, provides[key])
-      }
+      })
     })
   }