Skip to content

Commit 03455b4

Browse files
committed
elide "use strict" and 'use strict' by default from all production
builds. Add flag to disable the behavior.
1 parent 3d5553d commit 03455b4

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
:fn-invoke-direct :checked-arrays :closure-module-roots :rewrite-polyfills :use-only-custom-externs
203203
:watch :watch-error-fn :watch-fn :install-deps :process-shim :rename-prefix :rename-prefix-namespace
204204
:closure-variable-map-in :closure-property-map-in :closure-variable-map-out :closure-property-map-out
205-
:stable-names :ignore-js-module-exts :opts-cache :aot-cache})
205+
:stable-names :ignore-js-module-exts :opts-cache :aot-cache :elide-strict})
206206

207207
(def string->charset
208208
{"iso-8859-1" StandardCharsets/ISO_8859_1
@@ -1589,17 +1589,25 @@
15891589
(deps-file {} [{:url (deps/to-url "out/cljs/core.js") :requires ["goog.string"] :provides ["cljs.core"]}])
15901590
)
15911591

1592+
(defn elide-strict [js {:keys [elide-strict] :as opts}]
1593+
(cond-> js
1594+
(not (false? elide-strict))
1595+
(->
1596+
(string/replace "\"use strict\"" " ")
1597+
(string/replace "'use strict'" " "))))
1598+
15921599
(defn output-one-file [{:keys [output-to] :as opts} js]
1593-
(cond
1594-
(nil? output-to) js
1600+
(let [js (elide-strict js opts)]
1601+
(cond
1602+
(nil? output-to) js
15951603

1596-
(or (string? output-to)
1597-
(util/file? output-to))
1598-
(let [f (io/file output-to)]
1599-
(util/mkdirs f)
1600-
(spit f js))
1604+
(or (string? output-to)
1605+
(util/file? output-to))
1606+
(let [f (io/file output-to)]
1607+
(util/mkdirs f)
1608+
(spit f js))
16011609

1602-
:else (println js)))
1610+
:else (println js))))
16031611

16041612
(defn output-deps-file [opts sources]
16051613
(output-one-file opts (deps-file opts sources)))
@@ -1733,7 +1741,7 @@
17331741
out-file (io/file output-to)]
17341742
(util/mkdirs out-file)
17351743
(spit out-file
1736-
(as-> source source
1744+
(as-> (elide-strict source opts) source
17371745
(if (= name :cljs-base)
17381746
(add-header opts source)
17391747
source)

0 commit comments

Comments
 (0)