]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: generate codeframe for compiler deprecations
authorEvan You <yyx990803@gmail.com>
Fri, 16 Apr 2021 15:51:47 +0000 (11:51 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 16 Apr 2021 15:51:47 +0000 (11:51 -0400)
packages/compiler-core/src/compat/compatConfig.ts
packages/compiler-core/src/options.ts
packages/vue-compat/src/index.ts
packages/vue/src/index.ts

index 92e2c63db4af6fef223190af6b4258900309c90a..3c69e00c8f544854019147087a0aa6b4ce1d83b5 100644 (file)
@@ -124,13 +124,8 @@ export function warnDeprecation(
     typeof message === 'function' ? message(...args) : message
   }${link ? `\n  Details: ${link}` : ``}`
 
-  if (loc) {
-    const err = new SyntaxError(msg) as CompilerError
-    err.code = key
-    err.loc = loc
-    context.onWarn(err)
-    return
-  }
-
-  context.onWarn(msg)
+  const err = new SyntaxError(msg) as CompilerError
+  err.code = key
+  if (loc) err.loc = loc
+  context.onWarn(err)
 }
index 62fd2f1cb23565a675d43d6fee30d312df31a622..08cb12d89d7a2f6b5609c5e195fa931751e35af1 100644 (file)
@@ -10,7 +10,7 @@ import { CompilerCompatOptions } from './compat/compatConfig'
 import { ParserPlugin } from '@babel/parser'
 
 export interface ErrorHandlingOptions {
-  onWarn?: (msg: string | CompilerError) => void
+  onWarn?: (warning: CompilerError) => void
   onError?: (error: CompilerError) => void
 }
 
index 09036c5d4f79ead4fdf04e32a8ff97fdb430a739..abd669d0cc3942b252961aec54d0d2072e3a65d6 100644 (file)
@@ -1,7 +1,7 @@
 // This entry is the "full-build" that includes both the runtime
 // and the compiler, and supports on-the-fly compilation of the template option.
 import { initDev } from './dev'
-import { compile, CompilerOptions, CompilerError } from '@vue/compiler-dom'
+import { compile, CompilerError, CompilerOptions } from '@vue/compiler-dom'
 import {
   registerRuntimeCompiler,
   RenderFunction,
@@ -55,27 +55,32 @@ function compileToFunction(
     extend(
       {
         hoistStatic: true,
-        onError(err: CompilerError) {
+        onError(err) {
           if (__DEV__) {
-            const message = `Template compilation error: ${err.message}`
-            const codeFrame =
-              err.loc &&
-              generateCodeFrame(
-                template as string,
-                err.loc.start.offset,
-                err.loc.end.offset
-              )
-            warn(codeFrame ? `${message}\n${codeFrame}` : message)
+            onError(err)
           } else {
             /* istanbul ignore next */
             throw err
           }
-        }
-      },
+        },
+        onWarn: __DEV__ ? onError : NOOP
+      } as CompilerOptions,
       options
     )
   )
 
+  function onError(err: CompilerError) {
+    const message = `Template compilation error: ${err.message}`
+    const codeFrame =
+      err.loc &&
+      generateCodeFrame(
+        template as string,
+        err.loc.start.offset,
+        err.loc.end.offset
+      )
+    warn(codeFrame ? `${message}\n${codeFrame}` : message)
+  }
+
   // The wildcard import results in a huge object with every export
   // with keys that cannot be mangled, and can be quite heavy size-wise.
   // In the global build we know `Vue` is available globally so we can avoid
index 4874bb0d5f2474af254ac342152cea921d8cb7a2..ced879a928ae1008a0f1857c867c5e5cc9126628 100644 (file)
@@ -49,27 +49,32 @@ function compileToFunction(
     extend(
       {
         hoistStatic: true,
-        onError(err: CompilerError) {
+        onError(err) {
           if (__DEV__) {
-            const message = `Template compilation error: ${err.message}`
-            const codeFrame =
-              err.loc &&
-              generateCodeFrame(
-                template as string,
-                err.loc.start.offset,
-                err.loc.end.offset
-              )
-            warn(codeFrame ? `${message}\n${codeFrame}` : message)
+            onError(err)
           } else {
             /* istanbul ignore next */
             throw err
           }
-        }
-      },
+        },
+        onWarn: __DEV__ ? onError : NOOP
+      } as CompilerOptions,
       options
     )
   )
 
+  function onError(err: CompilerError) {
+    const message = `Template compilation error: ${err.message}`
+    const codeFrame =
+      err.loc &&
+      generateCodeFrame(
+        template as string,
+        err.loc.start.offset,
+        err.loc.end.offset
+      )
+    warn(codeFrame ? `${message}\n${codeFrame}` : message)
+  }
+
   // The wildcard import results in a huge object with every export
   // with keys that cannot be mangled, and can be quite heavy size-wise.
   // In the global build we know `Vue` is available globally so we can avoid