Skip to content

Commit

Permalink
fix Node.js regressions due to AOT
Browse files Browse the repository at this point in the history
move all Node.js target decisions to runtime so AOTed core can be used
by all targets.

fix Node.js REPL foreign dep support regression
  • Loading branch information
swannodette committed Mar 15, 2015
1 parent 7e1f81a commit feccc01
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
19 changes: 7 additions & 12 deletions src/clj/cljs/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -848,19 +848,14 @@
(emitln "if(!COMPILED) " loaded-libs " = cljs.core.set();"))
(doseq [lib (remove (set (vals seen)) (distinct (vals libs)))]
(cond
(ana/foreign-dep? lib)
(and (= :nodejs (get-in @env/*compiler* [:options :target]))
(ana/foreign-dep? lib))
;; under node.js we load foreign libs globally
(if (= :nodejs (get-in @env/*compiler* [:options :target]))
(let [js-index (:js-dependency-index @env/*compiler*)
ijs-url (get-in js-index [(name lib) :url])]
(emitln "cljs.core.load_file(\"" (util/get-name ijs-url) "\");"))
;; otherwise only include if set in the options to do so,
;; in the browser unnecessary due to the fact that goog.require
;; there works by writing all deps as script tags, this doesn't
;; work in Rhino-like environment where we do a proper goog.require
;; on demand
(when (get-in @env/*compiler* [:options :require-foreign])
(emitln "goog.require('" (munge lib) "');")))
(let [{:keys [js-dependency-index options]} @env/*compiler*
ijs-url (get-in js-dependency-index [(name lib) :url])]
(emitln "cljs.core.load_file(\""
(str (io/file (util/output-directory options) (util/get-name ijs-url)))
"\");"))

(-> libs meta :reload)
(emitln "goog.require('" (munge lib) "', 'reload');")
Expand Down
12 changes: 2 additions & 10 deletions src/clj/cljs/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,6 @@
(defmacro false? [x]
(bool-expr (core/list 'js* "~{} === false" x)))

(defmacro array? [x]
(if (= :nodejs (-> @env/*compiler* :options :target))
(bool-expr `(.isArray js/Array ~x))
(bool-expr (core/list 'js* "~{} instanceof Array" x))))

(defmacro string? [x]
(bool-expr (core/list 'js* "typeof ~{} === 'string'" x)))

Expand Down Expand Up @@ -1974,9 +1969,6 @@
[vol f & args]
`(-vreset! ~vol (~f (-deref ~vol) ~@args)))

;; INTERNAL - do not use, only for Node.js
(defmacro load-file* [f]
(core/let [{:keys [target output-dir]} (:options @env/*compiler*)]
(core/condp = target
;; under Node.js, always relative to JVM working directory
:nodejs `(. js/goog (~'nodeGlobalRequire (str ~output-dir ~File/separator ~f)))
`(. js/goog (~'importScript_ ~f)))))
`(. js/goog (~'nodeGlobalRequire ~f)))
3 changes: 1 addition & 2 deletions src/clj/cljs/repl/rhino.clj
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@
(defrecord RhinoEnv []
repl/IReplEnvOptions
(-repl-options [this]
{:require-foreign true
:output-dir ".cljs_rhino_repl"
{:output-dir ".cljs_rhino_repl"
:wrap wrap-fn})
repl/IParseStacktrace
(-parse-stacktrace [this frames-str ret {output-dir :output-dir}]
Expand Down
6 changes: 4 additions & 2 deletions src/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@
(defn ^boolean array?
"Returns true if x is a JavaScript array."
[x]
(cljs.core/array? x))
(if (identical? *target* "nodejs")
(.isArray js/Array x)
(instance? js/Array x)))

(defn ^boolean number?
"Returns true if x is a JavaScript number."
Expand Down Expand Up @@ -221,7 +223,7 @@
s
(str ty)))

;; INTERNAL - do not use
;; INTERNAL - do not use, only for Node.js
(defn load-file [file]
(when-not js/COMPILED
(cljs.core/load-file* file)))
Expand Down

0 comments on commit feccc01

Please sign in to comment.