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

Class SourceMap

src/SourceMap.ts:84–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82const btoa = /* #__PURE__ */ getBtoa()
83
84export default class SourceMap {
85 declare version: number
86 declare file: string | undefined
87 declare sources: string[]
88 declare sourcesContent: Array<string | null> | undefined
89 declare names: string[]
90 declare mappings: string
91 declare x_google_ignoreList: number[] | undefined
92 declare debugId: string | undefined
93 declare rangeMappings: string | undefined
94
95 constructor(properties: DecodedSourceMap) {
96 this.version = 3
97 this.file = properties.file
98 this.sources = properties.sources
99 this.sourcesContent = properties.sourcesContent
100 this.names = properties.names
101 this.mappings = encode(properties.mappings)
102 if (typeof properties.x_google_ignoreList !== 'undefined') {
103 this.x_google_ignoreList = properties.x_google_ignoreList
104 }
105 if (typeof properties.debugId !== 'undefined') {
106 this.debugId = properties.debugId
107 }
108 if (typeof properties.rangeMappings !== 'undefined') {
109 let shouldOutputRangeMapping = false
110 for (const line of properties.rangeMappings) {
111 if (line.length !== 0) {
112 shouldOutputRangeMapping = true
113 break
114 }
115 }
116 if (shouldOutputRangeMapping) {
117 this.rangeMappings = encodeRangeMappings(properties.rangeMappings)
118 }
119 }
120 }
121
122 /**
123 * Returns the equivalent of `JSON.stringify(map)`
124 */
125 toString(): string {
126 return JSON.stringify(this)
127 }
128
129 /**
130 * Returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
131 * `generateMap(options?: SourceMapOptions): SourceMap;`
132 */
133 toUrl(): string {
134 return `data:application/json;charset=utf-8;base64,${btoa(this.toString())}`
135 }
136}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected