Skip to content

Commit

Permalink
CLJS-2423: Allow custom :output-wrapper function
Browse files Browse the repository at this point in the history
Expands support from 2 types to 4 types:
- function
- string (`format` compatible string interpolation)
- truthy (that is of course, neither function nor string)
- falsey

Previously, any truthy value would cause the javascript to be wrapped by some
default stringified function. For most simple applications, this would have
sufficed. In cases where the `this` context in the wrapper function is used,
something more expressive is needed to be able to assign this context.
The string and function support aims to fill this gap.
  • Loading branch information
livtanong authored and dnolen committed Dec 1, 2017
1 parent 13d3900 commit 1f9bfe1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/clojure/cljs/closure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1869,8 +1869,11 @@

(defn add-wrapper [{:keys [output-wrapper] :as opts} js]
(if output-wrapper
(str ";(function(){\n" js "\n})();\n")
js))
(cond
(fn? output-wrapper) (output-wrapper js)
(string? output-wrapper) (format output-wrapper js)
:else (str ";(function(){\n" js "\n})();\n"))
js))

(defn add-source-map-link [{:keys [source-map output-to] :as opts} js]
(if source-map
Expand Down

0 comments on commit 1f9bfe1

Please sign in to comment.