Skip to content

Commit 50cde7c

Browse files
committedNov 27, 2023
perf(compiler-sfc): use faster source map addMapping
1 parent d193666 commit 50cde7c

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed
 

‎packages/compiler-core/src/codegen.ts

-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ function createCodegenContext(
227227
// lazy require source-map implementation, only in non-browser builds
228228
context.map = new SourceMapGenerator()
229229
context.map.setSourceContent(filename, context.source)
230-
// @ts-ignore
231230
context.map._sources.add(filename)
232231
}
233232

‎packages/compiler-sfc/src/parse.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -339,22 +339,21 @@ function generateSourceMap(
339339
sourceRoot: sourceRoot.replace(/\\/g, '/')
340340
})
341341
map.setSourceContent(filename, source)
342+
map._sources.add(filename)
342343
generated.split(splitRE).forEach((line, index) => {
343344
if (!emptyRE.test(line)) {
344345
const originalLine = index + 1 + lineOffset
345346
const generatedLine = index + 1
346347
for (let i = 0; i < line.length; i++) {
347348
if (!/\s/.test(line[i])) {
348-
map.addMapping({
349+
map._mappings.add({
350+
originalLine,
351+
originalColumn: i,
352+
generatedLine,
353+
generatedColumn: i,
349354
source: filename,
350-
original: {
351-
line: originalLine,
352-
column: i
353-
},
354-
generated: {
355-
line: generatedLine,
356-
column: i
357-
}
355+
// @ts-ignore
356+
name: null
358357
})
359358
}
360359
}

‎packages/global.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ declare module 'source-map-js' {
4848
export interface SourceMapGenerator {
4949
// SourceMapGenerator has this method but the types do not include it
5050
toJSON(): RawSourceMap
51+
_sources: Set<string>
5152
_names: Set<string>
5253
_mappings: {
5354
add(mapping: MappingItem): void

0 commit comments

Comments
 (0)
Please sign in to comment.