Skip to content

Commit cfcc13d

Browse files
committed
cljs.externs/ns-match? was ignoring ctors that are exactly the namespace, add
test case
1 parent 09e513c commit cfcc13d

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/main/clojure/cljs/externs.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,12 @@
205205
defaults sources))))
206206

207207
(defn ns-match? [ns-segs var-segs]
208-
(and
209-
(= (inc (count ns-segs)) (count var-segs))
210-
(= ns-segs (take (count ns-segs) var-segs))))
208+
(or
209+
;; exact match (i.e. ctors)
210+
(= ns-segs var-segs)
211+
(and
212+
(= (inc (count ns-segs)) (count var-segs))
213+
(= ns-segs (take (count ns-segs) var-segs)))))
211214

212215
(defn parsed->defs [externs]
213216
(let [ns-segs (into [] (map symbol (string/split (str *goog-ns*) #"\.")))]
@@ -325,4 +328,4 @@
325328
parse-externs index-externs
326329
(get 'React)
327330
(find 'Component) first meta)
328-
)
331+
)

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,3 +1456,22 @@
14561456
'[(ns test.foo
14571457
(:import [goog.history Html5History]))]))
14581458
(is (some? (get-in @cenv [::ana/namespaces 'goog.history.Html5History :defs])))))
1459+
1460+
(deftest test-analyze-goog-ns-ctor
1461+
(let [cenv (env/default-compiler-env)]
1462+
(env/with-compiler-env cenv
1463+
(ana/analyze-form-seq
1464+
'[(ns test.foo
1465+
(:import [goog.history Html5History]))]))
1466+
(is (some? (get-in @cenv [::ana/namespaces 'goog.history.Html5History :defs 'Html5History])))))
1467+
1468+
(comment
1469+
1470+
(let [cenv (env/default-compiler-env)]
1471+
(env/with-compiler-env cenv
1472+
(ana/analyze-form-seq
1473+
'[(ns test.foo
1474+
(:import [goog.history Html5History]))]))
1475+
(get-in @cenv [::ana/namespaces 'goog.history.Html5History :defs]))
1476+
1477+
)

0 commit comments

Comments
 (0)