From: Evan You Date: Fri, 17 Apr 2020 14:23:10 +0000 (-0400) Subject: fix(runtime-core): fix user attched public instance properties that start with "$" X-Git-Tag: v3.0.0-beta.2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d7ca1c5c6e75648793d670299c9059b6db9b1715;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-core): fix user attched public instance properties that start with "$" --- diff --git a/packages/runtime-core/__tests__/componentProxy.spec.ts b/packages/runtime-core/__tests__/componentProxy.spec.ts index d5d46c25ee..706fad4a69 100644 --- a/packages/runtime-core/__tests__/componentProxy.spec.ts +++ b/packages/runtime-core/__tests__/componentProxy.spec.ts @@ -117,6 +117,11 @@ describe('component: proxy', () => { instanceProxy.foo = 1 expect(instanceProxy.foo).toBe(1) expect(instance!.ctx.foo).toBe(1) + + // should also allow properties that start with $ + const obj = (instanceProxy.$store = {}) + expect(instanceProxy.$store).toBe(obj) + expect(instance!.ctx.$store).toBe(obj) }) test('globalProperties', () => { diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 183207e90a..bee09ee87f 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -184,6 +184,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { (cssModule = cssModule[key]) ) { return cssModule + } else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) { + // user may set custom properties to `this` that start with `$` + accessCache![key] = AccessTypes.CONTEXT + return ctx[key] } else if ( // global properties ((globalProperties = appContext.config.globalProperties),