|
205 | 205 | [f]
|
206 | 206 | (let [smf (io/file (str f ".map"))]
|
207 | 207 | (when (.exists smf)
|
208 |
| - (sm/decode (json/read-str (slurp smf) :key-fn keyword))))) |
| 208 | + (as-> @env/*compiler* compiler-env |
| 209 | + (let [t (util/last-modified smf)] |
| 210 | + (if (> t (get-in compiler-env [::source-maps f :last-modified] 0)) |
| 211 | + (swap! env/*compiler* assoc-in [::source-maps f] |
| 212 | + {:last-modified t |
| 213 | + :source-map (sm/decode (json/read-str (slurp smf) :key-fn keyword))}) |
| 214 | + compiler-env)) |
| 215 | + (get-in compiler-env [::source-maps f :source-map]))))) |
209 | 216 |
|
210 | 217 | (defn ^File js-src->cljs-src
|
211 | 218 | "Map a JavaScript output file back to the original ClojureScript source
|
|
261 | 268 | from the classpath."
|
262 | 269 | ([stacktrace] (mapped-stacktrace stacktrace nil))
|
263 | 270 | ([stacktrace opts]
|
264 |
| - (let [read-source-map' (memoize read-source-map) |
265 |
| - ns-info' (memoize ns-info)] |
266 |
| - (vec |
267 |
| - (let [with-calls |
268 |
| - (for [{:keys [function file line column] :as frame} stacktrace] |
269 |
| - ;; need to convert file, a relative URL style path, to host-specific file |
270 |
| - (let [no-source-file? (if-not file |
271 |
| - true |
272 |
| - (.startsWith file "<")) |
273 |
| - rfile (when-not no-source-file? |
274 |
| - (io/file (URL. (.toURL (io/file (util/output-directory opts))) file))) |
275 |
| - [sm {:keys [ns source-file] :as ns-info}] |
276 |
| - (when-not no-source-file? |
277 |
| - ((juxt read-source-map' ns-info') rfile)) |
278 |
| - [line' column' call] (if ns-info |
279 |
| - (mapped-line-column-call sm line column) |
280 |
| - [line column]) |
281 |
| - name' (when (and ns-info function) |
282 |
| - function) |
283 |
| - file' (if no-source-file? |
284 |
| - file |
285 |
| - (string/replace |
286 |
| - (.getCanonicalFile |
287 |
| - (if ns-info |
288 |
| - source-file |
289 |
| - (io/file rfile))) |
290 |
| - (str (System/getProperty "user.dir") File/separator) "")) |
291 |
| - url (or (and ns-info (io/resource (util/ns->relpath ns))) |
292 |
| - (and file (io/resource file)))] |
293 |
| - (merge |
294 |
| - {:function name' |
295 |
| - :call call |
296 |
| - :file (if no-source-file? |
297 |
| - (str "NO_SOURCE_FILE" |
298 |
| - (when file |
299 |
| - (str " " file))) |
300 |
| - (io/file file')) |
301 |
| - :line line' |
302 |
| - :column column'} |
303 |
| - (when url |
304 |
| - {:url url}))))] |
305 |
| - ;; take each non-nil :call and optionally merge it into :function one-level up |
306 |
| - ;; to avoid replacing with local symbols, we only replace munged name if we can munge call symbol back to it |
307 |
| - (map #(merge-with (fn [munged-fn-name unmunged-call-name] |
308 |
| - (if (= munged-fn-name (string/replace (cljs.compiler/munge unmunged-call-name) "." "$")) |
309 |
| - unmunged-call-name |
310 |
| - munged-fn-name)) %1 %2) |
311 |
| - (map #(dissoc % :call) with-calls) |
312 |
| - (concat (rest (map #(if (:call %) |
313 |
| - (hash-map :function (:call %)) |
314 |
| - {}) |
315 |
| - with-calls)) [{}]))))))) |
| 271 | + (vec |
| 272 | + (let [with-calls |
| 273 | + (for [{:keys [function file line column] :as frame} stacktrace] |
| 274 | + ;; need to convert file, a relative URL style path, to host-specific file |
| 275 | + (let [no-source-file? (if-not file |
| 276 | + true |
| 277 | + (.startsWith file "<")) |
| 278 | + rfile (when-not no-source-file? |
| 279 | + (io/file (URL. (.toURL (io/file (util/output-directory opts))) file))) |
| 280 | + [sm {:keys [ns source-file] :as ns-info}] |
| 281 | + (when-not no-source-file? |
| 282 | + ((juxt read-source-map ns-info) rfile)) |
| 283 | + [line' column' call] (if ns-info |
| 284 | + (mapped-line-column-call sm line column) |
| 285 | + [line column]) |
| 286 | + name' (when (and ns-info function) |
| 287 | + function) |
| 288 | + file' (if no-source-file? |
| 289 | + file |
| 290 | + (string/replace |
| 291 | + (.getCanonicalFile |
| 292 | + (if ns-info |
| 293 | + source-file |
| 294 | + (io/file rfile))) |
| 295 | + (str (System/getProperty "user.dir") File/separator) "")) |
| 296 | + url (or (and ns-info (io/resource (util/ns->relpath ns))) |
| 297 | + (and file (io/resource file)))] |
| 298 | + (merge |
| 299 | + {:function name' |
| 300 | + :call call |
| 301 | + :file (if no-source-file? |
| 302 | + (str "NO_SOURCE_FILE" |
| 303 | + (when file |
| 304 | + (str " " file))) |
| 305 | + (io/file file')) |
| 306 | + :line line' |
| 307 | + :column column'} |
| 308 | + (when url |
| 309 | + {:url url}))))] |
| 310 | + ;; take each non-nil :call and optionally merge it into :function one-level up |
| 311 | + ;; to avoid replacing with local symbols, we only replace munged name if we can munge call symbol back to it |
| 312 | + (map #(merge-with (fn [munged-fn-name unmunged-call-name] |
| 313 | + (if (= munged-fn-name (string/replace (cljs.compiler/munge unmunged-call-name) "." "$")) |
| 314 | + unmunged-call-name |
| 315 | + munged-fn-name)) %1 %2) |
| 316 | + (map #(dissoc % :call) with-calls) |
| 317 | + (concat (rest (map #(if (:call %) |
| 318 | + (hash-map :function (:call %)) |
| 319 | + {}) |
| 320 | + with-calls)) [{}])))))) |
316 | 321 |
|
317 | 322 | (defn print-mapped-stacktrace
|
318 | 323 | "Given a vector representing the canonicalized JavaScript stacktrace
|
|
0 commit comments