From e380903ba9af1ce9dd25691cccc1fb62c1a38d5b Mon Sep 17 00:00:00 2001 From: Dieter Komendera Date: Fri, 22 Dec 2017 21:24:29 +0100 Subject: [PATCH] Support targeting webworker --- src/main/cljs/cljs/core.cljs | 2 +- src/main/clojure/cljs/closure.clj | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/cljs/cljs/core.cljs b/src/main/cljs/cljs/core.cljs index ac0c180ca9..0188001baf 100644 --- a/src/main/cljs/cljs/core.cljs +++ b/src/main/cljs/cljs/core.cljs @@ -11342,7 +11342,7 @@ reduces them without incurring seq initialization" nil)) (next segs)) (find-ns-obj* goog/global segs)) - "default" (find-ns-obj* goog/global segs) + ("default" "webworker") (find-ns-obj* goog/global segs) (throw (js/Error. (str "find-ns-obj not supported for target " *target*)))))) (defn ns-interns* diff --git a/src/main/clojure/cljs/closure.clj b/src/main/clojure/cljs/closure.clj index f131114875..86eea41c66 100644 --- a/src/main/clojure/cljs/closure.clj +++ b/src/main/clojure/cljs/closure.clj @@ -1552,7 +1552,29 @@ entries [(:main opts)]))) "goog.require(\"cljs.nodejscli\");\n"))) + + :webworker (output-one-file + (merge opts + (when module + {:output-to (:output-to module)})) + (str (when (or (not module) (= :cljs-base (:module-name opts))) + (str "var CLOSURE_BASE_PATH = \"" asset-path "/goog/\";\n" + "var CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n" + "var CLOSURE_IMPORT_SCRIPT = (function(global) { return function(src) {global['importScripts'](src); return true;};})(this);\n" + "if(typeof goog == 'undefined') importScripts(\"" asset-path "/goog/base.js\");\n" + "importScripts(\"" asset-path "/cljs_deps.js\");\n" + (apply str (preloads (:preloads opts))))) + (apply str + (map (fn [entry] + (when-not (= "goog" entry) + (str "goog.require(\"" (comp/munge entry) "\");\n"))) + (if-let [entries (when module (:entries module))] + entries + (when-let [main (:main opts)] + [main])))))) + + (output-one-file (merge opts (when module {:output-to (:output-to module)}))