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

Method generateDecodedMap

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

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