]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf(compiler-sfc): use faster source map addMapping
authorEvan You <yyx990803@gmail.com>
Mon, 27 Nov 2023 06:42:12 +0000 (14:42 +0800)
committerEvan You <yyx990803@gmail.com>
Mon, 27 Nov 2023 06:42:12 +0000 (14:42 +0800)
packages/compiler-core/src/codegen.ts
packages/compiler-sfc/src/parse.ts
packages/global.d.ts

index 12a1bcd487d5831e6e524cf18fc57c13b54f03a4..9fe2bb249734b71d8fd9bfb314cb7167cf93d9d0 100644 (file)
@@ -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)
   }
 
index ba8517658fae597b772b98d8bf2be896c4eea26a..b7d9ee652b871047ff10c2d20089819c36132b39 100644 (file)
@@ -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
           })
         }
       }
index 70b9d158b2cdebecc0a40914dc99cad7cf3a7f58..f53d7b71acd89d581eea291b63f5315a2f6aa36a 100644 (file)
@@ -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