fix(compiler-core): allow PascalCase dynamic component tag usage (#3508)

fix #3507
This commit is contained in:
HcySunYang 2021-03-30 03:18:25 +08:00 committed by GitHub
parent 3736496006
commit 555b016dcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View File

@ -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', () => { test('dynamic binding', () => {
const { node, root } = parseWithBind(`<component :is="foo" />`) const { node, root } = parseWithBind(`<component :is="foo" />`)
expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT) expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)

View File

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