Skip to content

Commit 0707fa5

Browse files
committed
test: more coverage
1 parent cae03f6 commit 0707fa5

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import {
66
DirectiveNode,
77
NodeTypes,
88
ForNode,
9-
CompilerOptions
9+
CompilerOptions,
10+
IfNode
1011
} from '../../src'
11-
import { transformFor } from '../..//src/transforms/vFor'
12+
import { transformIf } from '../../src/transforms/vIf'
13+
import { transformFor } from '../../src/transforms/vFor'
1214
import { transformExpression } from '../../src/transforms/transformExpression'
1315

1416
function parseWithExpressionTransform(
@@ -18,7 +20,7 @@ function parseWithExpressionTransform(
1820
const ast = parse(template)
1921
transform(ast, {
2022
prefixIdentifiers: true,
21-
nodeTransforms: [transformFor, transformExpression],
23+
nodeTransforms: [transformIf, transformFor, transformExpression],
2224
...options
2325
})
2426
return ast.children[0]
@@ -147,6 +149,21 @@ describe('compiler: expression transform', () => {
147149
])
148150
})
149151

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+
150167
test('should not prefix v-for alias', () => {
151168
const node = parseWithExpressionTransform(
152169
`<div v-for="i in list">{{ i }}{{ j }}</div>`

0 commit comments

Comments
 (0)