MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / generateDecodedMap

Method generateDecodedMap

src/MagicString.ts:332–382  ·  view source on GitHub ↗

* Generates a sourcemap object with raw mappings in array form, rather than encoded as a string. * Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.

(options?: SourceMapOptions)

Source from the content-addressed store, hash-verified

330 * Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
331 */
332 generateDecodedMap(options?: SourceMapOptions): DecodedSourceMap {
333 options = options || {}
334
335 const sourceIndex = 0
336 const names = Object.keys(this.storedNames)
337 const mappings = new Mappings(options.hires)
338
339 const locate = getLocator(this.original)
340
341 if (this.intro) {
342 mappings.advance(this.intro)
343 }
344
345 this.firstChunk.eachNext((chunk) => {
346 const loc = locate(chunk.start)
347
348 if (chunk.intro.length)
349 mappings.advance(chunk.intro)
350
351 if (chunk.edited) {
352 mappings.addEdit(
353 sourceIndex,
354 chunk.content,
355 loc,
356 chunk.storeName ? names.indexOf(chunk.original) : -1,
357 )
358 }
359 else {
360 mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations)
361 }
362
363 if (chunk.outro.length)
364 mappings.advance(chunk.outro)
365 })
366
367 if (this.outro) {
368 mappings.advance(this.outro)
369 }
370
371 return {
372 file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
373 sources: [
374 options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
375 ],
376 sourcesContent: options.includeContent ? [this.original] : undefined,
377 names,
378 mappings: mappings.raw,
379 x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
380 rangeMappings: mappings.rawRangeMappings,
381 }
382 }
383
384 /**
385 * Generates a version 3 sourcemap.

Callers 1

generateMapMethod · 0.95

Calls 7

advanceMethod · 0.95
addEditMethod · 0.95
addUneditedChunkMethod · 0.95
getLocatorFunction · 0.50
getRelativePathFunction · 0.50
eachNextMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected