Skip to content

Commit 1a12612

Browse files
committed
fix(compiler-core): support resolving components from props
1 parent 37a14a5 commit 1a12612

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ describe('compiler: element transform', () => {
152152
expect(node.tag).toBe(`Foo.Example`)
153153
})
154154

155+
test('resolve namespaced component from setup bindings (inline props)', () => {
156+
const { root, node } = parseWithElementTransform(`<Foo.Example/>`, {
157+
inline: true,
158+
bindingMetadata: {
159+
Foo: BindingTypes.PROPS
160+
}
161+
})
162+
expect(root.helpers).not.toContain(RESOLVE_COMPONENT)
163+
expect(node.tag).toBe(`_unref(props["Foo"]).Example`)
164+
})
165+
155166
test('do not resolve component from non-script-setup bindings', () => {
156167
const bindingMetadata = {
157168
Example: BindingTypes.SETUP_MAYBE_REF

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ function resolveSetupReference(name: string, context: TransformContext) {
385385
`${context.helperString(UNREF)}(${fromMaybeRef})`
386386
: `$setup[${JSON.stringify(fromMaybeRef)}]`
387387
}
388+
389+
const fromProps = checkType(BindingTypes.PROPS)
390+
if (fromProps) {
391+
return context.inline
392+
? `${context.helperString(UNREF)}(props[${JSON.stringify(fromProps)}])`
393+
: `$props[${JSON.stringify(fromProps)}]`
394+
}
388395
}
389396

390397
export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode

0 commit comments

Comments
 (0)