File tree 2 files changed +22
-7
lines changed
main/clojure/cljs/analyzer
2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change 10
10
" This is intended to be a stable api for those who need programmatic access
11
11
to the analyzer."
12
12
(:refer-clojure :exclude [all-ns ns-interns ns-resolve resolve find-ns
13
- ns-publics remove-ns])
13
+ ns-publics remove-ns the-ns ])
14
14
#? (:clj (:require [cljs.analyzer :as ana]
15
15
[cljs.env :as env]
16
16
[cljs.util :as util]
227
227
{:pre [(symbol? sym)]}
228
228
(get-in @state [::ana/namespaces sym])))
229
229
230
+ (defn the-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
+
230
240
(defn ns-interns
231
241
" Given a namespace return all the var analysis maps. Analagous to
232
242
clojure.core/ns-interns but returns var analysis maps not vars."
233
243
([ns ]
234
244
(ns-interns env/*compiler* ns ))
235
245
([state ns ]
236
246
{:pre [(symbol? ns )]}
237
- (merge
238
- (get-in @state [::ana/namespaces ns :macros ])
239
- (get-in @state [::ana/namespaces ns :defs ]))))
247
+ (let [ns (the-ns state ns )]
248
+ (merge
249
+ (:macros ns )
250
+ (:defs ns )))))
240
251
241
252
(defn ns-publics
242
253
" Given a namespace return all the public var analysis maps. Analagous to
245
256
(ns-publics env/*compiler* ns ))
246
257
([state ns ]
247
258
{:pre [(symbol? ns )]}
248
- (->> (merge
249
- (get-in @state [::ana/namespaces ns :macros ])
250
- (get-in @state [::ana/namespaces ns :defs ]))
259
+ (->> (ns-interns state ns )
251
260
(remove (fn [[k v]] (:private v)))
252
261
(into {}))))
253
262
Original file line number Diff line number Diff line change 52
52
(is (= {:a 1 } (ana-api/get-js-index state)))
53
53
(ana-api/with-state state
54
54
(is (= {:a 1 } (ana-api/get-js-index ))))))
55
+
56
+ (deftest throw-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)))))
You can’t perform that action at this time.
0 commit comments