Преглед на файлове

perf(compiler-sfc): use faster source map addMapping

Evan You преди 2 години
родител
ревизия
50cde7cfbc
променени са 3 файла, в които са добавени 9 реда и са изтрити 10 реда
  1. 0 1
      packages/compiler-core/src/codegen.ts
  2. 8 9
      packages/compiler-sfc/src/parse.ts
  3. 1 0
      packages/global.d.ts

+ 0 - 1
packages/compiler-core/src/codegen.ts

@@ -227,7 +227,6 @@ function createCodegenContext(
     // lazy require source-map implementation, only in non-browser builds
     context.map = new SourceMapGenerator()
     context.map.setSourceContent(filename, context.source)
-    // @ts-ignore
     context.map._sources.add(filename)
   }
 

+ 8 - 9
packages/compiler-sfc/src/parse.ts

@@ -339,22 +339,21 @@ function generateSourceMap(
     sourceRoot: sourceRoot.replace(/\\/g, '/')
   })
   map.setSourceContent(filename, source)
+  map._sources.add(filename)
   generated.split(splitRE).forEach((line, index) => {
     if (!emptyRE.test(line)) {
       const originalLine = index + 1 + lineOffset
       const generatedLine = index + 1
       for (let i = 0; i < line.length; i++) {
         if (!/\s/.test(line[i])) {
-          map.addMapping({
+          map._mappings.add({
+            originalLine,
+            originalColumn: i,
+            generatedLine,
+            generatedColumn: i,
             source: filename,
-            original: {
-              line: originalLine,
-              column: i
-            },
-            generated: {
-              line: generatedLine,
-              column: i
-            }
+            // @ts-ignore
+            name: null
           })
         }
       }

+ 1 - 0
packages/global.d.ts

@@ -48,6 +48,7 @@ declare module 'source-map-js' {
   export interface SourceMapGenerator {
     // SourceMapGenerator has this method but the types do not include it
     toJSON(): RawSourceMap
+    _sources: Set<string>
     _names: Set<string>
     _mappings: {
       add(mapping: MappingItem): void