Skip to content

Commit feccc01

Browse files
committed
fix Node.js regressions due to AOT
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
1 parent 7e1f81a commit feccc01

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

src/clj/cljs/compiler.clj

+7-12
Original file line numberDiff line numberDiff line change
@@ -848,19 +848,14 @@
848848
(emitln "if(!COMPILED) " loaded-libs " = cljs.core.set();"))
849849
(doseq [lib (remove (set (vals seen)) (distinct (vals libs)))]
850850
(cond
851-
(ana/foreign-dep? lib)
851+
(and (= :nodejs (get-in @env/*compiler* [:options :target]))
852+
(ana/foreign-dep? lib))
852853
;; under node.js we load foreign libs globally
853-
(if (= :nodejs (get-in @env/*compiler* [:options :target]))
854-
(let [js-index (:js-dependency-index @env/*compiler*)
855-
ijs-url (get-in js-index [(name lib) :url])]
856-
(emitln "cljs.core.load_file(\"" (util/get-name ijs-url) "\");"))
857-
;; otherwise only include if set in the options to do so,
858-
;; in the browser unnecessary due to the fact that goog.require
859-
;; there works by writing all deps as script tags, this doesn't
860-
;; work in Rhino-like environment where we do a proper goog.require
861-
;; on demand
862-
(when (get-in @env/*compiler* [:options :require-foreign])
863-
(emitln "goog.require('" (munge lib) "');")))
854+
(let [{:keys [js-dependency-index options]} @env/*compiler*
855+
ijs-url (get-in js-dependency-index [(name lib) :url])]
856+
(emitln "cljs.core.load_file(\""
857+
(str (io/file (util/output-directory options) (util/get-name ijs-url)))
858+
"\");"))
864859

865860
(-> libs meta :reload)
866861
(emitln "goog.require('" (munge lib) "', 'reload');")

src/clj/cljs/core.clj

+2-10
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,6 @@
317317
(defmacro false? [x]
318318
(bool-expr (core/list 'js* "~{} === false" x)))
319319

320-
(defmacro array? [x]
321-
(if (= :nodejs (-> @env/*compiler* :options :target))
322-
(bool-expr `(.isArray js/Array ~x))
323-
(bool-expr (core/list 'js* "~{} instanceof Array" x))))
324-
325320
(defmacro string? [x]
326321
(bool-expr (core/list 'js* "typeof ~{} === 'string'" x)))
327322

@@ -1974,9 +1969,6 @@
19741969
[vol f & args]
19751970
`(-vreset! ~vol (~f (-deref ~vol) ~@args)))
19761971

1972+
;; INTERNAL - do not use, only for Node.js
19771973
(defmacro load-file* [f]
1978-
(core/let [{:keys [target output-dir]} (:options @env/*compiler*)]
1979-
(core/condp = target
1980-
;; under Node.js, always relative to JVM working directory
1981-
:nodejs `(. js/goog (~'nodeGlobalRequire (str ~output-dir ~File/separator ~f)))
1982-
`(. js/goog (~'importScript_ ~f)))))
1974+
`(. js/goog (~'nodeGlobalRequire ~f)))

src/clj/cljs/repl/rhino.clj

+1-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@
169169
(defrecord RhinoEnv []
170170
repl/IReplEnvOptions
171171
(-repl-options [this]
172-
{:require-foreign true
173-
:output-dir ".cljs_rhino_repl"
172+
{:output-dir ".cljs_rhino_repl"
174173
:wrap wrap-fn})
175174
repl/IParseStacktrace
176175
(-parse-stacktrace [this frames-str ret {output-dir :output-dir}]

src/cljs/cljs/core.cljs

+4-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@
153153
(defn ^boolean array?
154154
"Returns true if x is a JavaScript array."
155155
[x]
156-
(cljs.core/array? x))
156+
(if (identical? *target* "nodejs")
157+
(.isArray js/Array x)
158+
(instance? js/Array x)))
157159

158160
(defn ^boolean number?
159161
"Returns true if x is a JavaScript number."
@@ -221,7 +223,7 @@
221223
s
222224
(str ty)))
223225

224-
;; INTERNAL - do not use
226+
;; INTERNAL - do not use, only for Node.js
225227
(defn load-file [file]
226228
(when-not js/COMPILED
227229
(cljs.core/load-file* file)))

0 commit comments

Comments
 (0)