|
224 | 224 | (when (.exists f')
|
225 | 225 | (ana/parse-ns f'))))
|
226 | 226 |
|
227 |
| -(defn mapped-line-and-column |
| 227 | +(defn- mapped-line-column-call |
228 | 228 | "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." |
230 | 230 | [source-map line column]
|
231 |
| - (let [default [line column]] |
| 231 | + (let [default [line column nil]] |
232 | 232 | ;; source maps are 0 indexed for lines
|
233 | 233 | (if-let [columns (get source-map (dec line))]
|
234 | 234 | (vec
|
235 |
| - (map inc |
| 235 | + (map #(%1 %2) |
| 236 | + [inc inc identity] |
236 | 237 | (map
|
237 | 238 | ;; source maps are 0 indexed for columns
|
238 | 239 | ;; multiple segments may exist at column
|
239 | 240 | ;; the last segment seems most accurate
|
240 | 241 | (last
|
241 |
| - (if-let [mapping (get columns (dec column))] |
242 |
| - mapping |
| 242 | + (or |
| 243 | + (get columns (last (filter #(<= % (dec column)) (sort (keys columns))))) |
243 | 244 | (second (first columns))))
|
244 |
| - [:line :col]))) |
| 245 | + [:line :col :name]))) |
245 | 246 | default)))
|
246 | 247 |
|
247 | 248 | (defn mapped-stacktrace
|
|
263 | 264 | (let [read-source-map' (memoize read-source-map)
|
264 | 265 | ns-info' (memoize ns-info)]
|
265 | 266 | (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)) [{}]))))))) |
302 | 312 |
|
303 | 313 | (defn print-mapped-stacktrace
|
304 | 314 | "Given a vector representing the canonicalized JavaScript stacktrace
|
|
0 commit comments