Skip to content

Commit e316959

Browse files
mfikesswannodette
authored andcommitted
CLJS-1154: Unmunged function names for stacktrace
When source-mapping stacktraces, obtain unmunged function names from source map
1 parent 501a922 commit e316959

File tree

1 file changed

+53
-43
lines changed

1 file changed

+53
-43
lines changed

src/clj/cljs/repl.clj

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,25 @@
224224
(when (.exists f')
225225
(ana/parse-ns f'))))
226226

227-
(defn mapped-line-and-column
227+
(defn- mapped-line-column-call
228228
"Given a cljs.source-map source map data structure map a generated line
229-
and column back to the original line and column."
229+
and column back to the original line, column, and function called."
230230
[source-map line column]
231-
(let [default [line column]]
231+
(let [default [line column nil]]
232232
;; source maps are 0 indexed for lines
233233
(if-let [columns (get source-map (dec line))]
234234
(vec
235-
(map inc
235+
(map #(%1 %2)
236+
[inc inc identity]
236237
(map
237238
;; source maps are 0 indexed for columns
238239
;; multiple segments may exist at column
239240
;; the last segment seems most accurate
240241
(last
241-
(if-let [mapping (get columns (dec column))]
242-
mapping
242+
(or
243+
(get columns (last (filter #(<= % (dec column)) (sort (keys columns)))))
243244
(second (first columns))))
244-
[:line :col])))
245+
[:line :col :name])))
245246
default)))
246247

247248
(defn mapped-stacktrace
@@ -263,42 +264,51 @@
263264
(let [read-source-map' (memoize read-source-map)
264265
ns-info' (memoize ns-info)]
265266
(vec
266-
(for [{:keys [function file line column] :as frame} stacktrace]
267-
;; need to convert file, a relative URL style path, to host-specific file
268-
(let [no-source-file? (if-not file
269-
true
270-
(.startsWith file "<"))
271-
rfile (when-not no-source-file?
272-
(io/file (URL. (.toURL (io/file (util/output-directory opts))) file)))
273-
[sm {:keys [ns source-file] :as ns-info}]
274-
(when-not no-source-file?
275-
((juxt read-source-map' ns-info') rfile))
276-
[line' column'] (if ns-info
277-
(mapped-line-and-column sm line column)
278-
[line column])
279-
name' (when (and ns-info function)
280-
function)
281-
file' (if no-source-file?
282-
file
283-
(string/replace
284-
(.getCanonicalFile
285-
(if ns-info
286-
source-file
287-
(io/file rfile)))
288-
(str (System/getProperty "user.dir") File/separator) ""))
289-
url (or (and ns-info (io/resource (util/ns->relpath ns)))
290-
(and file (io/resource file)))]
291-
(merge
292-
{:function name'
293-
:file (if no-source-file?
294-
(str "NO_SOURCE_FILE"
295-
(when file
296-
(str " " file)))
297-
(io/file file'))
298-
:line line'
299-
:column column'}
300-
(when url
301-
{:url url}))))))))
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 merge it into :function one-level up
306+
(map merge
307+
(map #(dissoc % :call) with-calls)
308+
(concat (rest (map #(if (:call %)
309+
(hash-map :function (:call %))
310+
{})
311+
with-calls)) [{}])))))))
302312

303313
(defn print-mapped-stacktrace
304314
"Given a vector representing the canonicalized JavaScript stacktrace

0 commit comments

Comments
 (0)