]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: more compat tweaks
authorEvan You <yyx990803@gmail.com>
Thu, 22 Apr 2021 21:30:54 +0000 (17:30 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 22 Apr 2021 21:30:54 +0000 (17:30 -0400)
packages/runtime-core/src/compat/attrsFallthrough.ts
packages/runtime-core/src/compat/global.ts
packages/runtime-core/src/compat/instance.ts
packages/runtime-core/src/compat/renderFn.ts
packages/runtime-core/src/componentProps.ts
packages/runtime-core/src/componentPublicInstance.ts

index 56ffe160443cb954fe90be6b2239ce2a147cbfb4..a23890b618178f795095e1d10b4d67474566c5dd 100644 (file)
@@ -4,6 +4,7 @@ import { DeprecationTypes, isCompatEnabled } from './compatConfig'
 
 export function shouldSkipAttr(
   key: string,
+  value: any,
   instance: ComponentInternalInstance
 ): boolean {
   if (
@@ -18,5 +19,9 @@ export function shouldSkipAttr(
   ) {
     return true
   }
+  // vue-router
+  if (key.startsWith('routerView') || key === 'registerRouteInstance') {
+    return true
+  }
   return false
 }
index ca97117c9b7b8a02015fe38a855a27e0caf7f282..45b9a2ad9d89c410915721c055bce74000924afb 100644 (file)
@@ -153,10 +153,7 @@ export function createCompatVue(
 
     // copy prototype augmentations as config.globalProperties
     if (isCompatEnabled(DeprecationTypes.GLOBAL_PROTOTYPE, null)) {
-      app.config.globalProperties = extend(
-        Object.create(Ctor.prototype),
-        singletonApp.config.globalProperties
-      )
+      app.config.globalProperties = Ctor.prototype
     }
     let hasPrototypeAugmentations = false
     for (const key in Ctor.prototype) {
@@ -449,7 +446,9 @@ function defineReactive(obj: any, key: string, val: any) {
       })
     } else {
       Object.keys(val).forEach(key => {
-        defineReactiveSimple(val, key, val[key])
+        try {
+          defineReactiveSimple(val, key, val[key])
+        } catch (e) {}
       })
     }
   }
index bf1d2e2fb01959b52a8d24a4c411cc2f1b3a2f81..b105aafc6da78a75f6286a3609987dab7f571316 100644 (file)
@@ -93,11 +93,14 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
     $children: getCompatChildren,
     $listeners: getCompatListeners,
 
-    // inject parent into $options for compat
+    $vnode: i => i.vnode,
+
+    // inject addtional properties into $options for compat
     $options: i => {
       let res = resolveMergedOptions(i)
       if (res === i.type) res = i.type.__merged = extend({}, res)
       res.parent = i.proxy!.$parent
+      res.propsData = i.vnode.props
       return res
     },
 
index afaef39c5ff758b48cd3d7bc561c23ffdbb9d991..5fc574b0ce486ce2aa0821ff0a3fd859e9671750 100644 (file)
@@ -24,6 +24,7 @@ import {
   resolveDynamicComponent
 } from '../helpers/resolveAssets'
 import {
+  Comment,
   createVNode,
   isVNode,
   normalizeChildren,
@@ -121,6 +122,10 @@ export function compatH(
   propsOrChildren?: any,
   children?: any
 ): VNode {
+  if (!type) {
+    type = Comment
+  }
+
   // to support v2 string component name look!up
   if (typeof type === 'string') {
     const t = hyphenate(type)
@@ -201,6 +206,8 @@ function convertLegacyProps(
           }
         }
       }
+    } else if (key === 'hook') {
+      // TODO
     } else if (!skipLegacyRootLevelProps(key)) {
       converted[key] = legacyProps[key as keyof LegacyVNodeProps]
     }
index c1568bdab9d6f75e2ddb1204568cc12ad6686037..5d38325d9463747442e00cd2ed4a2feebf5f8911 100644 (file)
@@ -229,7 +229,7 @@ export function updateProps(
             )
           }
         } else {
-          if (__COMPAT__ && shouldSkipAttr(key, instance)) {
+          if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) {
             continue
           }
           if (value !== attrs[key]) {
@@ -337,7 +337,7 @@ function setFullProps(
         // Any non-declared (either as a prop or an emitted event) props are put
         // into a separate `attrs` object for spreading. Make sure to preserve
         // original key casing
-        if (__COMPAT__ && shouldSkipAttr(key, instance)) {
+        if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) {
           continue
         }
         if (value !== attrs[key]) {
index 22022317d258e1c081d5b79aa47795e1afa9a593..9610aad19b452b7d88fa0023fa69f88ecf413aeb 100644 (file)
@@ -345,8 +345,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
       hasOwn(globalProperties, key))
     ) {
       if (__COMPAT__) {
-        const val = globalProperties[key]
-        return isFunction(val) ? val.bind(instance.proxy) : val
+        const desc = Object.getOwnPropertyDescriptor(globalProperties, key)!
+        if (desc.get) {
+          return desc.get.call(instance.proxy)
+        } else {
+          const val = globalProperties[key]
+          return isFunction(val) ? val.bind(instance.proxy) : val
+        }
       } else {
         return globalProperties[key]
       }