]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: simplify resolveDyanmicComponent
authorEvan You <yyx990803@gmail.com>
Mon, 16 Mar 2020 16:46:15 +0000 (12:46 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 16 Mar 2020 17:06:46 +0000 (13:06 -0400)
packages/compiler-core/__tests__/transforms/transformElement.spec.ts
packages/compiler-core/src/transforms/transformElement.ts
packages/runtime-core/src/helpers/resolveAssets.ts

index cc3cbd480a5342274746f5b1b2a837e4b9943c45..85800feff69823ea95ed7a64dc5643931ed76f21 100644 (file)
@@ -814,8 +814,7 @@ describe('compiler: element transform', () => {
             {
               type: NodeTypes.SIMPLE_EXPRESSION,
               content: 'foo'
-            },
-            '$'
+            }
           ]
         }
       })
index 905268dee310ea83ab286249b9185d27e3b612ed..3123d8ecb7721cfdb73c4f0d2028413158b5cf50 100644 (file)
@@ -215,11 +215,9 @@ export function resolveComponentType(
     }
     // dynamic <component :is="asdf" />
     else if (isProp.exp) {
-      return createCallExpression(
-        context.helper(RESOLVE_DYNAMIC_COMPONENT),
-        // _ctx.$ exposes the owner instance of current render function
-        [isProp.exp, context.prefixIdentifiers ? `_ctx.$` : `$`]
-      )
+      return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
+        isProp.exp
+      ])
     }
   }
 
index dd12b4730e32136c22196b9d9ed04dd85cdd0820..9c3dee57ff2293b9ce566cd59703981e9be59ed1 100644 (file)
@@ -23,16 +23,11 @@ export function resolveComponent(name: string): Component | undefined {
 }
 
 export function resolveDynamicComponent(
-  component: unknown,
-  // Dynamic component resolution has to be called inline due to potential
-  // access to scope variables. When called inside slots it will be inside
-  // a different component's render cycle, so the owner instance must be passed
-  // in explicitly.
-  instance: ComponentInternalInstance
+  component: unknown
 ): Component | undefined {
   if (!component) return
   if (isString(component)) {
-    return resolveAsset(COMPONENTS, component, instance)
+    return resolveAsset(COMPONENTS, component, currentRenderingInstance)
   } else if (isFunction(component) || isObject(component)) {
     return component
   }
@@ -46,13 +41,13 @@ export function resolveDirective(name: string): Directive | undefined {
 function resolveAsset(
   type: typeof COMPONENTS,
   name: string,
-  instance?: ComponentInternalInstance
+  instance?: ComponentInternalInstance | null
 ): Component | undefined
 // overload 2: directives
 function resolveAsset(
   type: typeof DIRECTIVES,
   name: string,
-  instance?: ComponentInternalInstance
+  instance?: ComponentInternalInstance | null
 ): Directive | undefined
 
 function resolveAsset(