Skip to content

Commit 19228a4

Browse files
committed
refactor: simplify resolveDyanmicComponent
1 parent 9ad65b1 commit 19228a4

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

packages/compiler-core/__tests__/transforms/transformElement.spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,7 @@ describe('compiler: element transform', () => {
814814
{
815815
type: NodeTypes.SIMPLE_EXPRESSION,
816816
content: 'foo'
817-
},
818-
'$'
817+
}
819818
]
820819
}
821820
})

packages/compiler-core/src/transforms/transformElement.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,9 @@ export function resolveComponentType(
215215
}
216216
// dynamic <component :is="asdf" />
217217
else if (isProp.exp) {
218-
return createCallExpression(
219-
context.helper(RESOLVE_DYNAMIC_COMPONENT),
220-
// _ctx.$ exposes the owner instance of current render function
221-
[isProp.exp, context.prefixIdentifiers ? `_ctx.$` : `$`]
222-
)
218+
return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
219+
isProp.exp
220+
])
223221
}
224222
}
225223

packages/runtime-core/src/helpers/resolveAssets.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,11 @@ export function resolveComponent(name: string): Component | undefined {
2323
}
2424

2525
export function resolveDynamicComponent(
26-
component: unknown,
27-
// Dynamic component resolution has to be called inline due to potential
28-
// access to scope variables. When called inside slots it will be inside
29-
// a different component's render cycle, so the owner instance must be passed
30-
// in explicitly.
31-
instance: ComponentInternalInstance
26+
component: unknown
3227
): Component | undefined {
3328
if (!component) return
3429
if (isString(component)) {
35-
return resolveAsset(COMPONENTS, component, instance)
30+
return resolveAsset(COMPONENTS, component, currentRenderingInstance)
3631
} else if (isFunction(component) || isObject(component)) {
3732
return component
3833
}
@@ -46,13 +41,13 @@ export function resolveDirective(name: string): Directive | undefined {
4641
function resolveAsset(
4742
type: typeof COMPONENTS,
4843
name: string,
49-
instance?: ComponentInternalInstance
44+
instance?: ComponentInternalInstance | null
5045
): Component | undefined
5146
// overload 2: directives
5247
function resolveAsset(
5348
type: typeof DIRECTIVES,
5449
name: string,
55-
instance?: ComponentInternalInstance
50+
instance?: ComponentInternalInstance | null
5651
): Directive | undefined
5752

5853
function resolveAsset(

0 commit comments

Comments
 (0)