Преглед изворни кода

feat(compiler-sfc): improve sfc source map generation

Evan You пре 6 година
родитељ
комит
698c8d35d5
1 измењених фајлова са 15 додато и 11 уклоњено
  1. 15 11
      packages/compiler-sfc/src/parse.ts

+ 15 - 11
packages/compiler-sfc/src/parse.ts

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