clojurific 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/cljf/launcher.js +15 -8
- package/package.json +2 -2
- package/compiler/deps.edn +0 -9
- package/compiler/src/main/cljs/cljs/analyzer/passes/and_or.cljc +0 -118
- package/compiler/src/main/cljs/cljs/analyzer/passes/lite.cljc +0 -32
- package/compiler/src/main/cljs/cljs/analyzer/passes.cljc +0 -32
- package/compiler/src/main/cljs/cljs/bootstrap_nodejs.js +0 -154
- package/compiler/src/main/cljs/cljs/core/specs/alpha.cljc +0 -272
- package/compiler/src/main/cljs/cljs/core/specs/alpha.cljs +0 -10
- package/compiler/src/main/cljs/cljs/core.cljs +0 -13194
- package/compiler/src/main/cljs/cljs/esm/goog/array.js +0 -61
- package/compiler/src/main/cljs/cljs/esm/goog/math.js +0 -1846
- package/compiler/src/main/cljs/cljs/esm/goog/object.js +0 -80
- package/compiler/src/main/cljs/cljs/esm/goog/string.js +0 -192
- package/compiler/src/main/cljs/cljs/esm/goog/userAgent/product.js +0 -10
- package/compiler/src/main/cljs/cljs/esm/goog.js +0 -90
- package/compiler/src/main/cljs/cljs/esm/karma.cljs +0 -103
- package/compiler/src/main/cljs/cljs/esm/lazy.clj +0 -51
- package/compiler/src/main/cljs/cljs/esm/lazy.cljs +0 -49
- package/compiler/src/main/cljs/cljs/esm/node_test.cljs +0 -21
- package/compiler/src/main/cljs/cljs/esm/repl_runtime.cljs +0 -353
- package/compiler/src/main/cljs/cljs/externs.js +0 -27
- package/compiler/src/main/cljs/cljs/imul.js +0 -11
- package/compiler/src/main/cljs/cljs/js.clj +0 -24
- package/compiler/src/main/cljs/cljs/js.cljs +0 -1432
- package/compiler/src/main/cljs/cljs/loader.cljs +0 -107
- package/compiler/src/main/cljs/cljs/main.clj +0 -67
- package/compiler/src/main/cljs/cljs/math.cljs +0 -869
- package/compiler/src/main/cljs/cljs/module_deps.js +0 -250
- package/compiler/src/main/cljs/cljs/nodejs.cljs +0 -27
- package/compiler/src/main/cljs/cljs/nodejs_externs.js +0 -3
- package/compiler/src/main/cljs/cljs/nodejscli.cljs +0 -22
- package/compiler/src/main/cljs/cljs/pprint.cljc +0 -167
- package/compiler/src/main/cljs/cljs/pprint.cljs +0 -3325
- package/compiler/src/main/cljs/cljs/proxy/impl.cljs +0 -32
- package/compiler/src/main/cljs/cljs/proxy.cljs +0 -184
- package/compiler/src/main/cljs/cljs/reader.clj +0 -18
- package/compiler/src/main/cljs/cljs/reader.cljs +0 -214
- package/compiler/src/main/cljs/cljs/repl.cljs +0 -206
- package/compiler/src/main/cljs/cljs/source_map/base64.cljs +0 -25
- package/compiler/src/main/cljs/cljs/source_map/base64_vlq.cljs +0 -102
- package/compiler/src/main/cljs/cljs/source_map.cljs +0 -305
- package/compiler/src/main/cljs/cljs/spec/alpha.cljc +0 -564
- package/compiler/src/main/cljs/cljs/spec/alpha.cljs +0 -1510
- package/compiler/src/main/cljs/cljs/spec/gen/alpha.cljc +0 -68
- package/compiler/src/main/cljs/cljs/spec/gen/alpha.cljs +0 -183
- package/compiler/src/main/cljs/cljs/spec/test/alpha.cljc +0 -329
- package/compiler/src/main/cljs/cljs/spec/test/alpha.cljs +0 -380
- package/compiler/src/main/cljs/cljs/stacktrace.cljc +0 -578
- package/compiler/src/main/cljs/cljs/test.cljc +0 -458
- package/compiler/src/main/cljs/cljs/test.cljs +0 -606
- package/compiler/src/main/cljs/clojure/browser/dom.cljs +0 -152
- package/compiler/src/main/cljs/clojure/browser/event.cljs +0 -101
- package/compiler/src/main/cljs/clojure/browser/net.cljs +0 -181
- package/compiler/src/main/cljs/clojure/browser/repl/preload.cljs +0 -13
- package/compiler/src/main/cljs/clojure/browser/repl.cljs +0 -283
- package/compiler/src/main/cljs/clojure/core/protocols.cljs +0 -29
- package/compiler/src/main/cljs/clojure/core/reducers.cljs +0 -312
- package/compiler/src/main/cljs/clojure/data.cljs +0 -162
- package/compiler/src/main/cljs/clojure/datafy.cljs +0 -63
- package/compiler/src/main/cljs/clojure/edn.cljs +0 -55
- package/compiler/src/main/cljs/clojure/reflect.cljs +0 -57
- package/compiler/src/main/cljs/clojure/set.cljs +0 -165
- package/compiler/src/main/cljs/clojure/string.cljs +0 -290
- package/compiler/src/main/cljs/clojure/walk.cljs +0 -98
- package/compiler/src/main/cljs/clojure/zip.cljs +0 -291
- package/compiler/src/main/cljs/process/env.cljs +0 -12
- package/compiler/src/main/cljs/shadow/resource.clj +0 -60
- package/compiler/src/main/cljs/shadow/resource.cljs +0 -10
- package/compiler/src/main/clojure/cljs/analyzer/api.cljc +0 -299
- package/compiler/src/main/clojure/cljs/analyzer/impl/namespaces.cljc +0 -68
- package/compiler/src/main/clojure/cljs/analyzer/impl.cljc +0 -59
- package/compiler/src/main/clojure/cljs/analyzer/macros.clj +0 -57
- package/compiler/src/main/clojure/cljs/analyzer/utils.clj +0 -36
- package/compiler/src/main/clojure/cljs/analyzer.cljc +0 -5292
- package/compiler/src/main/clojure/cljs/build/api.clj +0 -309
- package/compiler/src/main/clojure/cljs/cli.clj +0 -812
- package/compiler/src/main/clojure/cljs/closure.clj +0 -3440
- package/compiler/src/main/clojure/cljs/compiler/api.clj +0 -101
- package/compiler/src/main/clojure/cljs/compiler/macros.clj +0 -16
- package/compiler/src/main/clojure/cljs/compiler.cljc +0 -2748
- package/compiler/src/main/clojure/cljs/core/macros.clj +0 -43
- package/compiler/src/main/clojure/cljs/core/server.clj +0 -167
- package/compiler/src/main/clojure/cljs/core.cljc +0 -3719
- package/compiler/src/main/clojure/cljs/env/macros.clj +0 -37
- package/compiler/src/main/clojure/cljs/env.cljc +0 -102
- package/compiler/src/main/clojure/cljs/esm/repl/nrepl.clj +0 -151
- package/compiler/src/main/clojure/cljs/esm/repl.clj +0 -878
- package/compiler/src/main/clojure/cljs/esm.clj +0 -987
- package/compiler/src/main/clojure/cljs/externs/default.edn +0 -1549
- package/compiler/src/main/clojure/cljs/externs.clj +0 -479
- package/compiler/src/main/clojure/cljs/foreign/node.clj +0 -207
- package/compiler/src/main/clojure/cljs/instant.clj +0 -54
- package/compiler/src/main/clojure/cljs/js_deps.cljc +0 -412
- package/compiler/src/main/clojure/cljs/module_graph.cljc +0 -402
- package/compiler/src/main/clojure/cljs/repl/bootstrap.clj +0 -53
- package/compiler/src/main/clojure/cljs/repl/browser.clj +0 -540
- package/compiler/src/main/clojure/cljs/repl/node.clj +0 -253
- package/compiler/src/main/clojure/cljs/repl/node_repl.js +0 -114
- package/compiler/src/main/clojure/cljs/repl/reflect.clj +0 -85
- package/compiler/src/main/clojure/cljs/repl/server.clj +0 -236
- package/compiler/src/main/clojure/cljs/repl.cljc +0 -1615
- package/compiler/src/main/clojure/cljs/server/browser.clj +0 -54
- package/compiler/src/main/clojure/cljs/server/node.clj +0 -54
- package/compiler/src/main/clojure/cljs/source_map/base64.clj +0 -28
- package/compiler/src/main/clojure/cljs/source_map/base64_vlq.clj +0 -104
- package/compiler/src/main/clojure/cljs/source_map.clj +0 -369
- package/compiler/src/main/clojure/cljs/support.cljc +0 -18
- package/compiler/src/main/clojure/cljs/tagged_literals.cljc +0 -93
- package/compiler/src/main/clojure/cljs/util.cljc +0 -420
- package/compiler/src/main/clojure/cljs/vendor/bridge.clj +0 -42
- package/compiler/src/main/clojure/cljs/vendor/clojure/data/json.clj +0 -809
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/default_data_readers.clj +0 -303
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/edn.clj +0 -440
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/commons.clj +0 -131
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/errors.clj +0 -214
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/inspect.clj +0 -91
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/impl/utils.clj +0 -127
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader/reader_types.clj +0 -431
- package/compiler/src/main/clojure/cljs/vendor/clojure/tools/reader.clj +0 -1035
- package/compiler/src/main/clojure/cljs/vendor/cognitect/transit.clj +0 -479
- /package/{compiler/no-clojurescript → no-clojurescript}/deps.edn +0 -0
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
; Copyright (c) Rich Hickey. All rights reserved.
|
|
2
|
-
; The use and distribution terms for this software are covered by the
|
|
3
|
-
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
|
4
|
-
; which can be found in the file epl-v10.html at the root of this distribution.
|
|
5
|
-
; By using this software in any fashion, you are agreeing to be bound by
|
|
6
|
-
; the terms of this license.
|
|
7
|
-
; You must not remove this notice, or any other, from this software.
|
|
8
|
-
|
|
9
|
-
(ns cljs.esm.repl-runtime
|
|
10
|
-
"Evaluates the REPL's forms (cljs.esm.repl) in a running build compiled
|
|
11
|
-
with :esm-repl, which the main namespaces import first.
|
|
12
|
-
|
|
13
|
-
Under :esm-repl modules register their namespace object, the setters of
|
|
14
|
-
all their instances and the npm modules they import with
|
|
15
|
-
globalThis.$CLJS_ESM (see cljs.compiler/emit-esm-repl-footer). A form
|
|
16
|
-
compiled by the REPL is the body of a function taking the namespaces it
|
|
17
|
-
references, views of them: a var reads the module's binding, assigning it
|
|
18
|
-
(def, set!) sets the bindings of all of the module's instances, as a hot
|
|
19
|
-
reload does. Vars the module doesn't define, and namespaces only defined
|
|
20
|
-
at the REPL, live in an overlay.
|
|
21
|
-
|
|
22
|
-
Messages are JSON-compatible objects, handle! takes the REPL's and replies
|
|
23
|
-
with send!; connect-vite! carries them over Vite's hot module reloading
|
|
24
|
-
websocket, and defines cljs_eval for the browser's console (see
|
|
25
|
-
console-eval).")
|
|
26
|
-
|
|
27
|
-
(def ^:private registry
|
|
28
|
-
(or (.-$CLJS_ESM js/globalThis)
|
|
29
|
-
(set! (.-$CLJS_ESM js/globalThis) #js {:nses (js/Map.)})))
|
|
30
|
-
|
|
31
|
-
(def ^:private overlays (js/Map.))
|
|
32
|
-
|
|
33
|
-
(def ^:private views (js/Map.))
|
|
34
|
-
|
|
35
|
-
(defn- overlay [ns]
|
|
36
|
-
(or (.get overlays ns)
|
|
37
|
-
(let [o #js {}]
|
|
38
|
-
(.set overlays ns o)
|
|
39
|
-
o)))
|
|
40
|
-
|
|
41
|
-
(defn- has-own? [o k]
|
|
42
|
-
(.call (.. js/Object -prototype -hasOwnProperty) o k))
|
|
43
|
-
|
|
44
|
-
(defn- set-var!
|
|
45
|
-
"Sets var nm of namespace ns: the bindings of all instances of the
|
|
46
|
-
namespace's module if it defines the var, otherwise the overlay."
|
|
47
|
-
[ns nm v]
|
|
48
|
-
(let [entry (.get (.-nses registry) ns)]
|
|
49
|
-
(if (and entry (js-in nm (.-mod entry)))
|
|
50
|
-
(doseq [set (.-sets entry)]
|
|
51
|
-
(try
|
|
52
|
-
(set nm v)
|
|
53
|
-
;; an earlier instance without the var
|
|
54
|
-
(catch :default _)))
|
|
55
|
-
(aset (overlay ns) nm v))
|
|
56
|
-
v))
|
|
57
|
-
|
|
58
|
-
(defn- lookup [ns k]
|
|
59
|
-
(let [entry (.get (.-nses registry) ns)]
|
|
60
|
-
(cond
|
|
61
|
-
(and entry (js-in k (.-mod entry))) (unchecked-get (.-mod entry) k)
|
|
62
|
-
(and entry (has-own? (.-libs entry) k)) (unchecked-get (.-libs entry) k)
|
|
63
|
-
:else (unchecked-get (overlay ns) k))))
|
|
64
|
-
|
|
65
|
-
(defn view
|
|
66
|
-
"The view of namespace ns REPL forms reference it through."
|
|
67
|
-
[ns]
|
|
68
|
-
(or (.get views ns)
|
|
69
|
-
(let [v (js/Proxy.
|
|
70
|
-
#js {}
|
|
71
|
-
#js {:get (fn [_ k]
|
|
72
|
-
(cond
|
|
73
|
-
(not (string? k)) nil
|
|
74
|
-
(= "$$set" k) (fn [nm v] (set-var! ns nm v))
|
|
75
|
-
;; set! of a dynamic var, binding
|
|
76
|
-
(.startsWith k "$set$") (fn [v] (set-var! ns (subs k 5) v))
|
|
77
|
-
:else (lookup ns k)))
|
|
78
|
-
:set (fn [_ k v]
|
|
79
|
-
(set-var! ns k v)
|
|
80
|
-
true)
|
|
81
|
-
:has (fn [_ k]
|
|
82
|
-
(let [entry (.get (.-nses registry) ns)]
|
|
83
|
-
(or (and entry (js-in k (.-mod entry)))
|
|
84
|
-
(has-own? (overlay ns) k))))})]
|
|
85
|
-
(.set views ns v)
|
|
86
|
-
v)))
|
|
87
|
-
|
|
88
|
-
(defn- root
|
|
89
|
-
"The output directory's URL, the REPL sends paths relative to it."
|
|
90
|
-
[]
|
|
91
|
-
;; not new URL("../../", import.meta.url), which Vite rewrites to the URL of
|
|
92
|
-
;; an asset
|
|
93
|
-
(let [url (.-url (js* "import.meta"))]
|
|
94
|
-
(js/URL. "../../" url)))
|
|
95
|
-
|
|
96
|
-
(defn- import-path [path]
|
|
97
|
-
(js* "import(/* @vite-ignore */ ~{})" (.-href (js/URL. path (root)))))
|
|
98
|
-
|
|
99
|
-
(defn- load-ns
|
|
100
|
-
"A promise of namespace ns' view, once its module (at path, relative to
|
|
101
|
-
the output directory) ran. Namespaces without a path only exist at the
|
|
102
|
-
REPL."
|
|
103
|
-
[ns path]
|
|
104
|
-
(if (or (nil? path) (.has (.-nses registry) ns))
|
|
105
|
-
(js/Promise.resolve (view ns))
|
|
106
|
-
(-> (import-path path)
|
|
107
|
-
(.then (fn [mod]
|
|
108
|
-
;; registered by the module, unless it's compiled without
|
|
109
|
-
;; :esm-repl
|
|
110
|
-
(when-not (.has (.-nses registry) ns)
|
|
111
|
-
(.set (.-nses registry) ns
|
|
112
|
-
#js {:mod mod :sets #js [(.-$$set mod)] :libs #js {} :gen 1}))
|
|
113
|
-
(view ns))))))
|
|
114
|
-
|
|
115
|
-
(defn- load-ref
|
|
116
|
-
"A promise of what a reference [alias ns kind path] of a REPL form is
|
|
117
|
-
bound to: a namespace's view (kind ns), a module's namespace object
|
|
118
|
-
(module, i.e. a goog shim) or its default export (default, Closure Library
|
|
119
|
-
namespaces run by the compatibility layer)."
|
|
120
|
-
[[_ ns kind path]]
|
|
121
|
-
(case kind
|
|
122
|
-
"ns" (load-ns ns path)
|
|
123
|
-
"module" (import-path path)
|
|
124
|
-
"default" (.then (import-path path) #(.-default %))))
|
|
125
|
-
|
|
126
|
-
(defn- error-reply [e]
|
|
127
|
-
(if (instance? js/Error e)
|
|
128
|
-
#js {:error (or (ex-message e) (str e))
|
|
129
|
-
:stack (.-stack e)
|
|
130
|
-
:exData (some-> (ex-data e) pr-str)}
|
|
131
|
-
#js {:error (pr-str e)}))
|
|
132
|
-
|
|
133
|
-
(defn- print-value [v {:strs [printLength printLevel]}]
|
|
134
|
-
(binding [*print-length* printLength
|
|
135
|
-
*print-level* printLevel]
|
|
136
|
-
(pr-str v)))
|
|
137
|
-
|
|
138
|
-
(defn- capture
|
|
139
|
-
"Calls f with the output printed meanwhile captured into the arrays out
|
|
140
|
-
and err, still printed where it would be, i.e. the console, which prints
|
|
141
|
-
lines."
|
|
142
|
-
[f out err]
|
|
143
|
-
(let [print-fn *print-fn*
|
|
144
|
-
print-err-fn *print-err-fn*]
|
|
145
|
-
(binding [*print-newline* true
|
|
146
|
-
*print-fn* (fn [s]
|
|
147
|
-
(.push out s)
|
|
148
|
-
(when (and print-fn (not= "\n" s)) (print-fn s)))
|
|
149
|
-
*print-err-fn* (fn [s]
|
|
150
|
-
(.push err s)
|
|
151
|
-
(when (and print-err-fn (not= "\n" s)) (print-err-fn s)))]
|
|
152
|
-
(f))))
|
|
153
|
-
|
|
154
|
-
(def ^:private console-evals
|
|
155
|
-
"The console's evaluations waiting for the REPL, {id {:resolve :reject
|
|
156
|
-
:opts}}, and the value of their last form evaluated, :value."
|
|
157
|
-
(atom {}))
|
|
158
|
-
|
|
159
|
-
(def ^:private console-ids (atom 0))
|
|
160
|
-
|
|
161
|
-
(defn- eval-js
|
|
162
|
-
"Evaluates a compiled REPL form, replies with its printed value, or its
|
|
163
|
-
error. Keeps the value of a console evaluation (see console-eval)."
|
|
164
|
-
[{:strs [code refs repl] :as msg} reply!]
|
|
165
|
-
(-> (js/Promise.all (into-array (map load-ref refs)))
|
|
166
|
-
(.then
|
|
167
|
-
(fn [args]
|
|
168
|
-
(let [out #js []
|
|
169
|
-
err #js []
|
|
170
|
-
done! (fn [m]
|
|
171
|
-
(reply! (doto m
|
|
172
|
-
(aset "out" (.join out ""))
|
|
173
|
-
(aset "err" (.join err "")))))
|
|
174
|
-
fail! (fn [e]
|
|
175
|
-
(when repl (set! *e e))
|
|
176
|
-
(done! (error-reply e)))
|
|
177
|
-
ok! (fn [v]
|
|
178
|
-
(when repl
|
|
179
|
-
(set! *3 *2)
|
|
180
|
-
(set! *2 *1)
|
|
181
|
-
(set! *1 v))
|
|
182
|
-
(when-let [k (get msg "keep")]
|
|
183
|
-
(when (contains? @console-evals k)
|
|
184
|
-
(swap! console-evals assoc-in [k :value] v)))
|
|
185
|
-
(done! #js {:value (print-value v msg)}))]
|
|
186
|
-
(try
|
|
187
|
-
(let [f (js/Reflect.construct js/Function (into-array (concat (map first refs) [code])))
|
|
188
|
-
v (capture #(.apply f nil args) out err)]
|
|
189
|
-
(if (and (get msg "await") (some? v) (fn? (.-then v)))
|
|
190
|
-
(.then v ok! fail!)
|
|
191
|
-
(ok! v)))
|
|
192
|
-
(catch :default e
|
|
193
|
-
(fail! e))))))
|
|
194
|
-
(.catch (fn [e] (reply! (error-reply e))))))
|
|
195
|
-
|
|
196
|
-
(def ^:private stamp-waiters (atom []))
|
|
197
|
-
|
|
198
|
-
(defn- stamps-reached?
|
|
199
|
-
"Whether the namespaces of want, {ns stamp}, run the module of that
|
|
200
|
-
compile (see cljs.compiler/emit-esm-repl-footer), or aren't loaded:
|
|
201
|
-
nothing to reload."
|
|
202
|
-
[want]
|
|
203
|
-
(every? (fn [[ns stamp]]
|
|
204
|
-
(let [entry (.get (.-nses registry) ns)]
|
|
205
|
-
(or (nil? entry) (= stamp (.-stamp entry)))))
|
|
206
|
-
want))
|
|
207
|
-
|
|
208
|
-
(defn- check-stamp-waiters! []
|
|
209
|
-
(let [[ready waiting] ((juxt filter remove) #(stamps-reached? (:want %)) @stamp-waiters)]
|
|
210
|
-
(reset! stamp-waiters (vec waiting))
|
|
211
|
-
(doseq [{:keys [reply!]} ready]
|
|
212
|
-
(reply! #js {:value "true"}))))
|
|
213
|
-
|
|
214
|
-
(defn- await-stamps
|
|
215
|
-
"Replies once the namespaces of want, {ns stamp}, run the module of that
|
|
216
|
-
compile, i.e. its hot reload applied (and the after-load hooks ran),
|
|
217
|
-
false after timeout ms."
|
|
218
|
-
[want timeout reply!]
|
|
219
|
-
(if (stamps-reached? want)
|
|
220
|
-
(reply! #js {:value "true"})
|
|
221
|
-
(let [waiter {:want want :reply! reply!}]
|
|
222
|
-
(swap! stamp-waiters conj waiter)
|
|
223
|
-
(js/setTimeout
|
|
224
|
-
(fn []
|
|
225
|
-
(when (some #(identical? waiter %) @stamp-waiters)
|
|
226
|
-
(swap! stamp-waiters (fn [ws] (vec (remove #(identical? waiter %) ws))))
|
|
227
|
-
(reply! #js {:value "false"})))
|
|
228
|
-
timeout))))
|
|
229
|
-
|
|
230
|
-
(def ^:private tag-key "cljs-esm-repl-tag")
|
|
231
|
-
|
|
232
|
-
(defn- session-storage []
|
|
233
|
-
(try
|
|
234
|
-
(.-sessionStorage js/globalThis)
|
|
235
|
-
(catch :default _ nil)))
|
|
236
|
-
|
|
237
|
-
(defn- tag []
|
|
238
|
-
(some-> (session-storage) (.getItem tag-key)))
|
|
239
|
-
|
|
240
|
-
(defn- format-warning [{:strs [message file line column]}]
|
|
241
|
-
(str "WARNING: " message (when file (str " at " file ":" line ":" column))))
|
|
242
|
-
|
|
243
|
-
(defn- console-result
|
|
244
|
-
"Settles the console evaluation id with the REPL's result (see
|
|
245
|
-
cljs.esm.repl/cljs-eval)."
|
|
246
|
-
[id {:strs [results warnings error stack] :as result}]
|
|
247
|
-
(when-let [{:keys [resolve reject value opts]} (get @console-evals id)]
|
|
248
|
-
(swap! console-evals dissoc id)
|
|
249
|
-
(doseq [w warnings]
|
|
250
|
-
(js/console.warn (format-warning w)))
|
|
251
|
-
(if error
|
|
252
|
-
(reject (doto (js/Error. error)
|
|
253
|
-
(aset "stack" (or stack error))
|
|
254
|
-
(aset "result" (clj->js result))))
|
|
255
|
-
(resolve (if (:print opts) (last results) value)))))
|
|
256
|
-
|
|
257
|
-
(defn console-eval
|
|
258
|
-
"Evaluates the ClojureScript of string code, compiled by the REPL, in this
|
|
259
|
-
runtime: returns a promise of the value of its last form, rejected with
|
|
260
|
-
an Error if a form failed or has compiler warnings (which aren't
|
|
261
|
-
evaluated). Forms are evaluated in the namespace of the console's last
|
|
262
|
-
in-ns, default cljs.user.
|
|
263
|
-
|
|
264
|
-
opts:
|
|
265
|
-
- :ns - evaluate in this namespace
|
|
266
|
-
- :await - the value of a promise
|
|
267
|
-
- :print - the printed value instead
|
|
268
|
-
- :timeout - give up waiting after these ms, default 60000"
|
|
269
|
-
[send! code opts]
|
|
270
|
-
(let [{:keys [ns timeout] :as opts} (cond-> opts (object? opts) (js->clj :keywordize-keys true))]
|
|
271
|
-
(js/Promise.
|
|
272
|
-
(fn [resolve reject]
|
|
273
|
-
(let [id (swap! console-ids inc)]
|
|
274
|
-
(swap! console-evals assoc id {:resolve resolve :reject reject :opts opts})
|
|
275
|
-
(send! #js {:op "console-eval" :rid id :code code :ns ns :await (boolean (:await opts))})
|
|
276
|
-
(js/setTimeout
|
|
277
|
-
(fn []
|
|
278
|
-
(when (contains? @console-evals id)
|
|
279
|
-
(swap! console-evals dissoc id)
|
|
280
|
-
(reject (js/Error. "No reply from the REPL, is the dev server running?"))))
|
|
281
|
-
(or timeout 60000)))))))
|
|
282
|
-
|
|
283
|
-
(defn handle!
|
|
284
|
-
"Handles message msg of the REPL, replies with send!."
|
|
285
|
-
[msg send!]
|
|
286
|
-
(let [msg (js->clj msg)
|
|
287
|
-
id (get msg "id")
|
|
288
|
-
reply! (fn [m]
|
|
289
|
-
(aset m "op" "result")
|
|
290
|
-
(aset m "id" id)
|
|
291
|
-
(send! m))]
|
|
292
|
-
(case (get msg "op")
|
|
293
|
-
"eval" (eval-js msg reply!)
|
|
294
|
-
"load" (-> (js/Promise.all (into-array (map load-ref (get msg "refs"))))
|
|
295
|
-
(.then (fn [_] (reply! #js {:value "nil"}))
|
|
296
|
-
(fn [e] (reply! (error-reply e)))))
|
|
297
|
-
"await-stamps" (await-stamps (get msg "stamps") (get msg "timeout" 10000) reply!)
|
|
298
|
-
"tag" (let [tag (get msg "tag")]
|
|
299
|
-
(when-let [storage (session-storage)]
|
|
300
|
-
(if tag
|
|
301
|
-
(.setItem storage tag-key tag)
|
|
302
|
-
(.removeItem storage tag-key)))
|
|
303
|
-
(reply! #js {:value (pr-str tag)}))
|
|
304
|
-
"console-result" (console-result (get msg "rid") (get msg "result"))
|
|
305
|
-
"welcome" nil
|
|
306
|
-
nil)))
|
|
307
|
-
|
|
308
|
-
(defn- document [] (.-document js/globalThis))
|
|
309
|
-
|
|
310
|
-
(defn- hello []
|
|
311
|
-
(let [doc (document)]
|
|
312
|
-
#js {:op "hello"
|
|
313
|
-
:url (some-> (.-location js/globalThis) .-href)
|
|
314
|
-
:title (some-> doc .-title)
|
|
315
|
-
:userAgent (some-> (.-navigator js/globalThis) .-userAgent)
|
|
316
|
-
:visible (if doc (= "visible" (.-visibilityState doc)) true)
|
|
317
|
-
:focused (boolean (and doc (.hasFocus doc)))
|
|
318
|
-
:tag (tag)
|
|
319
|
-
;; the output directory's URL, the REPL maps stack traces to the
|
|
320
|
-
;; ClojureScript sources with the source maps there
|
|
321
|
-
:root (.-href (root))}))
|
|
322
|
-
|
|
323
|
-
(defn connect-vite!
|
|
324
|
-
"Connects to the REPL through Vite's hot module reloading websocket, hot
|
|
325
|
-
is import.meta.hot. Says hello again when the websocket reconnects,
|
|
326
|
-
reports focus and visibility changes, which pick the runtime evaluating
|
|
327
|
-
forms by default. Defines cljs_eval(code, opts), console-eval for the
|
|
328
|
-
browser's console: cljs_eval(\"(+ 1 2)\"), cljs_eval(\"(foo)\", {ns:
|
|
329
|
-
\"my.app\", await: true})."
|
|
330
|
-
[^js hot]
|
|
331
|
-
(let [send! (fn [m] (.send hot "cljs:repl" m))
|
|
332
|
-
state (fn [focused]
|
|
333
|
-
#js {:op "focus"
|
|
334
|
-
:visible (= "visible" (.-visibilityState (document)))
|
|
335
|
-
:focused focused
|
|
336
|
-
:title (.-title (document))})]
|
|
337
|
-
(set! (.-connected registry) true)
|
|
338
|
-
(set! (.-cljs_eval js/globalThis)
|
|
339
|
-
(fn [code opts]
|
|
340
|
-
(console-eval send! code opts)))
|
|
341
|
-
(.on hot "cljs:repl" #(handle! % send!))
|
|
342
|
-
(.on hot "vite:ws:connect" #(send! (hello)))
|
|
343
|
-
;; hot reloads re-register modules, after-load hooks have run
|
|
344
|
-
(.on hot "vite:afterUpdate" #(check-stamp-waiters!))
|
|
345
|
-
(set! (.-registered registry) (fn [_] (js/setTimeout check-stamp-waiters! 0)))
|
|
346
|
-
(when (document)
|
|
347
|
-
(.addEventListener js/globalThis "focus" #(send! (state true)))
|
|
348
|
-
(.addEventListener (document) "visibilitychange" #(send! (state (.hasFocus (document))))))
|
|
349
|
-
(send! (hello))))
|
|
350
|
-
|
|
351
|
-
(when-let [hot (js* "import.meta.hot")]
|
|
352
|
-
(when-not (.-connected registry)
|
|
353
|
-
(connect-vite! hot)))
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Rich Hickey. All rights reserved.
|
|
3
|
-
* The use and distribution terms for this software are covered by the
|
|
4
|
-
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
|
5
|
-
* which can be found in the file epl-v10.html at the root of this distribution.
|
|
6
|
-
* By using this software in any fashion, you are agreeing to be bound by
|
|
7
|
-
* the terms of this license.
|
|
8
|
-
* You must not remove this notice, or any other, from this software.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
Math.imul = function(a, b) {};
|
|
12
|
-
|
|
13
|
-
Object.prototype.done;
|
|
14
|
-
Object.prototype.value;
|
|
15
|
-
Object.prototype.next = function() {};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @constructor;
|
|
19
|
-
*/
|
|
20
|
-
function IEquiv() {};
|
|
21
|
-
IEquiv.prototype.equiv = function() {};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @constructor
|
|
25
|
-
*/
|
|
26
|
-
function Java() {};
|
|
27
|
-
Java.prototype.type = function() {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
if(typeof Math.imul == "undefined" || (Math.imul(0xffffffff,5) == 0)) {
|
|
2
|
-
Math.imul = function (a, b) {
|
|
3
|
-
var ah = (a >>> 16) & 0xffff;
|
|
4
|
-
var al = a & 0xffff;
|
|
5
|
-
var bh = (b >>> 16) & 0xffff;
|
|
6
|
-
var bl = b & 0xffff;
|
|
7
|
-
// the shift by 0 fixes the sign on the high part
|
|
8
|
-
// the final |0 converts the unsigned value into a signed value
|
|
9
|
-
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
; Copyright (c) Rich Hickey. All rights reserved.
|
|
2
|
-
; The use and distribution terms for this software are covered by the
|
|
3
|
-
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
|
4
|
-
; which can be found in the file epl-v10.html at the root of this distribution.
|
|
5
|
-
; By using this software in any fashion, you are agreeing to be bound by
|
|
6
|
-
; the terms of this license.
|
|
7
|
-
; You must not remove this notice, or any other, from this software.
|
|
8
|
-
|
|
9
|
-
(ns cljs.js
|
|
10
|
-
(:require [cljs.env :as env]
|
|
11
|
-
[cljs.env.macros :as menv]
|
|
12
|
-
[cljs.analyzer :as ana]
|
|
13
|
-
[clojure.java.io :as io]))
|
|
14
|
-
|
|
15
|
-
(defmacro with-state
|
|
16
|
-
[state & body]
|
|
17
|
-
`(menv/with-compiler-env ~state
|
|
18
|
-
~@body))
|
|
19
|
-
|
|
20
|
-
(defmacro dump-core []
|
|
21
|
-
(let [state @env/*compiler*]
|
|
22
|
-
(if-not (false? (get-in state [:options :dump-core]))
|
|
23
|
-
`(quote ~(get-in state [::ana/namespaces 'cljs.core]))
|
|
24
|
-
`(hash-map))))
|