Skip to content

Commit 9e680c4

Browse files
committed
CLJS-1148: ClojureScript REPL must maintain eval/print pairing
direct all printing which is not the result of eval to *err*. default :bind-err to true which simply maps *err* to *out* to preserve old behavior for command line REPLs.
1 parent 46cf900 commit 9e680c4

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

src/clj/cljs/repl.clj

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
(def ^:dynamic *cljs-verbose* false)
3535
(def ^:dynamic *repl-opts* nil)
3636

37+
(defmacro err-out [& body]
38+
`(binding [*out* *err*]
39+
~@body))
40+
3741
;; =============================================================================
3842
;; Copied over from clojure.main
3943

@@ -355,26 +359,27 @@
355359
([repl-env ret form opts]
356360
(display-error repl-env ret form (constantly nil) opts))
357361
([repl-env ret form f {:keys [print flush] :as opts}]
358-
(f)
359-
(when-let [value (:value ret)]
360-
(print value))
361-
(when-let [st (:stacktrace ret)]
362-
(if (and (true? (:source-map opts))
363-
(satisfies? IParseStacktrace repl-env))
364-
(let [cst (try
365-
(-parse-stacktrace repl-env st ret opts)
366-
(catch Throwable e
367-
(when (:repl-verbose opts)
368-
(print "Failed to canonicalize stacktrace")
369-
(print (Throwables/getStackTraceAsString e))
370-
(flush))))]
371-
(if (vector? cst)
372-
(if (satisfies? IPrintStacktrace repl-env)
373-
(-print-stacktrace repl-env cst ret opts)
374-
(print-mapped-stacktrace cst opts))
375-
(print st)))
376-
(print st))
377-
(flush))))
362+
(err-out
363+
(f)
364+
(when-let [value (:value ret)]
365+
(print value))
366+
(when-let [st (:stacktrace ret)]
367+
(if (and (true? (:source-map opts))
368+
(satisfies? IParseStacktrace repl-env))
369+
(let [cst (try
370+
(-parse-stacktrace repl-env st ret opts)
371+
(catch Throwable e
372+
(when (:repl-verbose opts)
373+
(print "Failed to canonicalize stacktrace")
374+
(print (Throwables/getStackTraceAsString e))
375+
(flush))))]
376+
(if (vector? cst)
377+
(if (satisfies? IPrintStacktrace repl-env)
378+
(-print-stacktrace repl-env cst ret opts)
379+
(print-mapped-stacktrace cst opts))
380+
(print st)))
381+
(print st))
382+
(flush)))))
378383

379384
(defn evaluate-form
380385
"Evaluate a ClojureScript form in the JavaScript environment. Returns a
@@ -425,7 +430,7 @@
425430
(distinct (vals (:uses ast))))
426431
opts))
427432
(when *cljs-verbose*
428-
((:print opts) js))
433+
(err-out ((:print opts) js)))
429434
(let [ret (-evaluate repl-env filename (:line (meta form)) wrap-js)]
430435
(case (:status ret)
431436
:error (throw
@@ -649,7 +654,7 @@
649654
(defn repl*
650655
[repl-env {:keys [init need-prompt quit-prompt prompt flush read eval print caught reader
651656
print-no-newline source-map-inline wrap repl-requires
652-
compiler-env]
657+
compiler-env bind-err]
653658
:or {need-prompt #(if (readers/indexing-reader? *in*)
654659
(== (readers/get-column-number *in*) 1)
655660
(identity true))
@@ -665,7 +670,8 @@
665670
1 "NO_SOURCE_FILE")
666671
print-no-newline print
667672
source-map-inline true
668-
repl-requires '[[cljs.repl :refer-macros [source doc find-doc apropos dir pst]]]}
673+
repl-requires '[[cljs.repl :refer-macros [source doc find-doc apropos dir pst]]]
674+
bind-err true}
669675
:as opts}]
670676
(let [repl-opts (-repl-options repl-env)
671677
repl-requires (into repl-requires (:repl-requires repl-opts))
@@ -687,7 +693,8 @@
687693
:print-no-newline print-no-newline
688694
:source-map-inline source-map-inline})))]
689695
(env/with-compiler-env (or compiler-env (env/default-compiler-env opts))
690-
(binding [ana/*cljs-ns* 'cljs.user
696+
(binding [*err* (if bind-err *out* *err*)
697+
ana/*cljs-ns* 'cljs.user
691698
*cljs-verbose* repl-verbose
692699
ana/*cljs-warnings*
693700
(assoc ana/*cljs-warnings*
@@ -750,7 +757,7 @@
750757
(when-let [src (:watch opts)]
751758
(future
752759
(let [log-file (io/file (util/output-directory opts) "watch.log")]
753-
(print "Watch compilation log available at:" (str log-file))
760+
(err-out (print "Watch compilation log available at:" (str log-file)))
754761
(flush)
755762
(try
756763
(let [log-out (FileWriter. log-file)]

0 commit comments

Comments
 (0)