Skip to content

Commit 1d38f73

Browse files
anmonteirodnolen
authored andcommitted
CLJS-1968: Enable calling JS modules that export a single function
1 parent 86f26bf commit 1d38f73

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,9 @@
691691
[module]
692692
;; we need to check both keys and values of the JS module index, because
693693
;; macroexpansion will be looking for the provided name - António Monteiro
694-
(-> (into #{} (mapcat identity) (get-in @env/*compiler* [:js-module-index]))
695-
(contains? module)))
694+
(contains?
695+
(into #{} (mapcat identity) (get-in @env/*compiler* [:js-module-index]))
696+
(str module)))
696697

697698
(defn confirm-var-exists
698699
([env prefix suffix]
@@ -711,7 +712,7 @@
711712
(not (loaded-js-ns? env prefix))
712713
(not (and (= 'cljs.core prefix) (= 'unquote suffix)))
713714
(nil? (gets @env/*compiler* ::namespaces prefix :defs suffix))
714-
(not (js-module-exists? (str prefix))))
715+
(not (js-module-exists? prefix)))
715716
(missing-fn env prefix suffix)))))
716717

717718
(defn confirm-var-exists-throw []
@@ -746,7 +747,7 @@
746747
;; macros may refer to namespaces never explicitly required
747748
;; confirm that the library at least exists
748749
#?(:clj (nil? (util/ns->source ns-sym)))
749-
(not (js-module-exists? (str ns-sym))))
750+
(not (js-module-exists? ns-sym)))
750751
(warning :undeclared-ns env {:ns-sym ns-sym})))
751752

752753
(defn core-name?
@@ -921,6 +922,13 @@
921922
(some? (gets @env/*compiler* ::namespaces (-> env :ns :name) :imports sym))
922923
(recur env (gets @env/*compiler* ::namespaces (-> env :ns :name) :imports sym) confirm)
923924

925+
(or (js-module-exists? s)
926+
(js-module-exists? (resolve-ns-alias env s)))
927+
(let [module (or (gets @env/*compiler* :js-module-index s)
928+
(resolve-ns-alias env s))]
929+
{:name (symbol module)
930+
:ns 'js})
931+
924932
:else
925933
(let [cur-ns (-> env :ns :name)
926934
full-ns (cond

0 commit comments

Comments
 (0)