Skip to content

Commit 914fcb7

Browse files
condition: fix circular import (cljs)
1 parent e3c77ae commit 914fcb7

File tree

2 files changed

+39
-45
lines changed

2 files changed

+39
-45
lines changed

src/active/clojure/condition.cljc

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
[clojure.string :as string]
2222
[clojure.core :as core]
2323
[active.clojure.macro :refer [if-cljs]])
24-
:cljs (:require [active.clojure.condition :refer-macros [define-condition-type throw-condition]]
25-
[cljs.core :as core]))
24+
:cljs (:require-macros [active.clojure.condition :refer [define-condition-type throw-condition]]
25+
[cljs.core :as core]))
2626
#?(:clj (:import clojure.lang.ExceptionInfo)))
2727

2828
(defn condition?
@@ -227,7 +227,6 @@
227227
(nth (:arguments comp) i)
228228
(throw (new Error (str cond " is not a condition of type " type)))))))
229229

230-
#?(:clj
231230
(defmacro define-condition-type
232231
" (define-condition-type <condition-type>
233232
<supertype>
@@ -278,9 +277,9 @@
278277
m
279278
(assoc m :arglists `'(~arglist)))))))
280279
name-doc (fn [field]
281-
(if-let [doc (:doc (meta field))]
282-
(str " (" doc ")")
283-
""))
280+
(if-let [doc (:doc (meta field))]
281+
(str " (" doc ")")
282+
""))
284283
reference (fn [name]
285284
(str "[[" (ns-name *ns*) "/" name "]]"))]
286285
`(do
@@ -311,7 +310,7 @@
311310
(str "Access the `" ?field-name "`" (name-doc ?field-name)
312311
" field from a " (reference ?condition-type) " condition."))
313312
(condition-accessor ~?condition-type '~?field-name)))
314-
?field-pairs))))))
313+
?field-pairs)))))
315314

316315
; These standard condition types correspond directly to R6RS Scheme
317316

@@ -374,13 +373,12 @@
374373
(and (not-empty irritants) (make-irritants-condition irritants))
375374
conditions)))
376375

377-
#?(:clj
378376
(defmacro throw-condition
379377
"Throw a condition.
380378
381379
For internal use."
382380
[?base ?who ?message ?irritants]
383-
`(throw (build-condition ~?base ~?who ~?message ~?irritants))))
381+
`(throw (build-condition ~?base ~?who ~?message ~?irritants)))
384382

385383
(defn error
386384
"Throw an exception that signals that an error has occurred.
@@ -410,57 +408,53 @@
410408
[who message & irritants]
411409
(throw-condition (make-assertion-violation) who message irritants))
412410

413-
#?(:clj
414411
(defmacro assert
415412
"Evaluates expr and throws an exception if it does not evaluate to
416413
logical true."
417414
([x]
418-
(when *assert*
419-
(let [?ns (str *ns*)
420-
?file (let [f *file*] (when (not= f "NO_SOURCE_PATH") f))
421-
;; TODO Waiting on http://dev.clojure.org/jira/browse/CLJ-865:
422-
?line (:line (meta &form))]
423-
`(when-not ~x
424-
(assertion-violation (if-cljs
415+
(when *assert*
416+
(let [?ns (str *ns*)
417+
?file (let [f *file*] (when (not= f "NO_SOURCE_PATH") f))
418+
;; TODO Waiting on http://dev.clojure.org/jira/browse/CLJ-865:
419+
?line (:line (meta &form))]
420+
`(when-not ~x
421+
(assertion-violation (if-cljs
425422
nil
426423
(stack-trace-who (.getStackTrace (Thread/currentThread))))
427-
(str "Assertion failed")
428-
(make-location-condition '~?ns ~?file ~?line)
429-
'~x)))))
424+
(str "Assertion failed")
425+
(make-location-condition '~?ns ~?file ~?line)
426+
'~x)))))
430427
([x message]
431-
(when *assert*
432-
(let [?ns (str *ns*)
433-
?file (let [f *file*] (when (not= f "NO_SOURCE_PATH") f))
434-
;; TODO Waiting on http://dev.clojure.org/jira/browse/CLJ-865:
435-
?line (:line (meta &form))]
436-
`(when-not ~x
437-
(assertion-violation (if-cljs
438-
nil
439-
(stack-trace-who (.getStackTrace (Thread/currentThread))))
440-
(str "Assert failed: " ~message)
441-
(make-location-condition '~?ns ~?file ~?line)
442-
'~x)))))))
428+
(when *assert*
429+
(let [?ns (str *ns*)
430+
?file (let [f *file*] (when (not= f "NO_SOURCE_PATH") f))
431+
;; TODO Waiting on http://dev.clojure.org/jira/browse/CLJ-865:
432+
?line (:line (meta &form))]
433+
`(when-not ~x
434+
(assertion-violation (if-cljs
435+
nil
436+
(stack-trace-who (.getStackTrace (Thread/currentThread))))
437+
(str "Assert failed: " ~message)
438+
(make-location-condition '~?ns ~?file ~?line)
439+
'~x))))))
443440

444441

445-
#?(:clj
446442
(defmacro condition
447443
[?base ?message & ?irritants]
448444
`(combine-conditions ~?base
449445
(if-cljs
450-
nil
451-
(make-who-condition (stack-trace-who (.getStackTrace (Thread/currentThread)))))
446+
nil
447+
(make-who-condition (stack-trace-who (.getStackTrace (Thread/currentThread)))))
452448
(make-message-condition ~?message)
453-
(make-irritants-condition [~@?irritants]))))
449+
(make-irritants-condition [~@?irritants])))
454450

455-
#?(:clj
456451
(defmacro raise
457452
[?base ?message & ?irritants]
458-
`(throw (condition ~?base ~?message ~@?irritants))))
453+
`(throw (condition ~?base ~?message ~@?irritants)))
459454

460455
#?(:cljs
461456
(def Throwable js/Object))
462457

463-
#?(:clj
464458
(defmacro guard
465459
"Guard against specific conditions (with an optional default case), similar
466460
to `catch`.
@@ -481,13 +475,13 @@
481475
(let [?id (first ?handling)]
482476
`(try
483477
~@?body
484-
; If Throwable is not a symbol it means java.lang.Throwable which does not work in ClojureScript.
478+
; If Throwable is not a symbol it means java.lang.Throwable which does not work in ClojureScript.
485479
(catch ~'Throwable ~?id
486480
(cond
487-
~@(rest ?handling)
488-
~@(if (= :else (last (butlast ?handling)))
489-
`()
490-
`(:else (throw ~?id)))))))))
481+
~@(rest ?handling)
482+
~@(if (= :else (last (butlast ?handling)))
483+
`()
484+
`(:else (throw ~?id))))))))
491485

492486
(defn delete-first
493487
[pred? l]

test/active/clojure/condition_test.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#?(:clj (:require [clojure.test :refer [deftest is testing]]
33
[active.clojure.condition :as c])
44
:cljs (:require [cljs.test :refer-macros [is deftest testing]]
5-
[active.clojure.condition :as c :include-macros true])))
5+
[active.clojure.condition :as c :include-macros true :refer [Throwable]])))
66

77
#?(:cljs
88
(enable-console-print!))

0 commit comments

Comments
 (0)