]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(compiler-sfc): improve sfc source map generation
authorEvan You <yyx990803@gmail.com>
Thu, 7 May 2020 03:46:33 +0000 (23:46 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 7 May 2020 05:37:34 +0000 (01:37 -0400)
packages/compiler-sfc/src/parse.ts

index 04310acbfa2f08e7fd1df0b0ba4687f8e5f6cf2c..cc6e4a8e22a01b73ede2f6b4fb0d7ca9afb811a7 100644 (file)
@@ -255,17 +255,21 @@ function generateSourceMap(
   map.setSourceContent(filename, source)
   generated.split(splitRE).forEach((line, index) => {
     if (!emptyRE.test(line)) {
-      map.addMapping({
-        source: filename,
-        original: {
-          line: index + 1 + lineOffset,
-          column: 0
-        },
-        generated: {
-          line: index + 1,
-          column: 0
-        }
-      })
+      const originalLine = index + 1 + lineOffset
+      const generatedLine = index + 1
+      for (let i = 0; i < line.length; i++) {
+        map.addMapping({
+          source: filename,
+          original: {
+            line: originalLine,
+            column: i
+          },
+          generated: {
+            line: generatedLine,
+            column: i
+          }
+        })
+      }
     }
   })
   return JSON.parse(map.toString())