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

Method generateDecodedMap

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

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