File tree 2 files changed +24
-2
lines changed
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ import {
12
12
SimpleExpressionNode ,
13
13
ConditionalExpression ,
14
14
IfConditionalExpression ,
15
- VNodeCall
15
+ VNodeCall ,
16
+ ElementTypes
16
17
} from '../../src/ast'
17
18
import { ErrorCodes } from '../../src/errors'
18
19
import { CompilerOptions , generate } from '../../src'
@@ -77,6 +78,22 @@ describe('compiler: v-if', () => {
77
78
expect ( node . branches [ 0 ] . children [ 2 ] . type ) . toBe ( NodeTypes . ELEMENT )
78
79
expect ( ( node . branches [ 0 ] . children [ 2 ] as ElementNode ) . tag ) . toBe ( `p` )
79
80
} )
81
+
82
+ test ( 'component v-if' , ( ) => {
83
+ const { node } = parseWithIfTransform ( `<Component v-if="ok"></Component>` )
84
+ expect ( node . type ) . toBe ( NodeTypes . IF )
85
+ expect ( node . branches . length ) . toBe ( 1 )
86
+ expect ( ( node . branches [ 0 ] . children [ 0 ] as ElementNode ) . tag ) . toBe (
87
+ `Component`
88
+ )
89
+ expect ( ( node . branches [ 0 ] . children [ 0 ] as ElementNode ) . tagType ) . toBe (
90
+ ElementTypes . COMPONENT
91
+ )
92
+ expect (
93
+ ( ( node . branches [ 0 ] . children [ 0 ] as ElementNode ) !
94
+ . codegenNode as VNodeCall ) ! . isBlock
95
+ ) . toBe ( false )
96
+ } )
80
97
81
98
test ( 'v-if + v-else' , ( ) => {
82
99
const { node } = parseWithIfTransform ( `<div v-if="ok"/><p v-else/>` )
Original file line number Diff line number Diff line change @@ -212,7 +212,12 @@ function createChildrenCodegenNode(
212
212
const vnodeCall = ( firstChild as ElementNode )
213
213
. codegenNode as BlockCodegenNode
214
214
// Change createVNode to createBlock.
215
- if ( vnodeCall . type === NodeTypes . VNODE_CALL ) {
215
+ if (
216
+ vnodeCall . type === NodeTypes . VNODE_CALL &&
217
+ // component vnodes are always tracked and its children are
218
+ // compiled into slots so no need to make it a block
219
+ ( firstChild as ElementNode ) . tagType !== ElementTypes . COMPONENT
220
+ ) {
216
221
vnodeCall . isBlock = true
217
222
helper ( OPEN_BLOCK )
218
223
helper ( CREATE_BLOCK )
You can’t perform that action at this time.
0 commit comments