})
})
+ 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)
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
}
}
// skip :is on <component>
- if (name === 'is' && tag === 'component') {
+ if (name === 'is' && isComponentTag(tag)) {
continue
}
properties.push(
// skip v-is and :is on <component>
if (
name === 'is' ||
- (isBind && tag === 'component' && isBindKey(arg, 'is'))
+ (isBind && isComponentTag(tag) && isBindKey(arg, 'is'))
) {
continue
}
}
return propsNamesString + `]`
}
+
+function isComponentTag(tag: string) {
+ return tag[0].toLowerCase() + tag.slice(1) === 'component'
+}