Skip to content

Commit

Permalink
fix(compiler-core): support resolving components from props
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 authored and sxzz committed Aug 21, 2023
1 parent e7d5a41 commit 3aabc47
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ describe('compiler: element transform', () => {
expect(node.tag).toBe(`Foo.Example`)
})

test('resolve namespaced component from setup bindings (inline props)', () => {
const { root, node } = parseWithElementTransform(`<Foo.Example/>`, {
inline: true,
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
Expand Down
7 changes: 7 additions & 0 deletions packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.inline
? `${context.helperString(UNREF)}(props[${JSON.stringify(fromProps)}])`
: `$props[${JSON.stringify(fromProps)}]`
}
}

export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode
Expand Down

0 comments on commit 3aabc47

Please sign in to comment.