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

Class SourceMap

src/SourceMap.ts:70–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68const btoa = /* #__PURE__ */ getBtoa()
69
70export default class SourceMap {
71 declare version: number
72 declare file: string | undefined
73 declare sources: string[]
74 declare sourcesContent: Array<string | null> | undefined
75 declare names: string[]
76 declare mappings: string
77 declare x_google_ignoreList: number[] | undefined
78 declare debugId: string | undefined
79
80 constructor(properties: DecodedSourceMap) {
81 this.version = 3
82 this.file = properties.file
83 this.sources = properties.sources
84 this.sourcesContent = properties.sourcesContent
85 this.names = properties.names
86 this.mappings = encode(properties.mappings)
87 if (typeof properties.x_google_ignoreList !== 'undefined') {
88 this.x_google_ignoreList = properties.x_google_ignoreList
89 }
90 if (typeof properties.debugId !== 'undefined') {
91 this.debugId = properties.debugId
92 }
93 }
94
95 /**
96 * Returns the equivalent of `JSON.stringify(map)`
97 */
98 toString(): string {
99 return JSON.stringify(this)
100 }
101
102 /**
103 * Returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
104 * `generateMap(options?: SourceMapOptions): SourceMap;`
105 */
106 toUrl(): string {
107 return `data:application/json;charset=utf-8;base64,${btoa(this.toString())}`
108 }
109}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected