From: Evan You Date: Mon, 19 Aug 2019 19:06:03 +0000 (-0400) Subject: wip: make injected values immutable X-Git-Tag: v3.0.0-alpha.0~916 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=10a2cf47ea5c4c53852c3f99b0b8d5feef1010c2;p=thirdparty%2Fvuejs%2Fcore.git wip: make injected values immutable --- diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index 93d5e39a1d..c7f8f327e4 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -1,4 +1,6 @@ import { currentInstance } from './component' +import { immutable } from './apiState' +import { isObject } from '@vue/shared' export interface InjectionKey extends Symbol {} @@ -29,8 +31,8 @@ export function inject(key: InjectionKey | string, defaultValue?: any) { } else { // TODO should also check for app-level provides const provides = currentInstance.parent && currentInstance.provides - return provides && key in provides - ? (provides[key as any] as any) - : defaultValue + const val = + provides && key in provides ? (provides[key as any] as any) : defaultValue + return __DEV__ && isObject(val) ? immutable(val) : val } }