Skip to content

Commit 10fdfa2

Browse files
authored
CLJS-3481: support :error, :warning, :off modes with :warnings (#318)
- matches `:closure-warnings` - simpler path to fail builds w/o custom error handler
1 parent 0fee1c0 commit 10fdfa2

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

src/main/clojure/cljs/analyzer.cljc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,17 @@
484484
"ambiguous expression " form)))
485485

486486
(defn default-warning-handler [warning-type env extra]
487-
(when (warning-type *cljs-warnings*)
488-
(when-let [s (error-message warning-type extra)]
489-
#?(:clj (binding [*out* *err*]
490-
(println (message env (str "WARNING: " s))))
491-
:cljs (binding [*print-fn* *print-err-fn*]
492-
(println (message env (str "WARNING: " s))))))))
487+
(let [warn-mode (warning-type *cljs-warnings*)]
488+
(when-not (#{false :off} warn-mode)
489+
(when-let [s (error-message warning-type extra)]
490+
(cond
491+
(#{true :warning} warn-mode)
492+
#?(:clj (binding [*out* *err*]
493+
(println (message env (str "WARNING: " s))))
494+
:cljs (binding [*print-fn* *print-err-fn*]
495+
(println (message env (str "WARNING: " s)))))
496+
(= :error warn-mode)
497+
(throw (ex-info s {})))))))
493498

494499
(def ^:dynamic *cljs-warning-handlers*
495500
[default-warning-handler])

src/main/clojure/cljs/closure.clj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,15 +3049,18 @@
30493049
ana/*load-tests* (not= (:load-tests opts) false)
30503050
ana/*cljs-warnings*
30513051
(let [warnings (opts :warnings true)]
3052-
(merge
3053-
ana/*cljs-warnings*
3054-
(if (or (true? warnings)
3055-
(false? warnings))
3052+
(cond
3053+
(map? warnings)
3054+
(merge ana/*cljs-warnings* warnings)
3055+
3056+
;; backwards compatible
3057+
(or (boolean? warnings)
3058+
(keyword? warnings))
3059+
(merge ana/*cljs-warnings*
30563060
(zipmap
30573061
[:unprovided :undeclared-var
30583062
:undeclared-ns :undeclared-ns-form]
3059-
(repeat warnings))
3060-
warnings)))
3063+
(repeat warnings)))))
30613064
ana/*verbose* (:verbose opts)]
30623065
(when (and ana/*verbose* (not (::watch-triggered-build? opts)))
30633066
(util/debug-prn "Options passed to ClojureScript compiler:" (pr-str opts)))

0 commit comments

Comments
 (0)