Skip to content

Commit

Permalink
CLJS-1179: strange load-file behavior
Browse files Browse the repository at this point in the history
cljs.repl/load-namespace:
  - sym can actually be a string as well, rename to ns

cljs.repl/load-file:
  - need to load dependencies before loading the compiled file
  • Loading branch information
swannodette committed Mar 31, 2015
1 parent 380c8b1 commit 5b847b9
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/clj/cljs/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,23 @@
"Load a namespace and all of its dependencies into the evaluation environment.
The environment is responsible for ensuring that each namespace is loaded once and
only once."
([repl-env sym] (load-namespace repl-env sym nil))
([repl-env sym opts]
(let [sym (if (and (seq? sym)
(= (first sym) 'quote))
(second sym)
sym)
([repl-env ns] (load-namespace repl-env ns nil))
([repl-env ns opts]
(let [ns (if (and (seq? ns)
(= (first ns) 'quote))
(second ns)
ns)
;; TODO: add pre-condition to source-on-disk, the
;; source must supply at least :url - David
sources (cljsc/add-dependencies
(merge (env->opts repl-env) opts)
{:requires [(name sym)] :type :seed
:url (:uri (cljsc/source-for-namespace
sym env/*compiler*))})
deps (->> sources
(remove (comp #{["goog"]} :provides))
(remove (comp #{:seed} :type))
(map #(select-keys % [:provides :url])))]
sources (cljsc/add-dependencies
(merge (env->opts repl-env) opts)
{:requires [(name ns)] :type :seed
:url (:uri (cljsc/source-for-namespace
ns env/*compiler*))})
deps (->> sources
(remove (comp #{["goog"]} :provides))
(remove (comp #{:seed} :type))
(map #(select-keys % [:provides :url])))]
(if (:output-dir opts)
;; REPLs that read from :output-dir just need to add deps,
;; environment will handle actual loading - David
Expand Down Expand Up @@ -478,8 +478,6 @@
(let [env (assoc env :ns (ana/get-namespace ana/*cljs-ns*))]
(evaluate-form repl-env env filename form))))))

;; TODO: this should probably compile dependencies - David

(defn load-file
([repl-env f] (load-file repl-env f *repl-opts*))
([repl-env f opts]
Expand All @@ -492,6 +490,8 @@
(assoc opts
:output-file
(cljsc/src-file->target-file src)))]
;; need to load dependencies first
(load-dependencies repl-env (:requires compiled) opts)
;; make sure it's been analyzed, this is because if it's already compiled
;; cljs.compiler/compile-file won't do anything, good for builds,
;; but a bit annoying here
Expand Down

0 comments on commit 5b847b9

Please sign in to comment.