feat(compiler-core): support <portal> in template (#203)

This commit is contained in:
terencez
2019-10-15 03:11:04 +08:00
committed by Evan You
parent 37cbd0098d
commit 4547d85a38
4 changed files with 66 additions and 4 deletions

View File

@@ -6,7 +6,8 @@ import {
RESOLVE_DIRECTIVE,
APPLY_DIRECTIVES,
TO_HANDLERS,
helperNameMap
helperNameMap,
PORTAL
} from '../../src/runtimeHelpers'
import {
CallExpression,
@@ -255,6 +256,52 @@ describe('compiler: element transform', () => {
])
})
test('should handle <portal> element', () => {
const { node } = parseWithElementTransform(
`<portal target="#foo"><span /></portal>`
)
expect(node.callee).toBe(CREATE_VNODE)
expect(node.arguments).toMatchObject([
PORTAL,
createObjectMatcher({
target: '#foo'
}),
[
{
type: NodeTypes.ELEMENT,
tag: 'span',
codegenNode: {
callee: CREATE_VNODE,
arguments: [`"span"`]
}
}
]
])
})
test('should handle <Portal> element', () => {
const { node } = parseWithElementTransform(
`<Portal target="#foo"><span /></Portal>`
)
expect(node.callee).toBe(CREATE_VNODE)
expect(node.arguments).toMatchObject([
PORTAL,
createObjectMatcher({
target: '#foo'
}),
[
{
type: NodeTypes.ELEMENT,
tag: 'span',
codegenNode: {
callee: CREATE_VNODE,
arguments: [`"span"`]
}
}
]
])
})
test('error on v-bind with no argument', () => {
const onError = jest.fn()
parseWithElementTransform(`<div v-bind/>`, { onError })