Skip to content

Commit 240a9a5

Browse files
authored
CLJS-3381: Invokable JS namespaces used as constructors not hinted properly (#207)
* tag invokeable :node / :global nses as 'js * add node-module-index to infer-test-helper * add test case
1 parent a1fa32b commit 240a9a5

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,11 +1220,13 @@
12201220
:node {:name (symbol (str current-ns)
12211221
(munge-node-lib (resolve-ns-alias env ns)))
12221222
:op :js-var
1223-
:ns current-ns}
1223+
:ns current-ns
1224+
:tag 'js}
12241225
:global {:name (symbol (str current-ns)
12251226
(munge-global-export (resolve-ns-alias env ns)))
12261227
:op :js-var
1227-
:ns current-ns})))
1228+
:ns current-ns
1229+
:tag 'js})))
12281230

12291231
(defn resolve-import
12301232
"goog.modules are deterministically assigned to a property of the namespace,

src/test/clojure/cljs/externs_infer_tests.clj

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
(is (= 'js/Foo (ana/js-tag '[baz] :ret-tag externs)))))
5252

5353
(defn infer-test-helper
54-
[{:keys [forms externs warnings warn js-dependency-index with-core? opts]}]
54+
[{:keys [forms externs warnings warn js-dependency-index node-module-index with-core? opts]}]
5555
(let [test-cenv (atom
5656
(cond->
5757
(if with-core?
@@ -60,7 +60,8 @@
6060
{::ana/externs
6161
(externs/externs-map
6262
(closure/load-externs {:externs (or externs [])}))})
63-
js-dependency-index (assoc :js-dependency-index js-dependency-index)))
63+
js-dependency-index (assoc :js-dependency-index js-dependency-index)
64+
node-module-index (assoc :node-module-index node-module-index)))
6465
wrap (if with-core?
6566
#(comp/with-core-cljs nil %)
6667
#(do (%)))]
@@ -453,6 +454,27 @@
453454
"Object.someProperty;"])
454455
res)))))
455456

457+
(deftest test-cljs-3381
458+
(testing "invokeable js namespaces not hinted properly"
459+
(let [ws (atom [])
460+
res (infer-test-helper
461+
{:node-module-index #{"markdown-it"}
462+
:forms '[(ns foo.core
463+
(:require [markdown-it]))
464+
(defonce mdi
465+
(doto (new markdown-it
466+
(js-obj
467+
"linkify" true
468+
"typographer" true))
469+
(.renderInline mdi "hi")))]
470+
:warnings ws
471+
:warn true
472+
:with-core? false
473+
:target :nodejs})]
474+
(is (= (unsplit-lines
475+
["Object.renderInline;"])
476+
res)))))
477+
456478
(comment
457479
(binding [ana/*cljs-ns* ana/*cljs-ns*]
458480
(ana/no-warn

0 commit comments

Comments
 (0)