|
34 | 34 | (def ^:dynamic *cljs-verbose* false)
|
35 | 35 | (def ^:dynamic *repl-opts* nil)
|
36 | 36 |
|
| 37 | +(defmacro err-out [& body] |
| 38 | + `(binding [*out* *err*] |
| 39 | + ~@body)) |
| 40 | + |
37 | 41 | ;; =============================================================================
|
38 | 42 | ;; Copied over from clojure.main
|
39 | 43 |
|
|
355 | 359 | ([repl-env ret form opts]
|
356 | 360 | (display-error repl-env ret form (constantly nil) opts))
|
357 | 361 | ([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))))) |
378 | 383 |
|
379 | 384 | (defn evaluate-form
|
380 | 385 | "Evaluate a ClojureScript form in the JavaScript environment. Returns a
|
|
425 | 430 | (distinct (vals (:uses ast))))
|
426 | 431 | opts))
|
427 | 432 | (when *cljs-verbose*
|
428 |
| - ((:print opts) js)) |
| 433 | + (err-out ((:print opts) js))) |
429 | 434 | (let [ret (-evaluate repl-env filename (:line (meta form)) wrap-js)]
|
430 | 435 | (case (:status ret)
|
431 | 436 | :error (throw
|
|
649 | 654 | (defn repl*
|
650 | 655 | [repl-env {:keys [init need-prompt quit-prompt prompt flush read eval print caught reader
|
651 | 656 | print-no-newline source-map-inline wrap repl-requires
|
652 |
| - compiler-env] |
| 657 | + compiler-env bind-err] |
653 | 658 | :or {need-prompt #(if (readers/indexing-reader? *in*)
|
654 | 659 | (== (readers/get-column-number *in*) 1)
|
655 | 660 | (identity true))
|
|
665 | 670 | 1 "NO_SOURCE_FILE")
|
666 | 671 | print-no-newline print
|
667 | 672 | 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} |
669 | 675 | :as opts}]
|
670 | 676 | (let [repl-opts (-repl-options repl-env)
|
671 | 677 | repl-requires (into repl-requires (:repl-requires repl-opts))
|
|
687 | 693 | :print-no-newline print-no-newline
|
688 | 694 | :source-map-inline source-map-inline})))]
|
689 | 695 | (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 |
691 | 698 | *cljs-verbose* repl-verbose
|
692 | 699 | ana/*cljs-warnings*
|
693 | 700 | (assoc ana/*cljs-warnings*
|
|
750 | 757 | (when-let [src (:watch opts)]
|
751 | 758 | (future
|
752 | 759 | (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))) |
754 | 761 | (flush)
|
755 | 762 | (try
|
756 | 763 | (let [log-out (FileWriter. log-file)]
|
|
0 commit comments