MCPcopy
hub / github.com/vuejs/core / mapLines

Function mapLines

packages/compiler-sfc/src/compileTemplate.ts:277–328  ·  view source on GitHub ↗
(oldMap: RawSourceMap, newMap: RawSourceMap)

Source from the content-addressed store, hash-verified

275}
276
277function mapLines(oldMap: RawSourceMap, newMap: RawSourceMap): RawSourceMap {
278 if (!oldMap) return newMap
279 if (!newMap) return oldMap
280
281 const oldMapConsumer = new SourceMapConsumer(oldMap)
282 const newMapConsumer = new SourceMapConsumer(newMap)
283 const mergedMapGenerator = new SourceMapGenerator()
284
285 newMapConsumer.eachMapping(m => {
286 if (m.originalLine == null) {
287 return
288 }
289
290 const origPosInOldMap = oldMapConsumer.originalPositionFor({
291 line: m.originalLine,
292 column: m.originalColumn!,
293 })
294
295 if (origPosInOldMap.source == null) {
296 return
297 }
298
299 mergedMapGenerator.addMapping({
300 generated: {
301 line: m.generatedLine,
302 column: m.generatedColumn,
303 },
304 original: {
305 line: origPosInOldMap.line, // map line
306 // use current column, since the oldMap produced by @vue/compiler-sfc
307 // does not
308 column: m.originalColumn!,
309 },
310 source: origPosInOldMap.source,
311 name: origPosInOldMap.name,
312 })
313 })
314
315 // source-map's type definition is incomplete
316 const generator = mergedMapGenerator as any
317 ;(oldMapConsumer as any).sources.forEach((sourceFile: string) => {
318 generator._sources.add(sourceFile)
319 const sourceContent = oldMapConsumer.sourceContentFor(sourceFile)
320 if (sourceContent != null) {
321 mergedMapGenerator.setSourceContent(sourceFile, sourceContent)
322 }
323 })
324
325 generator._sourceRoot = oldMap.sourceRoot
326 generator._file = oldMap.file
327 return generator.toJSON()
328}
329
330function patchErrors(
331 errors: CompilerError[],

Callers 1

doCompileTemplateFunction · 0.85

Calls 3

forEachMethod · 0.80
setSourceContentMethod · 0.80
toJSONMethod · 0.80

Tested by

no test coverage detected