@@ -798,9 +798,18 @@ describe('compiler: element transform', () => {
|
||||
describe('dynamic component', () => {
|
||||
test('static binding', () => {
|
||||
const { node, root } = parseWithBind(`<component is="foo" />`)
|
||||
expect(root.helpers).not.toContain(RESOLVE_DYNAMIC_COMPONENT)
|
||||
expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)
|
||||
expect(node).toMatchObject({
|
||||
tag: '_component_foo'
|
||||
tag: {
|
||||
callee: RESOLVE_DYNAMIC_COMPONENT,
|
||||
arguments: [
|
||||
{
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
content: 'foo',
|
||||
isStatic: true
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -813,7 +822,8 @@ describe('compiler: element transform', () => {
|
||||
arguments: [
|
||||
{
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
content: 'foo'
|
||||
content: 'foo',
|
||||
isStatic: false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -204,19 +204,13 @@ export function resolveComponentType(
|
||||
// 1. dynamic component
|
||||
const isProp = node.tag === 'component' && findProp(node, 'is')
|
||||
if (isProp) {
|
||||
// static <component is="foo" />
|
||||
if (isProp.type === NodeTypes.ATTRIBUTE) {
|
||||
const isType = isProp.value && isProp.value.content
|
||||
if (isType) {
|
||||
context.helper(RESOLVE_COMPONENT)
|
||||
context.components.add(isType)
|
||||
return toValidAssetId(isType, `component`)
|
||||
}
|
||||
}
|
||||
// dynamic <component :is="asdf" />
|
||||
else if (isProp.exp) {
|
||||
const exp =
|
||||
isProp.type === NodeTypes.ATTRIBUTE
|
||||
? isProp.value && createSimpleExpression(isProp.value.content, true)
|
||||
: isProp.exp
|
||||
if (exp) {
|
||||
return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
|
||||
isProp.exp
|
||||
exp
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user