Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goog.debug #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ programmer to trace any form they wish rather than just the special forms.
#### Conditional tracing

If you want to remove tracing on production builds,
`clairvoyant.core/trace-forms` will not add tracing when the `:elide-asserts`
option (under `:compiler` options in your `project.clj` file) is set to true.
Therefore if you set this option in your prod builds you do not need to remove
`clairvoyant.core/trace-forms` from your source. This technique was taken from
the [reagent project](https://github.com/reagent-project/reagent)
`clairvoyant.core/trace-forms` will not add tracing when `js/goog.DEBUG`
is set to false this requires `:closure-defines {:goog.DEBUG false}`
option (under `:compiler` options in your `project.clj` file).
Therefore if you set this option in your prod builds you do not need to
remove `clairvoyant.core/trace-forms` from your source.

WARNING: to set this option you do need to have `:optimizations :simple`
or `optimizations :advanced` or else the value will not be set because
the closure compiler does not do the substitution.

## Trace data

Expand Down
18 changes: 11 additions & 7 deletions src/clairvoyant/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@
(trace-form x env))))
form))

(defmacro dev?
"True if assertions are enabled."
[]
(if *assert* true false))
; (defmacro dev?
; "True if assertions are enabled."
; []
; (if *assert* true false))

(def dev?
"True if assertions are enabled."
(vary-meta 'js/goog.DEBUG assoc :tag 'boolean))

(defmacro trace-forms
"Recursively trace one or more forms."
{:arglists '([& forms] [{:keys [tracer]} & forms])}
[& forms]
(if (dev?)
(let [opts (when (and (map? (first forms))
(contains? (first forms) :tracer))
(first forms))
Expand All @@ -96,8 +99,9 @@
(binding [*tracer* tracer]
(let [traced-forms (doall (for [form forms]
(trace-form form &env)))]
`(do ~@traced-forms))))
`(do ~@forms)))
`(if ~dev?
(do ~@traced-forms)
(do ~@forms))))))


;; ---------------------------------------------------------------------
Expand Down