diff --git a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts index a1ae013a830..466b01f5375 100644 --- a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts @@ -152,6 +152,28 @@ describe('compiler: element transform', () => { expect(node.tag).toBe(`Foo.Example`) }) + test('resolve namespaced component from props bindings (inline)', () => { + const { root, node } = parseWithElementTransform(``, { + inline: true, + bindingMetadata: { + Foo: BindingTypes.PROPS + } + }) + expect(root.helpers).not.toContain(RESOLVE_COMPONENT) + expect(node.tag).toBe(`_unref(__props["Foo"]).Example`) + }) + + test('resolve namespaced component from props bindings (non-inline)', () => { + const { root, node } = parseWithElementTransform(``, { + inline: false, + bindingMetadata: { + Foo: BindingTypes.PROPS + } + }) + expect(root.helpers).not.toContain(RESOLVE_COMPONENT) + expect(node.tag).toBe('_unref($props["Foo"]).Example') + }) + test('do not resolve component from non-script-setup bindings', () => { const bindingMetadata = { Example: BindingTypes.SETUP_MAYBE_REF diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index 253b6be5efa..20ddbaa6313 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -385,6 +385,13 @@ function resolveSetupReference(name: string, context: TransformContext) { `${context.helperString(UNREF)}(${fromMaybeRef})` : `$setup[${JSON.stringify(fromMaybeRef)}]` } + + const fromProps = checkType(BindingTypes.PROPS) + if (fromProps) { + return `${context.helperString(UNREF)}(${ + context.inline ? '__props' : '$props' + }[${JSON.stringify(fromProps)}])` + } } export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode