Skip to content

Commit ab1e922

Browse files
committed
improve behavior of cljs.repl/mapped-stacktrace if source file does not
exist
1 parent 0c0602a commit ab1e922

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/clj/cljs/repl.clj

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,26 @@
220220
(when-let [smf (util/file-or-resource (str f ".map"))]
221221
(let [ns (if (= f "cljs/core.aot.js")
222222
'cljs.core
223-
(:ns (ana/parse-ns (js-src->cljs-src f))))]
224-
(as-> @env/*compiler* compiler-env
225-
(let [t (util/last-modified smf)]
226-
(if (or (and (= ns 'cljs.core)
227-
(nil? (get-in compiler-env [::source-maps ns])))
228-
(and (not= ns 'cljs.core)
229-
(> t (get-in compiler-env [::source-maps ns :last-modified] 0))))
230-
(swap! env/*compiler* assoc-in [::source-maps ns]
231-
{:last-modified t
232-
:source-map (sm/decode (json/read-str (slurp smf) :key-fn keyword))})
233-
compiler-env))
234-
(get-in compiler-env [::source-maps ns :source-map])))))
223+
(some-> (js-src->cljs-src f) ana/parse-ns :ns))]
224+
(when ns
225+
(as-> @env/*compiler* compiler-env
226+
(let [t (util/last-modified smf)]
227+
(if (or (and (= ns 'cljs.core)
228+
(nil? (get-in compiler-env [::source-maps ns])))
229+
(and (not= ns 'cljs.core)
230+
(> t (get-in compiler-env [::source-maps ns :last-modified] 0))))
231+
(swap! env/*compiler* assoc-in [::source-maps ns]
232+
{:last-modified t
233+
:source-map (sm/decode (json/read-str (slurp smf) :key-fn keyword))})
234+
compiler-env))
235+
(get-in compiler-env [::source-maps ns :source-map]))))))
235236

236237
(defn ns-info
237238
"Given a path to a js source file return the ns info for the corresponding
238239
ClojureScript file if it exists."
239240
[f]
240241
(let [f' (js-src->cljs-src f)]
241-
(when (.exists f')
242+
(when (and f' (.exists f'))
242243
(ana/parse-ns f'))))
243244

244245
(defn- mapped-line-column-call
@@ -334,12 +335,12 @@
334335
print the ClojureScript stacktrace. See mapped-stacktrace."
335336
([stacktrace] (print-mapped-stacktrace stacktrace *repl-opts*))
336337
([stacktrace opts]
337-
(doseq [{:keys [function file line column]}
338-
(mapped-stacktrace stacktrace opts)]
339-
(err-out
340-
(println "\t"
341-
(str (when function (str function " "))
342-
"(" file (when line (str ":" line)) (when column (str ":" column)) ")"))))))
338+
(doseq [{:keys [function file line column]}
339+
(mapped-stacktrace stacktrace opts)]
340+
(err-out
341+
(println "\t"
342+
(str (when function (str function " "))
343+
"(" file (when line (str ":" line)) (when column (str ":" column)) ")"))))))
343344

344345
(comment
345346
(cljsc/build "samples/hello/src"

0 commit comments

Comments
 (0)