Skip to content

Commit 25c67f1

Browse files
committed
Merge branch 'master' of github.com:clojure/clojurescript
2 parents a5c5f4b + 3993863 commit 25c67f1

File tree

3 files changed

+63
-16
lines changed

3 files changed

+63
-16
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -788,20 +788,22 @@
788788
(defn compile-sources
789789
"Takes dependency ordered list of IJavaScript compatible maps from parse-ns
790790
and compiles them."
791-
[inputs compiler-stats opts]
792-
(if (:parallel-build opts)
793-
(parallel-compile-sources inputs compiler-stats opts)
794-
(util/measure compiler-stats
795-
"Compile sources"
796-
(binding [comp/*inputs* (zipmap (map :ns inputs) inputs)]
797-
(doall
798-
(for [ns-info inputs]
799-
; TODO: compile-file calls parse-ns unnecessarily to get ns-info
800-
; TODO: we could mark dependent namespaces for recompile here
801-
(-compile (or (:source-file ns-info)
802-
(:source-forms ns-info))
803-
; - ns-info -> ns -> cljs file relpath -> js relpath
804-
(merge opts {:output-file (comp/rename-to-js (util/ns->relpath (:ns ns-info)))}))))))))
791+
([inputs opts]
792+
(compile-sources inputs (:compiler-stats opts) opts))
793+
([inputs compiler-stats opts]
794+
(if (:parallel-build opts)
795+
(parallel-compile-sources inputs compiler-stats opts)
796+
(util/measure compiler-stats
797+
"Compile sources"
798+
(binding [comp/*inputs* (zipmap (map :ns inputs) inputs)]
799+
(doall
800+
(for [ns-info inputs]
801+
; TODO: compile-file calls parse-ns unnecessarily to get ns-info
802+
; TODO: we could mark dependent namespaces for recompile here
803+
(-compile (or (:source-file ns-info)
804+
(:source-forms ns-info))
805+
; - ns-info -> ns -> cljs file relpath -> js relpath
806+
(merge opts {:output-file (comp/rename-to-js (util/ns->relpath (:ns ns-info)))})))))))))
805807

806808
(defn add-goog-base
807809
[inputs]

src/main/clojure/cljs/compiler.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@
930930
(or (= protocol tag)
931931
;; ignore new type hints for now - David
932932
(and (not (set? tag))
933-
(not ('#{any clj clj-or-nil} tag))
933+
(not ('#{any clj clj-or-nil clj-nil number string boolean function object array} tag))
934934
(when-let [ps (:protocols (ana/resolve-existing-var (dissoc env :locals) tag))]
935935
(ps protocol)))))))
936936
opt-not? (and (= (:name info) 'cljs.core/not)

src/test/clojure/cljs/compiler_tests.clj

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
(:require [cljs.analyzer :as ana]
44
[cljs.compiler :as comp]
55
[cljs.env :as env]
6-
[cljs.util :as util])
6+
[cljs.util :as util]
7+
[cljs.tagged-literals :as tags])
78
(:import [java.io File]))
89

910
(def aenv (assoc-in (ana/empty-env) [:ns :name] 'cljs.user))
@@ -87,6 +88,50 @@
8788
'(defn foo ([a]) ([a b])))))
8889
)
8990

91+
(defn capture-warnings* [f]
92+
(let [capture (atom [])
93+
tracker (fn [warning-type env & [extra]]
94+
(when (warning-type ana/*cljs-warnings*)
95+
(let [err (ana/error-message warning-type extra)
96+
msg (ana/message env (str "WARNING: " err))]
97+
(swap! capture conj [warning-type msg]))))]
98+
(ana/with-warning-handlers [tracker]
99+
(f))
100+
@capture))
101+
102+
(defmacro capture-warnings [& body]
103+
`(capture-warnings* (fn [] ~@body)))
104+
105+
(deftest no-warn-on-emit-invoke-protocol-method
106+
(let [define-foo #(assoc-in % [::ana/namespaces 'cljs.user :defs 'foo]
107+
{:ns 'cljs.user
108+
:name 'cljs.user/foo
109+
:fn-var true
110+
:method-params '([x])
111+
:protocol 'cljs.user/Foo})
112+
aenv-with-foo (define-foo aenv)
113+
cenv-with-foo (define-foo @cenv)]
114+
(binding [ana/*cljs-static-fns* true]
115+
(are [form]
116+
(empty?
117+
(capture-warnings
118+
(env/with-compiler-env (atom cenv-with-foo)
119+
(with-out-str
120+
(comp/emit
121+
(ana/analyze aenv-with-foo form))))))
122+
123+
'(cljs.user/foo nil)
124+
'(cljs.user/foo 0)
125+
'(cljs.user/foo (inc 0))
126+
'(cljs.user/foo "")
127+
'(cljs.user/foo true)
128+
'(cljs.user/foo false)
129+
'(cljs.user/foo (nil? nil))
130+
'(cljs.user/foo (fn [x] x))
131+
`(cljs.user/foo ~(tags/->JSValue {}))
132+
`(cljs.user/foo ~(tags/->JSValue []))
133+
'(cljs.user/foo (make-array 0))))))
134+
90135
;; CLJS-1225
91136

92137
(comment

0 commit comments

Comments
 (0)