|
263 | 263 | [:line :col :name])))
|
264 | 264 | default)))
|
265 | 265 |
|
| 266 | +(defn- mapped-frame |
| 267 | + "Given opts and a canonicalized JavaScript stacktrace frame, return the |
| 268 | + ClojureScript frame." |
| 269 | + [{:keys [function file line column]} opts] |
| 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 (util/ns->source 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 | + |
266 | 306 | (defn mapped-stacktrace
|
267 | 307 | "Given a vector representing the canonicalized JavaScript stacktrace
|
268 | 308 | return the ClojureScript stacktrace. The canonical stacktrace must be
|
|
280 | 320 | ([stacktrace] (mapped-stacktrace stacktrace nil))
|
281 | 321 | ([stacktrace opts]
|
282 | 322 | (vec
|
283 |
| - (let [with-calls |
284 |
| - (for [{:keys [function file line column] :as frame} stacktrace] |
285 |
| - ;; need to convert file, a relative URL style path, to host-specific file |
286 |
| - (let [no-source-file? (if-not file |
287 |
| - true |
288 |
| - (.startsWith file "<")) |
289 |
| - rfile (when-not no-source-file? |
290 |
| - (io/file (URL. (.toURL (io/file (util/output-directory opts))) file))) |
291 |
| - [sm {:keys [ns source-file] :as ns-info}] |
292 |
| - (when-not no-source-file? |
293 |
| - ((juxt read-source-map ns-info) rfile)) |
294 |
| - [line' column' call] (if ns-info |
295 |
| - (mapped-line-column-call sm line column) |
296 |
| - [line column]) |
297 |
| - name' (when (and ns-info function) |
298 |
| - function) |
299 |
| - file' (if no-source-file? |
300 |
| - file |
301 |
| - (string/replace |
302 |
| - (.getCanonicalFile |
303 |
| - (if ns-info |
304 |
| - source-file |
305 |
| - (io/file rfile))) |
306 |
| - (str (System/getProperty "user.dir") File/separator) "")) |
307 |
| - url (or (and ns-info (util/ns->source ns)) |
308 |
| - (and file (io/resource file)))] |
309 |
| - (merge |
310 |
| - {:function name' |
311 |
| - :call call |
312 |
| - :file (if no-source-file? |
313 |
| - (str "NO_SOURCE_FILE" |
314 |
| - (when file |
315 |
| - (str " " file))) |
316 |
| - (io/file file')) |
317 |
| - :line line' |
318 |
| - :column column'} |
319 |
| - (when url |
320 |
| - {:url url}))))] |
| 323 | + (let [mapped-frames (map (memoize #(mapped-frame % opts)) stacktrace)] |
321 | 324 | ;; take each non-nil :call and optionally merge it into :function one-level up
|
322 | 325 | ;; to avoid replacing with local symbols, we only replace munged name if we can munge call symbol back to it
|
323 | 326 | (map #(merge-with (fn [munged-fn-name unmunged-call-name]
|
324 | 327 | (if (= munged-fn-name (string/replace (cljs.compiler/munge unmunged-call-name) "." "$"))
|
325 | 328 | unmunged-call-name
|
326 | 329 | munged-fn-name)) %1 %2)
|
327 |
| - (map #(dissoc % :call) with-calls) |
| 330 | + (map #(dissoc % :call) mapped-frames) |
328 | 331 | (concat (rest (map #(if (:call %)
|
329 | 332 | (hash-map :function (:call %))
|
330 | 333 | {})
|
331 |
| - with-calls)) [{}])))))) |
| 334 | + mapped-frames)) [{}])))))) |
332 | 335 |
|
333 | 336 | (defn print-mapped-stacktrace
|
334 | 337 | "Given a vector representing the canonicalized JavaScript stacktrace
|
|
0 commit comments