@@ -6,9 +6,11 @@ import {
6
6
DirectiveNode ,
7
7
NodeTypes ,
8
8
ForNode ,
9
- CompilerOptions
9
+ CompilerOptions ,
10
+ IfNode
10
11
} from '../../src'
11
- import { transformFor } from '../..//src/transforms/vFor'
12
+ import { transformIf } from '../../src/transforms/vIf'
13
+ import { transformFor } from '../../src/transforms/vFor'
12
14
import { transformExpression } from '../../src/transforms/transformExpression'
13
15
14
16
function parseWithExpressionTransform (
@@ -18,7 +20,7 @@ function parseWithExpressionTransform(
18
20
const ast = parse ( template )
19
21
transform ( ast , {
20
22
prefixIdentifiers : true ,
21
- nodeTransforms : [ transformFor , transformExpression ] ,
23
+ nodeTransforms : [ transformIf , transformFor , transformExpression ] ,
22
24
...options
23
25
} )
24
26
return ast . children [ 0 ]
@@ -147,6 +149,21 @@ describe('compiler: expression transform', () => {
147
149
] )
148
150
} )
149
151
152
+ test ( 'should prefix v-if condition' , ( ) => {
153
+ const node = parseWithExpressionTransform ( `<div v-if="ok"/>` ) as IfNode
154
+ expect ( node . branches [ 0 ] . condition ! . children ) . toMatchObject ( [
155
+ `_ctx.` ,
156
+ { content : `ok` }
157
+ ] )
158
+ } )
159
+
160
+ test ( 'should prefix v-for source' , ( ) => {
161
+ const node = parseWithExpressionTransform (
162
+ `<div v-for="i in list"/>`
163
+ ) as ForNode
164
+ expect ( node . source . children ) . toMatchObject ( [ `_ctx.` , { content : `list` } ] )
165
+ } )
166
+
150
167
test ( 'should not prefix v-for alias' , ( ) => {
151
168
const node = parseWithExpressionTransform (
152
169
`<div v-for="i in list">{{ i }}{{ j }}</div>`
0 commit comments