File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed
main/clojure/cljs/analyzer Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change 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]
227227 {:pre [(symbol? sym)]}
228228 (get-in @state [::ana/namespaces sym])))
229229
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+
230240(defn ns-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 ([state ns ]
236246 {: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 )))))
240251
241252(defn ns-publics
242253 " Given a namespace return all the public var analysis maps. Analagous to
245256 (ns-publics env/*compiler* ns ))
246257 ([state ns ]
247258 {: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 )
251260 (remove (fn [[k v]] (:private v)))
252261 (into {}))))
253262
Original file line number Diff line number Diff line change 5252 (is (= {:a 1 } (ana-api/get-js-index state)))
5353 (ana-api/with-state state
5454 (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