Skip to content

Commit 7a1a782

Browse files
fix(provide): support symbols in applyOptions (#2616)
fix #2615
1 parent e4f09c1 commit 7a1a782

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

packages/runtime-core/__tests__/apiOptions.spec.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ describe('api: options', () => {
251251
})
252252

253253
test('provide/inject', () => {
254+
const symbolKey = Symbol()
254255
const Root = defineComponent({
255256
data() {
256257
return {
@@ -259,7 +260,8 @@ describe('api: options', () => {
259260
},
260261
provide() {
261262
return {
262-
a: this.a
263+
a: this.a,
264+
[symbolKey]: 2
263265
}
264266
},
265267
render() {
@@ -271,7 +273,9 @@ describe('api: options', () => {
271273
h(ChildE),
272274
h(ChildF),
273275
h(ChildG),
274-
h(ChildH)
276+
h(ChildH),
277+
h(ChildI),
278+
h(ChildJ)
275279
]
276280
}
277281
})
@@ -321,7 +325,15 @@ describe('api: options', () => {
321325
default: () => 5
322326
}
323327
})
324-
expect(renderToString(h(Root))).toBe(`11112345`)
328+
const ChildI = defineChild({
329+
b: symbolKey
330+
})
331+
const ChildJ = defineChild({
332+
b: {
333+
from: symbolKey
334+
}
335+
})
336+
expect(renderToString(h(Root))).toBe(`1111234522`)
325337
})
326338

327339
test('provide accessing data in extends', () => {

packages/runtime-core/src/apiInject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { warn } from './warning'
55

66
export interface InjectionKey<T> extends Symbol {}
77

8-
export function provide<T>(key: InjectionKey<T> | string, value: T) {
8+
export function provide<T>(key: InjectionKey<T> | string | number, value: T) {
99
if (!currentInstance) {
1010
if (__DEV__) {
1111
warn(`provide() can only be used inside setup().`)

packages/runtime-core/src/componentOptions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,9 @@ export function applyOptions(
667667
const provides = isFunction(provideOptions)
668668
? provideOptions.call(publicThis)
669669
: provideOptions
670-
for (const key in provides) {
670+
Reflect.ownKeys(provides).forEach(key => {
671671
provide(key, provides[key])
672-
}
672+
})
673673
})
674674
}
675675

0 commit comments

Comments
 (0)