test: more coverage
This commit is contained in:
parent
cae03f616d
commit
0707fa5d21
@ -6,9 +6,11 @@ import {
|
|||||||
DirectiveNode,
|
DirectiveNode,
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
ForNode,
|
ForNode,
|
||||||
CompilerOptions
|
CompilerOptions,
|
||||||
|
IfNode
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
import { transformFor } from '../..//src/transforms/vFor'
|
import { transformIf } from '../../src/transforms/vIf'
|
||||||
|
import { transformFor } from '../../src/transforms/vFor'
|
||||||
import { transformExpression } from '../../src/transforms/transformExpression'
|
import { transformExpression } from '../../src/transforms/transformExpression'
|
||||||
|
|
||||||
function parseWithExpressionTransform(
|
function parseWithExpressionTransform(
|
||||||
@ -18,7 +20,7 @@ function parseWithExpressionTransform(
|
|||||||
const ast = parse(template)
|
const ast = parse(template)
|
||||||
transform(ast, {
|
transform(ast, {
|
||||||
prefixIdentifiers: true,
|
prefixIdentifiers: true,
|
||||||
nodeTransforms: [transformFor, transformExpression],
|
nodeTransforms: [transformIf, transformFor, transformExpression],
|
||||||
...options
|
...options
|
||||||
})
|
})
|
||||||
return ast.children[0]
|
return ast.children[0]
|
||||||
@ -147,6 +149,21 @@ describe('compiler: expression transform', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should prefix v-if condition', () => {
|
||||||
|
const node = parseWithExpressionTransform(`<div v-if="ok"/>`) as IfNode
|
||||||
|
expect(node.branches[0].condition!.children).toMatchObject([
|
||||||
|
`_ctx.`,
|
||||||
|
{ content: `ok` }
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should prefix v-for source', () => {
|
||||||
|
const node = parseWithExpressionTransform(
|
||||||
|
`<div v-for="i in list"/>`
|
||||||
|
) as ForNode
|
||||||
|
expect(node.source.children).toMatchObject([`_ctx.`, { content: `list` }])
|
||||||
|
})
|
||||||
|
|
||||||
test('should not prefix v-for alias', () => {
|
test('should not prefix v-for alias', () => {
|
||||||
const node = parseWithExpressionTransform(
|
const node = parseWithExpressionTransform(
|
||||||
`<div v-for="i in list">{{ i }}{{ j }}</div>`
|
`<div v-for="i in list">{{ i }}{{ j }}</div>`
|
||||||
|
Loading…
Reference in New Issue
Block a user