]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: improve coverage
authorEvan You <yyx990803@gmail.com>
Sat, 28 Sep 2019 18:15:10 +0000 (14:15 -0400)
committerEvan You <yyx990803@gmail.com>
Sat, 28 Sep 2019 18:15:10 +0000 (14:15 -0400)
packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap
packages/compiler-core/__tests__/parse.spec.ts
packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts
packages/compiler-core/src/codegen.ts
packages/compiler-core/src/index.ts

index 5b7edf2b33bf3bffd727eaa766e13d4506a1b796..4076be861a44ae6daeddb87cc087404a28e6a53c 100644 (file)
@@ -7117,6 +7117,109 @@ Object {
 }
 `;
 
+exports[`compiler: parse Errors X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END <div v-foo:[sef fsef] /> 1`] = `
+Object {
+  "children": Array [
+    Object {
+      "children": Array [],
+      "codegenNode": undefined,
+      "isSelfClosing": true,
+      "loc": Object {
+        "end": Object {
+          "column": 25,
+          "line": 1,
+          "offset": 24,
+        },
+        "source": "<div v-foo:[sef fsef] />",
+        "start": Object {
+          "column": 1,
+          "line": 1,
+          "offset": 0,
+        },
+      },
+      "ns": 0,
+      "props": Array [
+        Object {
+          "arg": Object {
+            "content": "se",
+            "isStatic": false,
+            "loc": Object {
+              "end": Object {
+                "column": 16,
+                "line": 1,
+                "offset": 15,
+              },
+              "source": "[sef",
+              "start": Object {
+                "column": 12,
+                "line": 1,
+                "offset": 11,
+              },
+            },
+            "type": 4,
+          },
+          "exp": undefined,
+          "loc": Object {
+            "end": Object {
+              "column": 16,
+              "line": 1,
+              "offset": 15,
+            },
+            "source": "v-foo:[sef",
+            "start": Object {
+              "column": 6,
+              "line": 1,
+              "offset": 5,
+            },
+          },
+          "modifiers": Array [],
+          "name": "foo",
+          "type": 7,
+        },
+        Object {
+          "loc": Object {
+            "end": Object {
+              "column": 22,
+              "line": 1,
+              "offset": 21,
+            },
+            "source": "fsef]",
+            "start": Object {
+              "column": 17,
+              "line": 1,
+              "offset": 16,
+            },
+          },
+          "name": "fsef]",
+          "type": 6,
+          "value": undefined,
+        },
+      ],
+      "tag": "div",
+      "tagType": 0,
+      "type": 1,
+    },
+  ],
+  "hoists": Array [],
+  "imports": Array [],
+  "loc": Object {
+    "end": Object {
+      "column": 25,
+      "line": 1,
+      "offset": 24,
+    },
+    "source": "<div v-foo:[sef fsef] />",
+    "start": Object {
+      "column": 1,
+      "line": 1,
+      "offset": 0,
+    },
+  },
+  "statements": Array [],
+  "type": 0,
+}
+`;
+
 exports[`compiler: parse Errors X_MISSING_END_TAG <template><div> 1`] = `
 Object {
   "children": Array [
index 35e11f84e78655fe067cab19aad4f48cfe64b96a..4df608b64f462ee5b0e8aea7ce67764c057c5579 100644 (file)
@@ -2464,6 +2464,17 @@ foo
           code: '{{}}',
           errors: []
         }
+      ],
+      X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END: [
+        {
+          code: `<div v-foo:[sef fsef] />`,
+          errors: [
+            {
+              type: ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END,
+              loc: { offset: 15, line: 1, column: 16 }
+            }
+          ]
+        }
       ]
     }
 
index 6e80abed36c78ceb6a5058a22a9e822921f1c924..262c5f2dcee8a9240ef85d5c9f0e964a3952b0fa 100644 (file)
@@ -342,6 +342,24 @@ describe('compiler: expression transform', () => {
     })
   })
 
+  test('function params should not affect out of scope identifiers', () => {
+    const node = parseWithExpressionTransform(
+      `{{ { a: foo => foo, b: foo } }}`
+    ) as InterpolationNode
+    expect(node.content).toMatchObject({
+      type: NodeTypes.COMPOUND_EXPRESSION,
+      children: [
+        `{ a: `,
+        { content: `foo` },
+        ` => `,
+        { content: `foo` },
+        `, b: `,
+        { content: `_ctx.foo` },
+        ` }`
+      ]
+    })
+  })
+
   test('should prefix default value of function param destructuring', () => {
     const node = parseWithExpressionTransform(
       `{{ ({ foo = bar }) => foo + bar }}`
index dbdc9efb57c5abe8cf0cf6f492647a8508d28ac9..7c4e5ef36504acea094ab031b3c07a0794702fe6 100644 (file)
@@ -374,8 +374,8 @@ function genNode(node: CodegenNode, context: CodegenContext) {
     case NodeTypes.JS_SLOT_FUNCTION:
       genSlotFunction(node, context)
       break
+    /* istanbul ignore next */
     default:
-      /* istanbul ignore if */
       if (__DEV__) {
         assert(false, `unhandled codegen node type: ${(node as any).type}`)
         // make sure we exhaust all possible types
index 53badd58fb348903dc60a0d951a2f9af37af4eb4..111f97e1ddbcf1ac06067d3a3003e5a90c3a169c 100644 (file)
@@ -22,6 +22,7 @@ export function baseCompile(
   template: string | RootNode,
   options: CompilerOptions = {}
 ): CodegenResult {
+  /* istanbul ignore if */
   if (__BROWSER__) {
     const onError = options.onError || defaultOnError
     if (options.prefixIdentifiers === true) {