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

Method generateDecodedMap

src/MagicString.ts:337–387  ·  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

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