Procházet zdrojové kódy

test: improve coverage

Evan You před 6 roky
rodič
revize
798a9cbe9b

+ 103 - 0
packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap

@@ -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 [

+ 11 - 0
packages/compiler-core/__tests__/parse.spec.ts

@@ -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 }
+            }
+          ]
+        }
       ]
     }
 

+ 18 - 0
packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

@@ -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 }}`

+ 1 - 1
packages/compiler-core/src/codegen.ts

@@ -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

+ 1 - 0
packages/compiler-core/src/index.ts

@@ -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) {