Skip to content

Commit 49b9304

Browse files
Deraendnolen
authored andcommitted
CLJS-1367: Expose default-warning-handler and warning-enabled?
As :warning-handlers option overwrites the handlers collection there should be a way to use default-warning-handler with :warning-handlers option. Warning-enabled? function is useful for custom warning-handlers where it might be necessary to check if warning was enabled.
1 parent 9e662c3 commit 49b9304

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
(str "Unsupported JavaScript module type " module-type " for foreign library "
340340
file "."))
341341

342-
(defn ^:private default-warning-handler [warning-type env extra]
342+
(defn default-warning-handler [warning-type env extra]
343343
(when (warning-type *cljs-warnings*)
344344
(when-let [s (error-message warning-type extra)]
345345
#?(:clj (binding [*out* *err*]

src/main/clojure/cljs/analyzer/api.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
`(binding [ana/*cljs-warnings* ~no-warnings]
4141
~@body)))
4242

43+
(defn warning-enabled?
44+
"Test if the given warning-type is enabled."
45+
[warning-type]
46+
(ana/*cljs-warnings* warning-type))
47+
48+
(defn default-warning-handler
49+
"The default warning handler.
50+
51+
Outputs the warning messages to *err*."
52+
[warning-type env extra]
53+
(ana/default-warning-handler warning-type env extra))
54+
4355
(defn get-options
4456
"Return the compiler options from compiler state."
4557
([] (get-options env/*compiler*))

src/test/clojure/cljs/analyzer_api_tests.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
(:require [cljs.analyzer.api :as ana-api])
33
(:use clojure.test))
44

5+
(deftest cljs-warning-test
6+
(is (ana-api/warning-enabled? :undeclared-var)
7+
"Undeclared-var warning is enabled by default")
8+
(is (not (ana-api/no-warn (ana-api/warning-enabled? :undeclared-var)))
9+
"Disabled when all warnings are disabled"))
10+
511
(def warning-form
612
'(do (defn x [a b] (+ a b))
713
(x 1 2 3 4)))

0 commit comments

Comments
 (0)