Skip to content

Commit

Permalink
perf(compiler-sfc): use faster source map addMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 27, 2023
1 parent d193666 commit 50cde7c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 0 additions & 1 deletion packages/compiler-core/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
17 changes: 8 additions & 9 deletions packages/compiler-sfc/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 50cde7c

Please sign in to comment.