Skip to content

Commit 555b016

Browse files
authored
fix(compiler-core): allow PascalCase dynamic component tag usage (#3508)
fix #3507
1 parent 3736496 commit 555b016

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

+18
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,24 @@ describe('compiler: element transform', () => {
836836
})
837837
})
838838

839+
test('capitalized version w/ static binding', () => {
840+
const { node, root } = parseWithBind(`<Component is="foo" />`)
841+
expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)
842+
expect(node).toMatchObject({
843+
isBlock: true,
844+
tag: {
845+
callee: RESOLVE_DYNAMIC_COMPONENT,
846+
arguments: [
847+
{
848+
type: NodeTypes.SIMPLE_EXPRESSION,
849+
content: 'foo',
850+
isStatic: true
851+
}
852+
]
853+
}
854+
})
855+
})
856+
839857
test('dynamic binding', () => {
840858
const { node, root } = parseWithBind(`<component :is="foo" />`)
841859
expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ export function resolveComponentType(
230230
const { tag } = node
231231

232232
// 1. dynamic component
233-
const isProp =
234-
node.tag === 'component' ? findProp(node, 'is') : findDir(node, 'is')
233+
const isProp = isComponentTag(tag)
234+
? findProp(node, 'is')
235+
: findDir(node, 'is')
235236
if (isProp) {
236237
const exp =
237238
isProp.type === NodeTypes.ATTRIBUTE
@@ -413,7 +414,7 @@ export function buildProps(
413414
}
414415
}
415416
// skip :is on <component>
416-
if (name === 'is' && tag === 'component') {
417+
if (name === 'is' && isComponentTag(tag)) {
417418
continue
418419
}
419420
properties.push(
@@ -452,7 +453,7 @@ export function buildProps(
452453
// skip v-is and :is on <component>
453454
if (
454455
name === 'is' ||
455-
(isBind && tag === 'component' && isBindKey(arg, 'is'))
456+
(isBind && isComponentTag(tag) && isBindKey(arg, 'is'))
456457
) {
457458
continue
458459
}
@@ -672,3 +673,7 @@ function stringifyDynamicPropNames(props: string[]): string {
672673
}
673674
return propsNamesString + `]`
674675
}
676+
677+
function isComponentTag(tag: string) {
678+
return tag[0].toLowerCase() + tag.slice(1) === 'component'
679+
}

0 commit comments

Comments
 (0)