Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1fc819

Browse files
borkdudeswannodette
authored andcommitted
CLJS-3421: Throw when calling ana-api/ns-publics on non-existing ns
1 parentb7ede4b commitf1fc819

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

‎src/main/clojure/cljs/analyzer/api.cljc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"This is intended to be a stable api for those who need programmatic access
1111
to the analyzer."
1212
(:refer-clojure:exclude [all-ns ns-interns ns-resolve resolve find-ns
13-
ns-publics remove-ns])
13+
ns-publics remove-ns the-ns])
1414
#?(:clj (:require [cljs.analyzer:as ana]
1515
[cljs.env:as env]
1616
[cljs.util:as util]
@@ -227,16 +227,27 @@
227227
{:pre [(symbol? sym)]}
228228
(get-in @state [::ana/namespaces sym])))
229229

230+
(defnthe-ns
231+
"Given a namespace return the corresponding namespace analysis map, throwing an
232+
exception if not found. Analagous to clojure.core/the-ns."
233+
([ns]
234+
(the-ns env/*compiler*ns))
235+
([state sym]
236+
{:pre [(symbol? sym)]}
237+
(or (find-ns state sym)
238+
(throw (ex-info (str"No namespace found:" sym) {:ns sym})))))
239+
230240
(defnns-interns
231241
"Given a namespace return all the var analysis maps. Analagous to
232242
clojure.core/ns-interns but returns var analysis maps not vars."
233243
([ns]
234244
(ns-interns env/*compiler*ns))
235245
([statens]
236246
{:pre [(symbol?ns)]}
237-
(merge
238-
(get-in @state [::ana/namespacesns:macros])
239-
(get-in @state [::ana/namespacesns:defs]))))
247+
(let [ns (the-ns statens)]
248+
(merge
249+
(:macrosns)
250+
(:defsns)))))
240251

241252
(defnns-publics
242253
"Given a namespace return all the public var analysis maps. Analagous to
@@ -245,9 +256,7 @@
245256
(ns-publics env/*compiler*ns))
246257
([statens]
247258
{:pre [(symbol?ns)]}
248-
(->> (merge
249-
(get-in @state [::ana/namespacesns:macros])
250-
(get-in @state [::ana/namespacesns:defs]))
259+
(->> (ns-interns statens)
251260
(remove (fn [[k v]] (:private v)))
252261
(into {}))))
253262

‎src/test/clojure/cljs/analyzer_api_tests.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@
5252
(is (= {:a1} (ana-api/get-js-index state)))
5353
(ana-api/with-state state
5454
(is (= {:a1} (ana-api/get-js-index))))))
55+
56+
(deftestthrow-test
57+
(let [state (atom {})]
58+
(is (thrown? Exception (ana-api/the-ns state 'non.existing)))
59+
(is (thrown? Exception (ana-api/ns-interns state 'non.existing)))
60+
(is (thrown? Exception (ana-api/ns-publics state 'non.existing)))))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp