|
214 | 214 | .toURI)]
|
215 | 215 | (str (.relativize source-map-parent-juri unrelativized-juri))))))
|
216 | 216 |
|
217 |
| -(defn encode |
| 217 | +(defn encode* |
218 | 218 | "Take an internal source map representation represented as nested
|
219 |
| - sorted maps of file, line, column and return a source map v3 JSON |
220 |
| - string." |
| 219 | + sorted maps of file, line, column and return a v3 representation." |
221 | 220 | [m opts]
|
222 | 221 | (let [lines (atom [[]])
|
223 | 222 | names->idx (atom {})
|
|
252 | 251 | (doseq [[line cols] lines]
|
253 | 252 | (doseq [[col infos] cols]
|
254 | 253 | (encode-cols infos source-idx line col))))
|
255 |
| - (let [source-map-file-contents |
256 |
| - (cond-> {"version" 3 |
257 |
| - "file" (:file opts) |
258 |
| - "sources" (into [] |
259 |
| - (let [paths (keys m) |
260 |
| - f (comp |
261 |
| - (if (true? (:source-map-timestamp opts)) |
262 |
| - #(str % "?rel=" (System/currentTimeMillis)) |
263 |
| - identity) |
264 |
| - (if (or (:output-dir opts) |
265 |
| - (:source-map-path opts)) |
266 |
| - #(relativize-path % opts) |
267 |
| - #(last (string/split % #"/"))))] |
268 |
| - (map f paths))) |
269 |
| - "lineCount" (:lines opts) |
270 |
| - "mappings" (->> (lines->segs (concat preamble-lines @lines)) |
271 |
| - (map #(string/join "," %)) |
272 |
| - (string/join ";")) |
273 |
| - "names" (into [] |
274 |
| - (map (set/map-invert @names->idx) |
275 |
| - (range (count @names->idx))))} |
276 |
| - (:sources-content opts) |
277 |
| - (assoc "sourcesContent" (:sources-content opts)))] |
278 |
| - (if (true? (:source-map-pretty-print opts)) |
279 |
| - (with-out-str |
280 |
| - (json/pprint |
281 |
| - source-map-file-contents |
282 |
| - :escape-slash false)) |
283 |
| - (json/write-str source-map-file-contents))))) |
| 254 | + |
| 255 | + (cond-> {"version" 3 |
| 256 | + "file" (:file opts) |
| 257 | + "sources" (into [] |
| 258 | + (let [paths (keys m) |
| 259 | + f (comp |
| 260 | + (if (true? (:source-map-timestamp opts)) |
| 261 | + #(str % "?rel=" (System/currentTimeMillis)) |
| 262 | + identity) |
| 263 | + (if (or (:output-dir opts) |
| 264 | + (:source-map-path opts)) |
| 265 | + #(relativize-path % opts) |
| 266 | + #(last (string/split % #"/"))))] |
| 267 | + (map f paths))) |
| 268 | + "lineCount" (:lines opts) |
| 269 | + "mappings" (->> (lines->segs (concat preamble-lines @lines)) |
| 270 | + (map #(string/join "," %)) |
| 271 | + (string/join ";")) |
| 272 | + "names" (into [] |
| 273 | + (map (set/map-invert @names->idx) |
| 274 | + (range (count @names->idx))))} |
| 275 | + |
| 276 | + (:sources-content opts) |
| 277 | + (assoc "sourcesContent" (:sources-content opts))))) |
| 278 | + |
| 279 | +(defn encode |
| 280 | + "Take an internal source map representation represented as nested |
| 281 | + sorted maps of file, line, column and return a source map v3 JSON |
| 282 | + string." |
| 283 | + [m opts] |
| 284 | + (let [source-map-file-contents (encode* m opts)] |
| 285 | + (if (true? (:source-map-pretty-print opts)) |
| 286 | + (with-out-str |
| 287 | + (json/pprint |
| 288 | + source-map-file-contents |
| 289 | + :escape-slash false)) |
| 290 | + (json/write-str source-map-file-contents)))) |
284 | 291 |
|
285 | 292 | ;; -----------------------------------------------------------------------------
|
286 | 293 | ;; Merging
|
|
0 commit comments