MCPcopy
hub / github.com/postcss/postcss / loadMap

Method loadMap

lib/previous-map.js:101–145  ·  view source on GitHub ↗
(file, prev)

Source from the content-addressed store, hash-verified

99 }
100
101 loadMap(file, prev) {
102 if (prev === false) return false
103
104 if (prev) {
105 if (typeof prev === 'string') {
106 return prev
107 } else if (typeof prev === 'function') {
108 let prevPath = prev(file)
109 if (prevPath) {
110 let map = this.loadFile(prevPath, file, true)
111 if (!map) {
112 throw new Error(
113 'Unable to load previous source map: ' + prevPath.toString()
114 )
115 }
116 return map
117 }
118 } else if (prev instanceof SourceMapConsumer) {
119 return SourceMapGenerator.fromSourceMap(prev).toString()
120 } else if (prev instanceof SourceMapGenerator) {
121 return prev.toString()
122 } else if (this.isMap(prev)) {
123 return JSON.stringify(prev)
124 } else {
125 throw new Error(
126 'Unsupported previous source map format: ' + prev.toString()
127 )
128 }
129 } else if (this.inline) {
130 return this.decodeInline(this.annotation)
131 } else if (this.annotation) {
132 let map = this.annotation
133 if (file) map = join(dirname(file), map)
134 let unknown = this.loadFile(map, file, false)
135 if (unknown) {
136 try {
137 /* c8 ignore next 4 */
138 this.json = JSON.parse(unknown.replace(/^\)]}'[^\n]*\n/, ''))
139 } catch {
140 return undefined
141 }
142 }
143 return unknown
144 }
145 }
146
147 startWith(string, start) {
148 if (!string) return false

Callers 1

constructorMethod · 0.95

Calls 6

loadFileMethod · 0.95
isMapMethod · 0.95
decodeInlineMethod · 0.95
parseMethod · 0.80
toStringMethod · 0.45
stringifyMethod · 0.45

Tested by

no test coverage detected