test(compiler-core): add v-if with comments test case (#1389)
This commit is contained in:
parent
bf5aba8f19
commit
d57749cbf7
@ -13,7 +13,8 @@ import {
|
|||||||
ConditionalExpression,
|
ConditionalExpression,
|
||||||
IfConditionalExpression,
|
IfConditionalExpression,
|
||||||
VNodeCall,
|
VNodeCall,
|
||||||
ElementTypes
|
ElementTypes,
|
||||||
|
IfBranchNode
|
||||||
} from '../../src/ast'
|
} from '../../src/ast'
|
||||||
import { ErrorCodes } from '../../src/errors'
|
import { ErrorCodes } from '../../src/errors'
|
||||||
import { CompilerOptions, generate } from '../../src'
|
import { CompilerOptions, generate } from '../../src'
|
||||||
@ -527,6 +528,50 @@ describe('compiler: v-if', () => {
|
|||||||
expect(generate(root).code).toMatchSnapshot()
|
expect(generate(root).code).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
test.todo('with comments')
|
test('with comments', () => {
|
||||||
|
const { node } = parseWithIfTransform(`
|
||||||
|
<template v-if="ok">
|
||||||
|
<!--comment1-->
|
||||||
|
<div v-if="ok2">
|
||||||
|
<!--comment2-->
|
||||||
|
</div>
|
||||||
|
<!--comment3-->
|
||||||
|
<b v-else/>
|
||||||
|
<!--comment4-->
|
||||||
|
<p/>
|
||||||
|
</template>
|
||||||
|
`)
|
||||||
|
expect(node.type).toBe(NodeTypes.IF)
|
||||||
|
expect(node.branches.length).toBe(1)
|
||||||
|
|
||||||
|
const b1 = node.branches[0]
|
||||||
|
expect((b1.condition as SimpleExpressionNode).content).toBe(`ok`)
|
||||||
|
expect(b1.children.length).toBe(4)
|
||||||
|
|
||||||
|
expect(b1.children[0].type).toBe(NodeTypes.COMMENT)
|
||||||
|
expect((b1.children[0] as CommentNode).content).toBe(`comment1`)
|
||||||
|
|
||||||
|
expect(b1.children[1].type).toBe(NodeTypes.IF)
|
||||||
|
expect((b1.children[1] as IfNode).branches.length).toBe(2)
|
||||||
|
const b1b1: ElementNode = (b1.children[1] as IfNode).branches[0]
|
||||||
|
.children[0] as ElementNode
|
||||||
|
expect(b1b1.type).toBe(NodeTypes.ELEMENT)
|
||||||
|
expect(b1b1.tag).toBe('div')
|
||||||
|
expect(b1b1.children[0].type).toBe(NodeTypes.COMMENT)
|
||||||
|
expect((b1b1.children[0] as CommentNode).content).toBe('comment2')
|
||||||
|
|
||||||
|
const b1b2: IfBranchNode = (b1.children[1] as IfNode)
|
||||||
|
.branches[1] as IfBranchNode
|
||||||
|
expect(b1b2.children[0].type).toBe(NodeTypes.COMMENT)
|
||||||
|
expect((b1b2.children[0] as CommentNode).content).toBe(`comment3`)
|
||||||
|
expect(b1b2.children[1].type).toBe(NodeTypes.ELEMENT)
|
||||||
|
expect((b1b2.children[1] as ElementNode).tag).toBe(`b`)
|
||||||
|
|
||||||
|
expect(b1.children[2].type).toBe(NodeTypes.COMMENT)
|
||||||
|
expect((b1.children[2] as CommentNode).content).toBe(`comment4`)
|
||||||
|
|
||||||
|
expect(b1.children[3].type).toBe(NodeTypes.ELEMENT)
|
||||||
|
expect((b1.children[3] as ElementNode).tag).toBe(`p`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user