aboutsummaryrefslogtreecommitdiff
path: root/luxc/src
diff options
context:
space:
mode:
authorEduardo Julian2017-02-20 19:51:46 -0400
committerEduardo Julian2017-02-20 19:51:46 -0400
commitdb5dcef3d2a5d3d786617a379a106bd66de3082f (patch)
treec7808d2e87f96504e19f85e87eb044f3b1399572 /luxc/src
parent0bfb1b4b1431c51441e4b47160e8c7dc8109da1b (diff)
- Now saving all the JS in a single file, instead of multiple files.
Diffstat (limited to 'luxc/src')
-rw-r--r--luxc/src/lux/compiler/js/base.clj34
1 files changed, 33 insertions, 1 deletions
diff --git a/luxc/src/lux/compiler/js/base.clj b/luxc/src/lux/compiler/js/base.clj
index fcf8a248c..50ece15e6 100644
--- a/luxc/src/lux/compiler/js/base.clj
+++ b/luxc/src/lux/compiler/js/base.clj
@@ -30,6 +30,28 @@
&/$None
]))
+(def ^String module-js-name "module.js")
+
+(def init-buffer
+ (fn [compiler-state]
+ (&/$Right (&/T [(&/update$ &/$host
+ (fn [host]
+ (&/set$ $buffer
+ (&/$Some (new StringBuilder))
+ host))
+ compiler-state)
+ nil]))))
+
+(def get-buffer
+ (fn [compiler-state]
+ (|case (->> compiler-state (&/get$ &/$host) (&/get$ $buffer))
+ (&/$Some _buffer)
+ (&/$Right (&/T [compiler-state
+ _buffer]))
+
+ (&/$None)
+ (&/$Left "[Error] No buffer available."))))
+
(defn run-js! [^String js-code]
(fn [compiler-state]
(|let [^NashornScriptEngine interpreter (->> compiler-state (&/get$ &/$host) (&/get$ $interpreter))]
@@ -189,11 +211,21 @@
(|do [_ (run-js! script)
eval? &/get-eval
module &/get-module-name
+ ^StringBuilder buffer get-buffer
+ :let [_ (when (not eval?)
+ (.append buffer ^String (str script "\n")))]]
+ (return nil)))
+
+(def save-module-js!
+ (|do [eval? &/get-eval
+ module &/get-module-name
+ ^StringBuilder buffer get-buffer
:let [_ (when (not eval?)
(let [^String module* (&host/->module-class module)
module-dir (str @&&/!output-dir java.io.File/separator (.replace module* "/" java.io.File/separator))]
(do (.mkdirs (File. module-dir))
- (&&/write-file (str module-dir java.io.File/separator (&host/def-name name) ".js") (.getBytes script)))))]]
+ (&&/write-file (str module-dir java.io.File/separator module-js-name)
+ (.getBytes (.toString buffer))))))]]
(return nil)))
(defn js-module [module]