cljs.js
*eval-fn*
Each runtime environment provides various ways to eval JavaScript
source. Whatever function *eval-fn* is bound to will be passed a map
containing the following keys:
:source - the source of the library (string)
:name - used to unique identify the script (symbol)
:cache - if the source was originally ClojureScript, will be given the
analysis cache.
The result of evaluation should be the return value.
*load-fn*
Each runtime environment provides a different way to load a library.
Whatever function *load-fn* is bound to will be passed two arguments - a
map and a callback function: The map will have the following keys:
:name - the name of the library (a symbol)
:macros - modifier signaling a macros namespace load
:path - munged relative library path (a string)
It is up to the implementor to correctly resolve the corresponding .cljs,
.cljc, or .js resource (the order must be respected). If :macros is true
resolution should only consider .clj or .cljc resources (the order must be
respected). Upon resolution the callback should be invoked with a map
containing the following keys:
:lang - the language, :clj or :js
:source - the source of the library (a string)
:file - optional, the file path, it will be added to AST's :file keyword
(but not in :meta)
:cache - optional, if a :clj namespace has been precompiled to :js, can
give an analysis cache for faster loads.
:source-map - optional, if a :clj namespace has been precompiled to :js, can
give a V3 source map JSON
If the resource could not be resolved, the callback should be invoked with
nil.
(analyze-str state source cb)
(analyze-str state source name cb)
(analyze-str state source name opts cb)
Analyze ClojureScript source. The compiler state will be populated with
the results of analyzes. The parameters:
state (atom)
the compiler state
source (string)
the ClojureScript source
name (symbol or string)
optional, the name of the source
opts (map)
compilation options.
:eval - eval function to invoke, see *eval-fn*
:load - library resolution function, see *load-fn*
:source-map - set to true to generate inline source map information
:def-emits-var - sets whether def (and derived) forms return either a Var
(if set to true) or the def init value (if false).
Defaults to false.
:checked-arrays - if :warn or :error, checks inferred types and values passed
to aget/aset. Logs for incorrect values if :warn, throws if
:error. Defaults to false.
:static-fns - employ static dispatch to specific function arities in
emitted JavaScript, as opposed to making use of the
`call` construct. Defaults to false.
:fn-invoke-direct - if `true`, does not generate `.call(null...)` calls for
unknown functions, but instead direct invokes via
`f(a0,a1...)`. Defaults to `false`.
:target - use `:nodejs` if targeting Node.js. Takes no other options
at the moment.
:ns - optional, the namespace in which to evaluate the source.
:verbose - optional, emit details from compiler activity. Defaults to
false.
:context - optional, sets the context for the source. Possible values
are `:expr`, `:statement` and `:return`. Defaults to
`:expr`.
cb (function)
callback, will be invoked with a map. If successful the map will contain
a key :value, the actual value is not meaningful. If unsuccessful the
map will contain a key :error with an ex-info instance describing the cause
of failure.
(compile-str state source cb)
(compile-str state source name cb)
(compile-str state source name opts cb)
Compile ClojureScript source into JavaScript. The parameters:
state (atom)
the compiler state
source (string)
the ClojureScript source
name (symbol or string)
optional, the name of the source
opts (map)
compilation options.
:eval - eval function to invoke, see *eval-fn*
:load - library resolution function, see *load-fn*
:source-map - set to true to generate inline source map information
:def-emits-var - sets whether def (and derived) forms return either a Var
(if set to true) or the def init value (if false). Default
is false.
:checked-arrays - if :warn or :error, checks inferred types and values passed
to aget/aset. Logs for incorrect values if :warn, throws if
:error. Defaults to false.
:static-fns - employ static dispatch to specific function arities in
emitted JavaScript, as opposed to making use of the
`call` construct. Defaults to false.
:fn-invoke-direct - if `true`, does not generate `.call(null...)` calls for
unknown functions, but instead direct invokes via
`f(a0,a1...)`. Defaults to `false`.
:target - use `:nodejs` if targeting Node.js. Takes no other options
at the moment.
:ns - optional, the namespace in which to evaluate the source.
:verbose - optional, emit details from compiler activity. Defaults to
false.
:context - optional, sets the context for the source. Possible values
are `:expr`, `:statement` and `:return`. Defaults to
`:expr`.
cb (function)
callback, will be invoked with a map. If successful the map will contain
a key :value with the compilation result (string). If unsuccessful the map
will contain a key :error with an ex-info instance describing the cause
of failure.
(eval state form cb)
(eval state form opts cb)
Evaluate a single ClojureScript form. The parameters:
state (atom)
the compiler state
form (s-expr)
the ClojureScript source
opts (map)
compilation options.
:eval - eval function to invoke, see *eval-fn*
:load - library resolution function, see *load-fn*
:source-map - set to true to generate inline source map information
:def-emits-var - sets whether def (and derived) forms return either a Var
(if set to true) or the def init value (if false). Default
is false.
:checked-arrays - if :warn or :error, checks inferred types and values passed
to aget/aset. Logs for incorrect values if :warn, throws if
:error. Defaults to false.
:static-fns - employ static dispatch to specific function arities in
emitted JavaScript, as opposed to making use of the
`call` construct. Defaults to false.
:fn-invoke-direct - if `true`, does not generate `.call(null...)` calls for
unknown functions, but instead direct invokes via
`f(a0,a1...)`. Defaults to `false`.
:target - use `:nodejs` if targeting Node.js. Takes no other options
at the moment.
:ns - optional, the namespace in which to evaluate the source.
:verbose - optional, emit details from compiler activity. Defaults to
false.
:context - optional, sets the context for the source. Possible values
are `:expr`, `:statement` and `:return`. Defaults to
`:expr`.
cb (function)
callback, will be invoked with a map. If successful the map will contain
a key :value with the result of evalution. If unsuccessful the map will
contain a key :error with an ex-info instance describing the cause of
failure.
(eval-str state source cb)
(eval-str state source name cb)
(eval-str state source name opts cb)
Evalute ClojureScript source given as a string. The parameters:
state (atom)
the compiler state
source (string)
the ClojureScript source
name (symbol or string)
optional, the name of the source
opts (map)
compilation options.
:eval - eval function to invoke, see *eval-fn*
:load - library resolution function, see *load-fn*
:source-map - set to true to generate inline source map information
:cache-source - optional, a function to run side-effects with the
compilation result prior to actual evalution. This function
takes two arguments, the first is the eval map, the source
will be under :source. The second argument is a callback of
one argument. If an error occurs an :error key should be
supplied.
:def-emits-var - sets whether def (and derived) forms return either a Var
(if set to true) or the def init value (if false). Default
is false.
:checked-arrays - if :warn or :error, checks inferred types and values passed
to aget/aset. Logs for incorrect values if :warn, throws if
:error. Defaults to false.
:static-fns - employ static dispatch to specific function arities in
emitted JavaScript, as opposed to making use of the
`call` construct. Defaults to false.
:fn-invoke-direct - if `true`, does not generate `.call(null...)` calls for
unknown functions, but instead direct invokes via
`f(a0,a1...)`. Defaults to `false`.
:target - use `:nodejs` if targeting Node.js. Takes no other options
at the moment.
:ns - optional, the namespace in which to evaluate the source.
:verbose - optional, emit details from compiler activity. Defaults to
false.
:context - optional, sets the context for the source. Possible values
are `:expr`, `:statement` and `:return`. Defaults to
`:expr`.
cb (function)
callback, will be invoked with a map. If succesful the map will contain
a :value key with the result of evaluation and :ns the current namespace.
If unsuccessful will contain a :error key with an ex-info instance describing
the cause of failure.