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

Class SourceMap

src/SourceMap.ts:71–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected