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

Method generateDecodedMap

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

237 * Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
238 */
239 generateDecodedMap(options?: SourceMapOptions): DecodedSourceMap {
240 options = options || {}
241
242 const sourceIndex = 0
243 const names = Object.keys(this.storedNames)
244 const mappings = new Mappings(options.hires)
245
246 const locate = getLocator(this.original)
247
248 if (this.intro) {
249 mappings.advance(this.intro)
250 }
251
252 this.firstChunk.eachNext((chunk) => {
253 const loc = locate(chunk.start)
254
255 if (chunk.intro.length)
256 mappings.advance(chunk.intro)
257
258 if (chunk.edited) {
259 mappings.addEdit(
260 sourceIndex,
261 chunk.content,
262 loc,
263 chunk.storeName ? names.indexOf(chunk.original) : -1,
264 )
265 }
266 else {
267 mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations)
268 }
269
270 if (chunk.outro.length)
271 mappings.advance(chunk.outro)
272 })
273
274 if (this.outro) {
275 mappings.advance(this.outro)
276 }
277
278 return {
279 file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
280 sources: [
281 options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
282 ],
283 sourcesContent: options.includeContent ? [this.original] : undefined,
284 names,
285 mappings: mappings.raw,
286 x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
287 }
288 }
289
290 /**
291 * 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