Skip to content

Commit b06247b

Browse files
committed
add bits necessary to dogfood cljs.repl on build / analysis public apis
1 parent 292a8a8 commit b06247b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/main/clojure/cljs/analyzer/api.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
[]
2121
(ana/empty-env))
2222

23+
(defmacro no-warn
24+
"Disable analyzer warnings for any analysis executed in body."
25+
[& body]
26+
(let [no-warnings (zipmap (keys ana/*cljs-warnings*) (repeat false))]
27+
`(binding [ana/*cljs-warnings* ~no-warnings]
28+
~@body)))
29+
2330
(defn analyze
2431
"Given an environment, a map containing {:locals (mapping of names to bindings), :context
2532
(one of :statement, :expr, :return), :ns (a symbol naming the

src/main/clojure/cljs/build/api.clj

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
For example: a build script may need to how to invalidate compiled
1313
files so that they will be recompiled."
14+
(:refer-clojure :exclude [compile])
1415
(:require [cljs.util :as util]
1516
[cljs.env :as env]
1617
[cljs.analyzer :as ana]
@@ -96,6 +97,39 @@
9697
;; =============================================================================
9798
;; Main API
9899

100+
(defn goog-dep-string
101+
"Given compiler options and a IJavaScript instance return the corresponding
102+
goog.addDependency string"
103+
[opts ijs]
104+
(closure/add-dep-string opts ijs))
105+
106+
(defn source-on-disk
107+
"Ensure that the given IJavaScript exists on disk in the output directory.
108+
Return updated IJavaScript with the new location if necessary."
109+
[opts ijs]
110+
(closure/source-on-disk opts ijs))
111+
112+
(defn ns->source
113+
"Given a namespace as a symbol return the corresponding resource if it exists."
114+
[ns]
115+
(util/ns->source ns))
116+
117+
(defn ns->location
118+
"Given a namespace and compilation environment return the relative path and
119+
uri of the corresponding source regardless of the source language extension:
120+
.cljs, .cljc, .js. Returns a map containing :relative-path a string, and
121+
:uri a URL."
122+
([ns] (ns->location ns env/*compiler*))
123+
([ns compiler-env]
124+
(closure/source-for-namespace ns compiler-env)))
125+
126+
(defn add-dependencies
127+
"Given one or more IJavaScript objects in dependency order, produce
128+
a new sequence of IJavaScript objects which includes the input list
129+
plus all dependencies in dependency order."
130+
[opts & ijss]
131+
(closure/add-dependencies opts ijss))
132+
99133
(defn add-implicit-options
100134
"Given a valid map of build options add any standard implicit options. For
101135
example :optimizations :none implies :cache-analysis true and :source-map
@@ -120,6 +154,21 @@
120154
[compiled])))]
121155
(mapcat compile-input xs)))))
122156

157+
(defn compile
158+
"Given a Compilable, compile it and return an IJavaScript."
159+
[opts compilable]
160+
(closure/compile compilable opts))
161+
162+
(defn output-unoptimized
163+
"Ensure that all JavaScript source files are on disk (not in jars),
164+
write the goog deps file including only the libraries that are being
165+
used and write the deps file for the current project.
166+
167+
The deps file for the current project will include third-party
168+
libraries."
169+
[opts & sources]
170+
(apply closure/output-unoptimized opts sources))
171+
123172
(defn build
124173
"Given a source which can be compiled, produce runnable JavaScript."
125174
([source opts]

0 commit comments

Comments
 (0)