aboutsummaryrefslogtreecommitdiff
path: root/luxc/src/lux/compiler/js/base.clj
diff options
context:
space:
mode:
authorEduardo Julian2017-03-21 23:22:21 -0400
committerEduardo Julian2017-03-21 23:22:21 -0400
commit749608e2f4f9804f33812b194297201851343947 (patch)
tree716888beb9aa95bf869445503b15a72325349288 /luxc/src/lux/compiler/js/base.clj
parentad2f9e165d2bdce646507f1aadd133b8f67ae75f (diff)
- Now packaging the complete JS code.
Diffstat (limited to '')
-rw-r--r--luxc/src/lux/compiler/js/base.clj14
1 files changed, 12 insertions, 2 deletions
diff --git a/luxc/src/lux/compiler/js/base.clj b/luxc/src/lux/compiler/js/base.clj
index 417b35d5a..7f560b87d 100644
--- a/luxc/src/lux/compiler/js/base.clj
+++ b/luxc/src/lux/compiler/js/base.clj
@@ -21,13 +21,16 @@
(deftuple
["interpreter"
- "buffer"])
+ "buffer"
+ "total-buffer"])
(defn js-host []
(&/$Js (&/T [;; "interpreter"
(.getScriptEngine (new NashornScriptEngineFactory))
;; "buffer"
&/$None
+ ;; "total-buffer"
+ (new StringBuilder)
])))
(def ^String module-js-name "module.js")
@@ -44,6 +47,10 @@
(&/$None)
(&/fail-with-loc "[Error] No buffer available."))))
+(def get-total-buffer
+ (|do [host &/js-host]
+ (return (&/get$ $total-buffer host))))
+
(defn run-js! [^String js-code]
(|do [host &/js-host
:let [interpreter ^NashornScriptEngine (&/get$ $interpreter host)]]
@@ -216,12 +223,15 @@
(|do [eval? &/get-eval
module &/get-module-name
^StringBuilder buffer get-buffer
+ ^StringBuilder total-buffer get-total-buffer
+ :let [buffer-code (.toString buffer)
+ _ (.append total-buffer ^String (str buffer-code "\n"))]
: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 module-js-name)
- (.getBytes (.toString buffer))))))]]
+ (.getBytes buffer-code)))))]]
(return nil)))
(defn js-module [module]