Skip to content

Commit

Permalink
CLJS-1968: Enable calling JS modules that export a single function
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored and dnolen committed Mar 10, 2017
1 parent 86f26bf commit 1d38f73
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,9 @@
[module]
;; we need to check both keys and values of the JS module index, because
;; macroexpansion will be looking for the provided name - António Monteiro
(-> (into #{} (mapcat identity) (get-in @env/*compiler* [:js-module-index]))
(contains? module)))
(contains?
(into #{} (mapcat identity) (get-in @env/*compiler* [:js-module-index]))
(str module)))

(defn confirm-var-exists
([env prefix suffix]
Expand All @@ -711,7 +712,7 @@
(not (loaded-js-ns? env prefix))
(not (and (= 'cljs.core prefix) (= 'unquote suffix)))
(nil? (gets @env/*compiler* ::namespaces prefix :defs suffix))
(not (js-module-exists? (str prefix))))
(not (js-module-exists? prefix)))
(missing-fn env prefix suffix)))))

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

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

(or (js-module-exists? s)
(js-module-exists? (resolve-ns-alias env s)))
(let [module (or (gets @env/*compiler* :js-module-index s)
(resolve-ns-alias env s))]
{:name (symbol module)
:ns 'js})

:else
(let [cur-ns (-> env :ns :name)
full-ns (cond
Expand Down

0 comments on commit 1d38f73

Please sign in to comment.