]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-core): use directive name in error code identifier (#163)
authorRahul Kadyan <hi@znck.me>
Wed, 9 Oct 2019 14:27:24 +0000 (19:57 +0530)
committerEvan You <yyx990803@gmail.com>
Wed, 9 Oct 2019 14:27:24 +0000 (10:27 -0400)
packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts
packages/compiler-core/__tests__/transforms/vFor.spec.ts
packages/compiler-core/__tests__/transforms/vIf.spec.ts
packages/compiler-core/__tests__/transforms/vSlot.spec.ts
packages/compiler-core/src/errors.ts
packages/compiler-core/src/transforms/transformElement.ts
packages/compiler-core/src/transforms/transformSlotOutlet.ts
packages/compiler-core/src/transforms/vFor.ts
packages/compiler-core/src/transforms/vIf.ts
packages/compiler-core/src/transforms/vSlot.ts

index 2a3e5455fb80b15396681250bf7bf55baa1bfab0..1e6a4b5418f7d075fd24cd025959457d9f759591 100644 (file)
@@ -317,7 +317,7 @@ describe('compiler: transform <slot> outlets', () => {
     parseWithSlots(source, { onError })
     const index = source.indexOf('v-foo')
     expect(onError.mock.calls[0][0]).toMatchObject({
-      code: ErrorCodes.X_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
+      code: ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
       loc: {
         source: `v-foo`,
         start: {
index 8763d74e3dc2f6991aac9699486055de3454014e..eb1141d9dd7c9357b21ea3a0379fa5974b6f2807 100644 (file)
@@ -219,7 +219,7 @@ describe('compiler: v-for', () => {
       expect(onError).toHaveBeenCalledTimes(1)
       expect(onError).toHaveBeenCalledWith(
         expect.objectContaining({
-          code: ErrorCodes.X_FOR_NO_EXPRESSION
+          code: ErrorCodes.X_V_FOR_NO_EXPRESSION
         })
       )
     })
@@ -231,7 +231,7 @@ describe('compiler: v-for', () => {
       expect(onError).toHaveBeenCalledTimes(1)
       expect(onError).toHaveBeenCalledWith(
         expect.objectContaining({
-          code: ErrorCodes.X_FOR_MALFORMED_EXPRESSION
+          code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
         })
       )
     })
@@ -243,7 +243,7 @@ describe('compiler: v-for', () => {
       expect(onError).toHaveBeenCalledTimes(1)
       expect(onError).toHaveBeenCalledWith(
         expect.objectContaining({
-          code: ErrorCodes.X_FOR_MALFORMED_EXPRESSION
+          code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
         })
       )
     })
@@ -255,7 +255,7 @@ describe('compiler: v-for', () => {
       expect(onError).toHaveBeenCalledTimes(1)
       expect(onError).toHaveBeenCalledWith(
         expect.objectContaining({
-          code: ErrorCodes.X_FOR_MALFORMED_EXPRESSION
+          code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
         })
       )
     })
@@ -267,7 +267,7 @@ describe('compiler: v-for', () => {
       expect(onError).toHaveBeenCalledTimes(1)
       expect(onError).toHaveBeenCalledWith(
         expect.objectContaining({
-          code: ErrorCodes.X_FOR_MALFORMED_EXPRESSION
+          code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
         })
       )
     })
index 4bee495b037e6affd475f40510884e5b7a490eb2..2052a7bd5225e15988b71010dc9d34609f934773 100644 (file)
@@ -195,7 +195,7 @@ describe('compiler: v-if', () => {
       const { node: node1 } = parseWithIfTransform(`<div v-else/>`, { onError })
       expect(onError.mock.calls[0]).toMatchObject([
         {
-          code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
+          code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
           loc: node1.loc
         }
       ])
@@ -207,7 +207,7 @@ describe('compiler: v-if', () => {
       )
       expect(onError.mock.calls[1]).toMatchObject([
         {
-          code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
+          code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
           loc: node2.loc
         }
       ])
@@ -219,7 +219,7 @@ describe('compiler: v-if', () => {
       )
       expect(onError.mock.calls[2]).toMatchObject([
         {
-          code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
+          code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
           loc: node3.loc
         }
       ])
@@ -233,7 +233,7 @@ describe('compiler: v-if', () => {
       })
       expect(onError.mock.calls[0]).toMatchObject([
         {
-          code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
+          code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
           loc: node1.loc
         }
       ])
@@ -245,7 +245,7 @@ describe('compiler: v-if', () => {
       )
       expect(onError.mock.calls[1]).toMatchObject([
         {
-          code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
+          code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
           loc: node2.loc
         }
       ])
@@ -257,7 +257,7 @@ describe('compiler: v-if', () => {
       )
       expect(onError.mock.calls[2]).toMatchObject([
         {
-          code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
+          code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
           loc: node3.loc
         }
       ])
index bd1057f36dfca6720363c6b89180df18cb0b587a..a430b5bfd62961ef836ccd5e210e01b5ab579ba2 100644 (file)
@@ -556,7 +556,7 @@ describe('compiler: transform component slots', () => {
       parseWithSlots(source, { onError })
       const index = source.indexOf('bar')
       expect(onError.mock.calls[0][0]).toMatchObject({
-        code: ErrorCodes.X_EXTRANEOUS_NON_SLOT_CHILDREN,
+        code: ErrorCodes.X_V_SLOT_EXTRANEOUS_NON_SLOT_CHILDREN,
         loc: {
           source: `bar`,
           start: {
@@ -579,7 +579,7 @@ describe('compiler: transform component slots', () => {
       parseWithSlots(source, { onError })
       const index = source.lastIndexOf('#foo')
       expect(onError.mock.calls[0][0]).toMatchObject({
-        code: ErrorCodes.X_DUPLICATE_SLOT_NAMES,
+        code: ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES,
         loc: {
           source: `#foo`,
           start: {
@@ -602,7 +602,7 @@ describe('compiler: transform component slots', () => {
       parseWithSlots(source, { onError })
       const index = source.lastIndexOf('#foo')
       expect(onError.mock.calls[0][0]).toMatchObject({
-        code: ErrorCodes.X_MIXED_SLOT_USAGE,
+        code: ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE,
         loc: {
           source: `#foo`,
           start: {
@@ -625,7 +625,7 @@ describe('compiler: transform component slots', () => {
       parseWithSlots(source, { onError })
       const index = source.indexOf('v-slot')
       expect(onError.mock.calls[0][0]).toMatchObject({
-        code: ErrorCodes.X_MISPLACED_V_SLOT,
+        code: ErrorCodes.X_V_SLOT_MISPLACED,
         loc: {
           source: `v-slot`,
           start: {
@@ -648,7 +648,7 @@ describe('compiler: transform component slots', () => {
       parseWithSlots(source, { onError })
       const index = source.indexOf('v-slot')
       expect(onError.mock.calls[0][0]).toMatchObject({
-        code: ErrorCodes.X_NAMED_SLOT_ON_COMPONENT,
+        code: ErrorCodes.X_V_SLOT_NAMED_SLOT_ON_COMPONENT,
         loc: {
           source: `v-slot:foo`,
           start: {
index e9c16bfcf27e75ef40e2309c8065e1e3dc982b78..a9b2cf5d6a32c6f27c8b93f0723dadab492bada9 100644 (file)
@@ -62,20 +62,20 @@ export const enum ErrorCodes {
   X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END,
 
   // transform errors
-  X_IF_NO_EXPRESSION,
-  X_ELSE_NO_ADJACENT_IF,
-  X_FOR_NO_EXPRESSION,
-  X_FOR_MALFORMED_EXPRESSION,
+  X_V_IF_NO_EXPRESSION,
+  X_V_ELSE_NO_ADJACENT_IF,
+  X_V_FOR_NO_EXPRESSION,
+  X_V_FOR_MALFORMED_EXPRESSION,
   X_V_BIND_NO_EXPRESSION,
   X_V_ON_NO_EXPRESSION,
   X_V_HTML_NO_EXPRESSION,
   X_V_HTML_WITH_CHILDREN,
-  X_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
-  X_NAMED_SLOT_ON_COMPONENT,
-  X_MIXED_SLOT_USAGE,
-  X_DUPLICATE_SLOT_NAMES,
-  X_EXTRANEOUS_NON_SLOT_CHILDREN,
-  X_MISPLACED_V_SLOT,
+  X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
+  X_V_SLOT_NAMED_SLOT_ON_COMPONENT,
+  X_V_SLOT_MIXED_SLOT_USAGE,
+  X_V_SLOT_DUPLICATE_SLOT_NAMES,
+  X_V_SLOT_EXTRANEOUS_NON_SLOT_CHILDREN,
+  X_V_SLOT_MISPLACED,
 
   // generic errors
   X_PREFIX_ID_NOT_SUPPORTED,
@@ -140,27 +140,27 @@ export const errorMessages: { [code: number]: string } = {
     'Note that dynamic directive argument cannot contain spaces.',
 
   // transform errors
-  [ErrorCodes.X_IF_NO_EXPRESSION]: `v-if/v-else-if is missing expression.`,
-  [ErrorCodes.X_ELSE_NO_ADJACENT_IF]: `v-else/v-else-if has no adjacent v-if.`,
-  [ErrorCodes.X_FOR_NO_EXPRESSION]: `v-for is missing expression.`,
-  [ErrorCodes.X_FOR_MALFORMED_EXPRESSION]: `v-for has invalid expression.`,
+  [ErrorCodes.X_V_IF_NO_EXPRESSION]: `v-if/v-else-if is missing expression.`,
+  [ErrorCodes.X_V_ELSE_NO_ADJACENT_IF]: `v-else/v-else-if has no adjacent v-if.`,
+  [ErrorCodes.X_V_FOR_NO_EXPRESSION]: `v-for is missing expression.`,
+  [ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION]: `v-for has invalid expression.`,
   [ErrorCodes.X_V_BIND_NO_EXPRESSION]: `v-bind is missing expression.`,
   [ErrorCodes.X_V_ON_NO_EXPRESSION]: `v-on is missing expression.`,
   [ErrorCodes.X_V_HTML_NO_EXPRESSION]: `v-html is missing epxression.`,
   [ErrorCodes.X_V_HTML_WITH_CHILDREN]: `v-html will override element children.`,
-  [ErrorCodes.X_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET]: `Unexpected custom directive on <slot> outlet.`,
-  [ErrorCodes.X_NAMED_SLOT_ON_COMPONENT]:
+  [ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET]: `Unexpected custom directive on <slot> outlet.`,
+  [ErrorCodes.X_V_SLOT_NAMED_SLOT_ON_COMPONENT]:
     `Named v-slot on component. ` +
     `Named slots should use <template v-slot> syntax nested inside the component.`,
-  [ErrorCodes.X_MIXED_SLOT_USAGE]:
+  [ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE]:
     `Mixed v-slot usage on both the component and nested <template>.` +
     `The default slot should also use <template> syntax when there are other ` +
     `named slots to avoid scope ambiguity.`,
-  [ErrorCodes.X_DUPLICATE_SLOT_NAMES]: `Duplicate slot names found. `,
-  [ErrorCodes.X_EXTRANEOUS_NON_SLOT_CHILDREN]:
+  [ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES]: `Duplicate slot names found. `,
+  [ErrorCodes.X_V_SLOT_EXTRANEOUS_NON_SLOT_CHILDREN]:
     `Extraneous children found when component has explicit slots. ` +
     `These children will be ignored.`,
-  [ErrorCodes.X_MISPLACED_V_SLOT]: `v-slot can only be used on components or <template> tags.`,
+  [ErrorCodes.X_V_SLOT_MISPLACED]: `v-slot can only be used on components or <template> tags.`,
 
   // generic errors
   [ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
index 33ddcb607f787cadf4c2b1b4dcb15ff7e1377129..762ed0d5d570e99777ff69583783c0b65ecef13f 100644 (file)
@@ -228,7 +228,7 @@ export function buildProps(
       if (name === 'slot') {
         if (!isComponent) {
           context.onError(
-            createCompilerError(ErrorCodes.X_MISPLACED_V_SLOT, loc)
+            createCompilerError(ErrorCodes.X_V_SLOT_MISPLACED, loc)
           )
         }
         continue
index 1c65d31776ad3b84e20ab518caed4d8238ac323e..f8862cbbfc3af3d50f44f4b5600724abf498e17f 100644 (file)
@@ -59,7 +59,7 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
       if (directives.length) {
         context.onError(
           createCompilerError(
-            ErrorCodes.X_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
+            ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
             directives[0].loc
           )
         )
index 674b43b5bcaddbce32c8a05df3c1c99aa6ad45f2..fe4f3eda675a25de060ebe75af0d34321ad74484 100644 (file)
@@ -159,12 +159,12 @@ export const transformFor = createStructuralDirectiveTransform(
         }
       } else {
         context.onError(
-          createCompilerError(ErrorCodes.X_FOR_MALFORMED_EXPRESSION, dir.loc)
+          createCompilerError(ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, dir.loc)
         )
       }
     } else {
       context.onError(
-        createCompilerError(ErrorCodes.X_FOR_NO_EXPRESSION, dir.loc)
+        createCompilerError(ErrorCodes.X_V_FOR_NO_EXPRESSION, dir.loc)
       )
     }
   }
index b7268171b3414bb3cff606daf68f7b3c8cc09f20..262233c24904ec1bf76cced6308c1f1b1b2720b5 100644 (file)
@@ -46,7 +46,7 @@ export const transformIf = createStructuralDirectiveTransform(
     ) {
       const loc = dir.exp ? dir.exp.loc : node.loc
       context.onError(
-        createCompilerError(ErrorCodes.X_IF_NO_EXPRESSION, dir.loc)
+        createCompilerError(ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc)
       )
       dir.exp = createSimpleExpression(`true`, false, loc)
     }
@@ -125,7 +125,7 @@ export const transformIf = createStructuralDirectiveTransform(
           }
         } else {
           context.onError(
-            createCompilerError(ErrorCodes.X_ELSE_NO_ADJACENT_IF, node.loc)
+            createCompilerError(ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, node.loc)
           )
         }
         break
index 7bb044e168fdffef16b10271aa7ddb0c5d8977d6..62fee3e6a7dfb5d654e5b0875f52a03c8ca49728 100644 (file)
@@ -119,7 +119,7 @@ export function buildSlots(
     const { arg, exp, loc } = explicitDefaultSlot
     if (arg) {
       context.onError(
-        createCompilerError(ErrorCodes.X_NAMED_SLOT_ON_COMPONENT, loc)
+        createCompilerError(ErrorCodes.X_V_SLOT_NAMED_SLOT_ON_COMPONENT, loc)
       )
     }
     slotsProperties.push(buildDefaultSlot(exp, children, loc))
@@ -148,7 +148,7 @@ export function buildSlots(
     if (explicitDefaultSlot) {
       // already has on-component default slot - this is incorrect usage.
       context.onError(
-        createCompilerError(ErrorCodes.X_MIXED_SLOT_USAGE, slotDir.loc)
+        createCompilerError(ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, slotDir.loc)
       )
       break
     }
@@ -224,7 +224,7 @@ export function buildSlots(
           : buildDynamicSlot(slotName, slotFunction)
       } else {
         context.onError(
-          createCompilerError(ErrorCodes.X_ELSE_NO_ADJACENT_IF, vElse.loc)
+          createCompilerError(ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, vElse.loc)
         )
       }
     } else if ((vFor = findDir(slotElement, 'for'))) {
@@ -247,7 +247,7 @@ export function buildSlots(
         )
       } else {
         context.onError(
-          createCompilerError(ErrorCodes.X_FOR_MALFORMED_EXPRESSION, vFor.loc)
+          createCompilerError(ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, vFor.loc)
         )
       }
     } else {
@@ -255,7 +255,10 @@ export function buildSlots(
       if (staticSlotName) {
         if (seenSlotNames.has(staticSlotName)) {
           context.onError(
-            createCompilerError(ErrorCodes.X_DUPLICATE_SLOT_NAMES, dirLoc)
+            createCompilerError(
+              ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES,
+              dirLoc
+            )
           )
           continue
         }
@@ -268,7 +271,7 @@ export function buildSlots(
   if (hasTemplateSlots && extraneousChild) {
     context.onError(
       createCompilerError(
-        ErrorCodes.X_EXTRANEOUS_NON_SLOT_CHILDREN,
+        ErrorCodes.X_V_SLOT_EXTRANEOUS_NON_SLOT_CHILDREN,
         extraneousChild.loc
       )
     )