From: Evan You Date: Thu, 3 Sep 2020 15:21:14 +0000 (-0400) Subject: fix(runtime-core): warn reserved prefix for setup return properties and ensure consis... X-Git-Tag: v3.0.0-rc.11~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa7ab0a7f7a939dc7724930a548805219e6a86c5;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-core): warn reserved prefix for setup return properties and ensure consistent dev/prod behavior close #2042 --- diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index c47941fc56..695e5ace3c 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -299,12 +299,16 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { // to infinite warning loop key.indexOf('__v') !== 0) ) { - if (data !== EMPTY_OBJ && key[0] === '$' && hasOwn(data, key)) { + if ( + data !== EMPTY_OBJ && + (key[0] === '$' || key[0] === '_') && + hasOwn(data, key) + ) { warn( `Property ${JSON.stringify( key )} must be accessed via $data because it starts with a reserved ` + - `character and is not proxied on the render context.` + `character ("$" or "_") and is not proxied on the render context.` ) } else { warn( @@ -474,6 +478,15 @@ export function exposeSetupStateOnRenderContext( ) { const { ctx, setupState } = instance Object.keys(toRaw(setupState)).forEach(key => { + if (key[0] === '$' || key[0] === '_') { + warn( + `setup() return property ${JSON.stringify( + key + )} should not start with "$" or "_" ` + + `which are reserved prefixes for Vue internals.` + ) + return + } Object.defineProperty(ctx, key, { enumerable: true, configurable: true,