]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): warn reserved prefix for setup return properties and ensure consis...
authorEvan You <yyx990803@gmail.com>
Thu, 3 Sep 2020 15:21:14 +0000 (11:21 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 3 Sep 2020 15:21:14 +0000 (11:21 -0400)
close #2042

packages/runtime-core/src/componentPublicInstance.ts

index c47941fc568973fb346d2cc88b6a28f7d32aac59..695e5ace3c901020c361e8f038db7eb85144074a 100644 (file)
@@ -299,12 +299,16 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
         // 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,