From: Evan You Date: Mon, 27 Nov 2023 06:42:12 +0000 (+0800) Subject: perf(compiler-sfc): use faster source map addMapping X-Git-Tag: v3.4.0-alpha.2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50cde7cfbcc49022ba88f5f69fa9b930b483c282;p=thirdparty%2Fvuejs%2Fcore.git perf(compiler-sfc): use faster source map addMapping --- diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index 12a1bcd487..9fe2bb2497 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/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) } diff --git a/packages/compiler-sfc/src/parse.ts b/packages/compiler-sfc/src/parse.ts index ba8517658f..b7d9ee652b 100644 --- a/packages/compiler-sfc/src/parse.ts +++ b/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 }) } } diff --git a/packages/global.d.ts b/packages/global.d.ts index 70b9d158b2..f53d7b71ac 100644 --- a/packages/global.d.ts +++ b/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 _names: Set _mappings: { add(mapping: MappingItem): void