Skip to content

Commit

Permalink
CLJS-3259: revert public api change made in 45022fa
Browse files Browse the repository at this point in the history
Restore checking for a bound compiler state.
  • Loading branch information
swannodette committed Jul 8, 2020
1 parent 6691bae commit b7895ae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/main/clojure/cljs/analyzer/api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
([env form] (analyze env form nil))
([env form name] (analyze env form name nil))
([env form name opts]
(analyze (empty-state opts) env form name opts))
(analyze (or (current-state) (empty-state opts)) env form name opts))
([state env form name opts]
(env/with-compiler-env state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand All @@ -161,7 +161,7 @@
([src] (parse-ns src nil nil))
([src opts] (parse-ns src nil opts))
([src dest opts]
(parse-ns (empty-state opts) src dest opts))
(parse-ns (or (current-state) (empty-state opts)) src dest opts))
([state src dest opts]
(env/with-compiler-env state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand All @@ -178,7 +178,7 @@
meaningful value."
([f] (analyze-file f nil))
([f opts]
(analyze-file (empty-state opts) f opts))
(analyze-file (or (current-state) (empty-state opts)) f opts))
([state f opts]
(env/with-compiler-env state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand Down
37 changes: 22 additions & 15 deletions src/main/clojure/cljs/build/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
('example.core 'example.util)"
([namespaces]
(closure/cljs-dependents-for-macro-namespaces
(ana-api/empty-state) namespaces))
(or (ana-api/current-state) (ana-api/empty-state)) namespaces))
([state namespaces]
(closure/cljs-dependents-for-macro-namespaces state namespaces)))

Expand All @@ -68,7 +68,8 @@
provide build options with :output-dir specified."
([src] (src-file->target-file src nil))
([src opts]
(src-file->target-file (ana-api/empty-state opts) src opts))
(src-file->target-file
(or (ana-api/current-state) (ana-api/empty-state opts)) src opts))
([state src opts]
(ana-api/with-state state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand All @@ -79,7 +80,8 @@
the goog.require statement for it."
([src] (src-file->goog-require src nil))
([src opts]
(src-file->goog-require (ana-api/empty-state opts) src opts))
(src-file->goog-require
(or (ana-api/current-state) (ana-api/empty-state opts)) src opts))
([state src opts]
(ana-api/with-state state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand Down Expand Up @@ -121,7 +123,7 @@
.cljs, .cljc, .js. Returns a map containing :relative-path a string, and
:uri a URL."
([ns]
(ns->location ns (ana-api/empty-state)))
(ns->location ns (or (ana-api/current-state) (ana-api/empty-state))))
([ns compiler-env]
(closure/source-for-namespace ns compiler-env)))

Expand All @@ -139,7 +141,7 @@
([xs]
(add-dependency-sources xs {}))
([xs opts]
(add-dependency-sources (ana-api/empty-state opts) xs opts))
(add-dependency-sources (or (ana-api/current-state) (ana-api/empty-state opts)) xs opts))
([state xs opts]
(ana-api/with-state state
(closure/add-dependency-sources xs opts))))
Expand Down Expand Up @@ -192,7 +194,7 @@
(defn compile
"Given a Compilable, compile it and return an IJavaScript."
([opts compilable]
(compile (ana-api/empty-state opts) opts compilable))
(compile (or (ana-api/current-state) (ana-api/empty-state opts)) opts compilable))
([state opts compilable]
(ana-api/with-state state
(closure/compile compilable opts))))
Expand All @@ -214,11 +216,13 @@
(build nil opts))
([source opts]
(build source opts
(ana-api/empty-state
;; need to dissoc :foreign-libs since we won't know what overriding
;; foreign libspecs are referring to until after add-implicit-options
;; - David
(closure/add-externs-sources (dissoc opts :foreign-libs)))))
(or
(ana-api/current-state)
(ana-api/empty-state
;; need to dissoc :foreign-libs since we won't know what overriding
;; foreign libspecs are referring to until after add-implicit-options
;; - David
(closure/add-externs-sources (dissoc opts :foreign-libs))))))
([source opts compiler-env]
(doseq [[unknown-opt suggested-opt] (util/unknown-opts (set (keys opts)) closure/known-opts)]
(when suggested-opt
Expand All @@ -230,8 +234,9 @@
"Given a source which can be compiled, watch it for changes to produce."
([source opts]
(watch source opts
(ana-api/empty-state
(closure/add-externs-sources opts))))
(or (ana-api/current-state)
(ana-api/empty-state
(closure/add-externs-sources opts)))))
([source opts compiler-env]
(watch source opts compiler-env nil))
([source opts compiler-env stop]
Expand Down Expand Up @@ -291,12 +296,14 @@
installed."
([entries]
(node-inputs entries
(:options (ana-api/empty-state))))
(:options (or (ana-api/current-state) (ana-api/empty-state)))))
([entries opts]
(closure/node-inputs entries opts)))

(defn node-modules
"Return a sequence of requirable libraries found under node_modules."
([]
(node-modules {}))
([opts]
(ana-api/with-state (ana-api/empty-state opts)
(ana-api/with-state (or (ana-api/current-state) (ana-api/empty-state opts))
(filter :provides (closure/index-node-modules-dir)))))
10 changes: 5 additions & 5 deletions src/main/clojure/cljs/compiler/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(defn emit
"Given an AST node generated by the analyzer emit JavaScript as a string."
([ast]
(emit (ana-api/empty-state) ast))
(emit (or (ana-api/current-state) (ana-api/empty-state)) ast))
([state ast]
(ana-api/with-state state
(with-out-str
Expand All @@ -40,7 +40,7 @@
(:options @state))))
([opts] (with-core-cljs opts (fn [])))
([opts body]
(with-core-cljs (ana-api/empty-state opts) opts body))
(with-core-cljs (or (ana-api/current-state) (ana-api/empty-state opts)) opts body))
([state opts body]
(ana-api/with-state state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand All @@ -50,7 +50,7 @@
"Return true if the src file requires compilation."
([src dest] (requires-compilation? src dest nil))
([src dest opts]
(requires-compilation? (ana-api/empty-state opts) src dest opts))
(requires-compilation? (or (ana-api/current-state)(ana-api/empty-state opts)) src dest opts))
([state src dest opts]
(ana-api/with-state state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand All @@ -74,7 +74,7 @@
([src dest]
(compile-file src dest nil))
([src dest opts]
(compile-file (ana-api/empty-state opts) src dest opts))
(compile-file (or (ana-api/current-state) (ana-api/empty-state opts)) src dest opts))
([state src dest opts]
(ana-api/with-state state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand All @@ -94,7 +94,7 @@
([src-dir] (compile-root src-dir "out"))
([src-dir target-dir] (compile-root src-dir target-dir nil))
([src-dir target-dir opts]
(compile-root (ana-api/empty-state opts) src-dir target-dir opts))
(compile-root (or (ana-api/current-state) (ana-api/empty-state opts)) src-dir target-dir opts))
([state src-dir target-dir opts]
(ana-api/with-state state
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
Expand Down

0 comments on commit b7895ae

Please sign in to comment.