]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: more coverage
authorEvan You <yyx990803@gmail.com>
Tue, 24 Sep 2019 20:40:32 +0000 (16:40 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 24 Sep 2019 20:40:32 +0000 (16:40 -0400)
packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

index 85089bd223d6c65753c9bc05fba5d1be2fd706f9..088edecf874fb5a078f8d7b1f6ee344a7f8cfd6a 100644 (file)
@@ -6,9 +6,11 @@ import {
   DirectiveNode,
   NodeTypes,
   ForNode,
-  CompilerOptions
+  CompilerOptions,
+  IfNode
 } 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'
 
 function parseWithExpressionTransform(
@@ -18,7 +20,7 @@ function parseWithExpressionTransform(
   const ast = parse(template)
   transform(ast, {
     prefixIdentifiers: true,
-    nodeTransforms: [transformFor, transformExpression],
+    nodeTransforms: [transformIf, transformFor, transformExpression],
     ...options
   })
   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', () => {
     const node = parseWithExpressionTransform(
       `<div v-for="i in list">{{ i }}{{ j }}</div>`