Skip to content

Commit b7ea8d3

Browse files
committed
feat(compiler): support namespaced component name
1 parent 43195e7 commit b7ea8d3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/core/compiler/transforms/transformElement.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ export const transformElement: NodeTransform = (node, context) => {
4343
const {
4444
openingElement: { name },
4545
} = node
46-
const tag = name.type === 'JSXIdentifier' ? name.name : ''
46+
const tag =
47+
name.type === 'JSXIdentifier'
48+
? name.name
49+
: name.type === 'JSXMemberExpression'
50+
? context.ir.source.slice(name.start!, name.end!)
51+
: ''
4752
const isComponent = isComponentNode(node)
4853
const propsResult = buildProps(
4954
node,

test/transforms/transformElement.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { describe, expect, test } from 'vitest'
44
// BindingTypes,
55
// NodeTypes,
66
// } from '@vue/compiler-core'
7+
import { BindingTypes } from '@vue-vapor/compiler-core'
78
import {
89
// IRDynamicPropsKind,
910
// IRNodeTypes,
@@ -42,4 +43,24 @@ describe('compiler: element transform', () => {
4243
)
4344
})
4445
})
46+
47+
test('resolve namespaced component from setup bindings (inline const)', () => {
48+
const { code, vaporHelpers } = compileWithElementTransform(
49+
`<Foo.Example/>`,
50+
{
51+
inline: true,
52+
bindingMetadata: {
53+
Foo: BindingTypes.SETUP_CONST,
54+
},
55+
},
56+
)
57+
expect(code).toMatchInlineSnapshot(`
58+
"(() => {
59+
const n0 = _createComponent(Foo.Example, null, null, true)
60+
return n0
61+
})()"
62+
`)
63+
expect(code).contains(`Foo.Example`)
64+
expect(vaporHelpers).not.toContain('resolveComponent')
65+
})
4566
})

0 commit comments

Comments
 (0)