Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
This ticket asks that analyzer warnings be suppressed when using transitively loaded Closure libs via qualified references.

{code:title=co.edn}
{:libs ["libs/mylib.js"]}


{code:title=libs/mylib.js}
goog.provide('my_lib.core')

my_lib.core = {
  add: function(x, y) { return x + y; }
}


{code:title=src/foo/core.cljs}
(ns foo.core
 (:require my-lib.core
           clojure.set))


Here is an example illustrating the concept:


$ clj -m cljs.main -co co.edn -re node -r
ClojureScript 1.10.339
cljs.user=> (clojure.set/intersection #{1 2 3} #{2 4 5})
WARNING: Use of undeclared Var clojure.set/intersection at line 1 <cljs repl>
...
cljs.user=> (require 'foo.core)
nil
cljs.user=> (clojure.set/intersection #{1 2 3} #{2 4 5})
#{2}
cljs.user=> (clojure.set/intersection)
WARNING: Wrong number of args (0) passed to clojure.set/intersection at line 1 <cljs repl>
cljs.user=> (my-lib.core/add 2 3)
WARNING: No such namespace: my-lib.core, could not locate my_lib/core.cljs, my_lib/core.cljc, or JavaScript source providing "my-lib.core" (Please check that namespaces with dashes use underscores in the ClojureScript file name) at line 1 <cljs repl>
WARNING: Use of undeclared Var my-lib.core/add at line 1 <cljs repl>
5
cljs.user=> (in-ns 'foo.core)
nil
foo.core=> (my-lib.core/add 2 3)
5


In the above, you can see that when a transitively loaded ClojureScript namespace (in this example {{clojure.set}}) is used via qualified symbols, the analyzer works properly.

This characteristic evidently doesn't currently apply to Closure libs, so (correctly functioning) source code would need to be revised in this example simply in order to avoid analyzer warnings (and the source code would need to be aware that a namespace is implemented by a Closure lib instead of a ClojureScript namespace).

The argument for this enhancement is that it leads to consistency and make it possible to cleanly use Closure libs in valid scenarios where transitive dependencies are used. (Normally it is a bad idea to not directly indicate your dependencies in a given namespace, but an arguably copacetic use is when you are using a namespace that exposes macros that expand to use code that the namespace transitively loads. This could occur, for example with macros that want to use libs defined via {{:libs}} or even libs in Closure Library.)

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2860 (reported by mfikes)
...