|
3 | 3 | (:require [cljs.analyzer :as ana]
|
4 | 4 | [cljs.compiler :as comp]
|
5 | 5 | [cljs.env :as env]
|
6 |
| - [cljs.util :as util]) |
| 6 | + [cljs.util :as util] |
| 7 | + [cljs.tagged-literals :as tags]) |
7 | 8 | (:import [java.io File]))
|
8 | 9 |
|
9 | 10 | (def aenv (assoc-in (ana/empty-env) [:ns :name] 'cljs.user))
|
|
87 | 88 | '(defn foo ([a]) ([a b])))))
|
88 | 89 | )
|
89 | 90 |
|
| 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 | + |
90 | 135 | ;; CLJS-1225
|
91 | 136 |
|
92 | 137 | (comment
|
|
0 commit comments