fix(compiler-core): fix v-bind shorthand for component :is
close #10469 close #10471
This commit is contained in:
parent
969c5fb30f
commit
04af9504a7
|
@ -1231,6 +1231,24 @@ describe('compiler: element transform', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('dynamic binding shorthand', () => {
|
||||||
|
const { node, root } = parseWithBind(`<component :is />`)
|
||||||
|
expect(root.helpers).toContain(RESOLVE_DYNAMIC_COMPONENT)
|
||||||
|
expect(node).toMatchObject({
|
||||||
|
isBlock: true,
|
||||||
|
tag: {
|
||||||
|
callee: RESOLVE_DYNAMIC_COMPONENT,
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||||
|
content: 'is',
|
||||||
|
isStatic: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('is casting', () => {
|
test('is casting', () => {
|
||||||
const { node, root } = parseWithBind(`<div is="vue:foo" />`)
|
const { node, root } = parseWithBind(`<div is="vue:foo" />`)
|
||||||
expect(root.helpers).toContain(RESOLVE_COMPONENT)
|
expect(root.helpers).toContain(RESOLVE_COMPONENT)
|
||||||
|
|
|
@ -64,6 +64,7 @@ import {
|
||||||
checkCompatEnabled,
|
checkCompatEnabled,
|
||||||
isCompatEnabled,
|
isCompatEnabled,
|
||||||
} from '../compat/compatConfig'
|
} from '../compat/compatConfig'
|
||||||
|
import { processExpression } from './transformExpression'
|
||||||
|
|
||||||
// some directive transforms (e.g. v-model) may return a symbol for runtime
|
// some directive transforms (e.g. v-model) may return a symbol for runtime
|
||||||
// import, which should be used instead of a resolveDirective call.
|
// import, which should be used instead of a resolveDirective call.
|
||||||
|
@ -253,7 +254,7 @@ export function resolveComponentType(
|
||||||
|
|
||||||
// 1. dynamic component
|
// 1. dynamic component
|
||||||
const isExplicitDynamic = isComponentTag(tag)
|
const isExplicitDynamic = isComponentTag(tag)
|
||||||
const isProp = findProp(node, 'is')
|
const isProp = findProp(node, 'is', false, true /* allow empty */)
|
||||||
if (isProp) {
|
if (isProp) {
|
||||||
if (
|
if (
|
||||||
isExplicitDynamic ||
|
isExplicitDynamic ||
|
||||||
|
@ -263,10 +264,19 @@ export function resolveComponentType(
|
||||||
context,
|
context,
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
const exp =
|
let exp: ExpressionNode | undefined
|
||||||
isProp.type === NodeTypes.ATTRIBUTE
|
if (isProp.type === NodeTypes.ATTRIBUTE) {
|
||||||
? isProp.value && createSimpleExpression(isProp.value.content, true)
|
exp = isProp.value && createSimpleExpression(isProp.value.content, true)
|
||||||
: isProp.exp
|
} else {
|
||||||
|
exp = isProp.exp
|
||||||
|
if (!exp) {
|
||||||
|
// #10469 handle :is shorthand
|
||||||
|
exp = createSimpleExpression(`is`, false, isProp.loc)
|
||||||
|
if (!__BROWSER__) {
|
||||||
|
exp = isProp.exp = processExpression(exp, context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (exp) {
|
if (exp) {
|
||||||
return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
|
return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
|
||||||
exp,
|
exp,
|
||||||
|
|
Loading…
Reference in New Issue