Skip to content

Commit

Permalink
CLJS-1034: Support REPL-defined functions in stacktrace infrastructure
Browse files Browse the repository at this point in the history
Make `cljs.repl/mapped-stacktrace` nil safe for all the stack element
components.

If handed :file that starts with "<" or nil :file prepend "NO_SOURCE_FILE"
a la Clojure.

Smarter printing for nil values of a stack element.
  • Loading branch information
dnolen committed Mar 4, 2015
1 parent cf5fccc commit de15ba8
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/clj/cljs/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,39 @@
(vec
(for [{:keys [function file line column] :as frame} stacktrace]
;; need to convert file, a relative URL style path, to host-specific file
(let [rfile (io/file (URL. (.toURL (io/file (util/output-directory opts))) file))
(let [no-source-file? (if-not file
true
(.startsWith file "<"))
rfile (when-not no-source-file?
(io/file (URL. (.toURL (io/file (util/output-directory opts))) file)))
[sm {:keys [ns source-file] :as ns-info}]
((juxt read-source-map' ns-info') rfile)
(when-not no-source-file?
((juxt read-source-map' ns-info') rfile))
[line' column'] (if ns-info
(mapped-line-and-column sm line column)
[line column])
name' (if (and ns-info function)
(symbol (name ns) (cljrepl/demunge function))
function)
file' (string/replace
(.getCanonicalFile
(if ns-info
source-file
(io/file rfile)))
(str (System/getProperty "user.dir") File/separator) "")
file' (if no-source-file?
file
(string/replace
(.getCanonicalFile
(if ns-info
source-file
(io/file rfile)))
(str (System/getProperty "user.dir") File/separator) ""))
url (or (and ns-info (io/resource (util/ns->relpath ns)))
(io/resource file))]
(and file (io/resource file)))]
(merge
{:function name'
:file (io/file file')
:line line'
:column column'}
:file (if no-source-file?
(str "NO_SOURCE_FILE"
(when file
(str " " file)))
(io/file file'))
:line line'
:column column'}
(when url
{:url url}))))))))

Expand All @@ -293,8 +304,8 @@
(doseq [{:keys [function file line column]}
(mapped-stacktrace stacktrace opts)]
((:print opts) "\t"
(str (and function (str function " "))
"(" file ":" line ":" column ")")))))
(str (when function (str function " "))
"(" file (when line (str ":" line)) (when column (str ":" column)) ")")))))

(comment
(cljsc/build "samples/hello/src"
Expand Down

0 comments on commit de15ba8

Please sign in to comment.