]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
workflow: make template-explorer error tolerant
authorEvan You <yyx990803@gmail.com>
Tue, 8 Oct 2019 21:31:22 +0000 (17:31 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 8 Oct 2019 21:31:22 +0000 (17:31 -0400)
packages/template-explorer/src/index.ts

index 7e73218265541afc0bf179dd4780d6cd56d16c7b..5bf7b10bf0ac95f8e8416d11776715dcbb266391 100644 (file)
@@ -25,13 +25,20 @@ window.init = () => {
   function compileCode(source: string): string {
     console.clear()
     try {
+      const errors: CompilerError[] = []
       const { code, ast, map } = compile(source, {
         filename: 'template.vue',
         ...compilerOptions,
         sourceMap: true,
-        onError: displayError
+        onError: err => {
+          errors.push(err)
+        }
       })
-      monaco.editor.setModelMarkers(editor.getModel()!, `@vue/compiler-dom`, [])
+      monaco.editor.setModelMarkers(
+        editor.getModel()!,
+        `@vue/compiler-dom`,
+        errors.filter(e => e.loc).map(formatError)
+      )
       console.log(`AST: `, ast)
       lastSuccessfulCode = code + `\n\n// Check the console for the AST`
       lastSuccessfulMap = new window._deps['source-map'].SourceMapConsumer(map)
@@ -42,22 +49,17 @@ window.init = () => {
     return lastSuccessfulCode
   }
 
-  function displayError(err: CompilerError) {
-    const loc = err.loc
-    if (loc) {
-      monaco.editor.setModelMarkers(editor.getModel()!, `@vue/compiler-dom`, [
-        {
-          severity: monaco.MarkerSeverity.Error,
-          startLineNumber: loc.start.line,
-          startColumn: loc.start.column,
-          endLineNumber: loc.end.line,
-          endColumn: loc.end.column,
-          message: `Vue template compilation error: ${err.message}`,
-          code: String(err.code)
-        }
-      ])
+  function formatError(err: CompilerError) {
+    const loc = err.loc!
+    return {
+      severity: monaco.MarkerSeverity.Error,
+      startLineNumber: loc.start.line,
+      startColumn: loc.start.column,
+      endLineNumber: loc.end.line,
+      endColumn: loc.end.column,
+      message: `Vue template compilation error: ${err.message}`,
+      code: String(err.code)
     }
-    throw err
   }
 
   function reCompile() {