Skip to content

Commit

Permalink
fix(compiler-core): allow PascalCase dynamic component tag usage (#3508)
Browse files Browse the repository at this point in the history
fix #3507
  • Loading branch information
HcySunYang authored Mar 29, 2021
1 parent 3736496 commit 555b016
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,24 @@ describe('compiler: element transform', () => {
})
})

test('capitalized version w/ static binding', () => {
const { node, root } = parseWithBind(`<Component is="foo" />`)
expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)
expect(node).toMatchObject({
isBlock: true,
tag: {
callee: RESOLVE_DYNAMIC_COMPONENT,
arguments: [
{
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'foo',
isStatic: true
}
]
}
})
})

test('dynamic binding', () => {
const { node, root } = parseWithBind(`<component :is="foo" />`)
expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)
Expand Down
13 changes: 9 additions & 4 deletions packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ export function resolveComponentType(
const { tag } = node

// 1. dynamic component
const isProp =
node.tag === 'component' ? findProp(node, 'is') : findDir(node, 'is')
const isProp = isComponentTag(tag)
? findProp(node, 'is')
: findDir(node, 'is')
if (isProp) {
const exp =
isProp.type === NodeTypes.ATTRIBUTE
Expand Down Expand Up @@ -413,7 +414,7 @@ export function buildProps(
}
}
// skip :is on <component>
if (name === 'is' && tag === 'component') {
if (name === 'is' && isComponentTag(tag)) {
continue
}
properties.push(
Expand Down Expand Up @@ -452,7 +453,7 @@ export function buildProps(
// skip v-is and :is on <component>
if (
name === 'is' ||
(isBind && tag === 'component' && isBindKey(arg, 'is'))
(isBind && isComponentTag(tag) && isBindKey(arg, 'is'))
) {
continue
}
Expand Down Expand Up @@ -672,3 +673,7 @@ function stringifyDynamicPropNames(props: string[]): string {
}
return propsNamesString + `]`
}

function isComponentTag(tag: string) {
return tag[0].toLowerCase() + tag.slice(1) === 'component'
}

0 comments on commit 555b016

Please sign in to comment.