File tree Expand file tree Collapse file tree 3 files changed +20
-11
lines changed Expand file tree Collapse file tree 3 files changed +20
-11
lines changed Original file line number Diff line number Diff line change 30453045 cnt (count xs)]
30463046 (cond
30473047 (> cnt 1 )
3048- (throw (error env ( str " Only one :refer-global form is allowed per namespace definition " ( count xs)) ))
3048+ (throw (error env " Only one :refer-global form is allowed per namespace definition" ))
30493049
30503050 (== cnt 1 )
3051- (let [[_ refers & {:keys [rename] :as renames-only}] (first xs)
3052- err-str " Only [:refer-global (names)] and optionally `:rename {from to}` specs supported" ]
3053- (when-not (and (vector? refers) (every? symbol refers))
3051+ (let [[_ & {:keys [only rename] :as parsed-spec}] (first xs)
3052+ err-str " Only (:refer-global :only [names]) and optionally `:rename {from to}` specs supported" ]
3053+ (when-not (or (empty? only)
3054+ (and (vector? only)
3055+ (every? symbol only)))
30543056 (throw (error env err-str)))
3055- (when-not (or (empty? renames-only)
3056- (and (= 1 (count renames-only))
3057- (contains? renames-only :rename )
3058- (map? rename)
3057+ (when-not (or (empty? rename)
3058+ (and (map? rename)
30593059 (every? symbol (mapcat identity rename))))
3060- (throw (error env (str err-str (pr-str renames-only)))))
3061- {:use (zipmap refers (repeat 'js))
3060+ (throw (error env (str err-str (pr-str parsed-spec)))))
3061+ (when-not (every? #{:only :rename } (keys parsed-spec))
3062+ (throw (error env (str err-str (pr-str parsed-spec)))))
3063+ {:use (zipmap only (repeat 'js))
30623064 :rename (into {}
30633065 (map (fn [[orig new-name]]
30643066 [new-name (symbol " js" (str orig))]))
Original file line number Diff line number Diff line change 31163116 [& args]
31173117 `(~'ns* ~(cons :refer-clojure args)))
31183118
3119+ (core/defmacro refer-global
3120+ " Refer global js vars. Supports renaming via :rename.
3121+
3122+ (refer-global :only '[Date Symbol] :rename '{Symbol Sym})"
3123+ [& args]
3124+ `(~'ns* ~(cons :refer-global args)))
3125+
31193126; ; INTERNAL - do not use, only for Node.js
31203127(core/defmacro load-file* [f]
31213128 `(goog/nodeGlobalRequire ~f))
Original file line number Diff line number Diff line change 389389
390390(deftest test-parse-global-refer
391391 (let [parsed (ana/parse-global-refer-spec {}
392- '((:refer-global [Date] :rename {Symbol JSSymbol})))]
392+ '((:refer-global :only [Date] :rename {Symbol JSSymbol})))]
393393 (is (= parsed
394394 '{:use {Date js}
395395 :rename {JSSymbol js/Symbol}}))))
You can’t perform that action at this time.
0 commit comments