@@ -490,35 +490,46 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
490
490
; ; -----------------------------------------------------------------------------
491
491
; ; Stacktrace Mapping
492
492
493
+ (defn remove-ext [file]
494
+ (-> file
495
+ (string/replace #"\. js$" " " )
496
+ (string/replace #"\. cljs$" " " )
497
+ (string/replace #"\. cljc$" " " )
498
+ (string/replace #"\. clj$" " " )))
499
+
493
500
(defn mapped-line-column-call
494
501
" Given a cljs.source-map source map data structure map a generated line
495
502
and column back to the original line, column, and function called."
496
- [source-map line column]
497
- ; ; source maps are 0 indexed for columns
498
- ; ; multiple segments may exist at column
499
- ; ; the last segment seems most accurate
500
- (letfn [(get-best-column [columns column]
501
- (last (or (get columns
502
- (last (filter #(<= % (dec column))
503
- (sort (keys columns)))))
504
- (second (first columns)))))
505
- (adjust [mapped]
506
- (vec (map #(%1 %2 ) [inc inc identity] mapped)))]
507
- (let [default [line column nil ]]
508
- ; ; source maps are 0 indexed for lines
509
- (if-let [columns (get source-map (dec line))]
510
- (adjust (map (get-best-column columns column) [:line :col :name ]))
511
- default ))))
503
+ [sms file line column]
504
+ (let [source-map (get sms (symbol (string/replace (remove-ext file) " /" " ." )))]
505
+ ; ; source maps are 0 indexed for columns
506
+ ; ; multiple segments may exist at column
507
+ ; ; the last segment seems most accurate
508
+ (letfn [(get-best-column [columns column]
509
+ (last (or (get columns
510
+ (last (filter #(<= % (dec column))
511
+ (sort (keys columns)))))
512
+ (second (first columns)))))
513
+ (adjust [mapped]
514
+ (vec (map #(%1 %2 ) [inc inc identity] mapped)))]
515
+ (let [default [line column nil ]]
516
+ ; ; source maps are 0 indexed for lines
517
+ (if-let [columns (get source-map (dec line))]
518
+ (adjust (map (get-best-column columns column) [:line :col :name ]))
519
+ default )))))
512
520
513
521
(defn mapped-frame
514
522
" Given opts and a canonicalized JavaScript stacktrace frame, return the
515
523
ClojureScript frame."
516
- [{:keys [function file line column]} sm opts]
524
+ [{:keys [function file line column]} sms opts]
517
525
(let [no-source-file? (if-not file true (starts-with? file " <" ))
518
- [line' column' call] (mapped-line-column-call sm line column)
519
- file' (if (ends-with? file " .js" )
520
- (str (subs file 0 (- (count file) 3 )) " .cljs" )
521
- file)]
526
+ [line' column' call] (if no-source-file?
527
+ [line column nil ]
528
+ (mapped-line-column-call sms file line column))
529
+ file' (when-not no-source-file?
530
+ (if (ends-with? file " .js" )
531
+ (str (subs file 0 (- (count file) 3 )) " .cljs" )
532
+ file))]
522
533
{:function function
523
534
:call call
524
535
:file (if no-source-file?
@@ -541,8 +552,9 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
541
552
identifier delimited by angle brackets. The returned mapped stacktrace will
542
553
also contain :url entries to the original sources if it can be determined
543
554
from the classpath."
544
- ([stacktrace sm] (mapped-stacktrace stacktrace sm nil ))
545
- ([stacktrace sm opts]
555
+ ([stacktrace sms]
556
+ (mapped-stacktrace stacktrace sms nil ))
557
+ ([stacktrace sms opts]
546
558
(letfn [(call->function [x]
547
559
(if (:call x)
548
560
(hash-map :function (:call x))
@@ -555,7 +567,7 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
555
567
unmunged-call-name
556
568
munged-fn-name))
557
569
function call))]
558
- (let [mapped-frames (map (memoize #(mapped-frame % sm opts)) stacktrace)]
570
+ (let [mapped-frames (map (memoize #(mapped-frame % sms opts)) stacktrace)]
559
571
; ; take each non-nil :call and optionally merge it into :function one-level
560
572
; ; up to avoid replacing with local symbols, we only replace munged name if
561
573
; ; we can munge call symbol back to it
@@ -564,14 +576,15 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
564
576
(concat (rest (map call->function mapped-frames)) [{}])))))))
565
577
566
578
(defn mapped-stacktrace-str
567
- " Given a vector representing the canonicalized JavaScript stacktrace
568
- print the ClojureScript stacktrace. See mapped-stacktrace."
569
- ([stacktrace sm]
570
- (mapped-stacktrace-str stacktrace sm nil ))
571
- ([stacktrace sm opts]
579
+ " Given a vector representing the canonicalized JavaScript stacktrace and a map
580
+ of library names to decoded source maps, print the ClojureScript stacktrace .
581
+ See mapped-stacktrace."
582
+ ([stacktrace sms]
583
+ (mapped-stacktrace-str stacktrace sms nil ))
584
+ ([stacktrace sms opts]
572
585
(with-out-str
573
586
(doseq [{:keys [function file line column]}
574
- (mapped-stacktrace stacktrace sm opts)]
587
+ (mapped-stacktrace stacktrace sms opts)]
575
588
(println " \t "
576
589
(str (when function (str function " " ))
577
590
" (" file (when line (str " :" line))
@@ -589,26 +602,27 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
589
602
:output-to " samples/hello/out/hello.js"
590
603
:source-map true })
591
604
592
- (def sm
593
- (sm/decode
594
- (json/read-str
595
- (slurp " samples/hello/out/hello/core.js.map" )
596
- :key-fn keyword)))
605
+ (def sms
606
+ {'hello.core
607
+ (sm/decode
608
+ (json/read-str
609
+ (slurp " samples/hello/out/hello/core.js.map" )
610
+ :key-fn keyword))})
597
611
598
- (pp/pprint sm )
612
+ (pp/pprint sms )
599
613
600
614
; ; maps to :line 5 :column 24
601
615
(mapped-stacktrace
602
616
[{:file " hello/core.js"
603
617
:function " first"
604
618
:line 6
605
619
:column 0 }]
606
- sm {:output-dir " samples/hello/out" })
620
+ sms {:output-dir " samples/hello/out" })
607
621
608
622
(mapped-stacktrace-str
609
623
[{:file " hello/core.js"
610
624
:function " first"
611
625
:line 6
612
626
:column 0 }]
613
- sm {:output-dir " samples/hello/out" })
627
+ sms {:output-dir " samples/hello/out" })
614
628
)
0 commit comments