Skip to content

Commit d3f1e55

Browse files
author
dnolen
committed
give Google Closure enough information so that type checking can work
sensibly without extra noise
1 parent 42dc1f5 commit d3f1e55

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828

2929
(def
3030
^{:dynamic true
31-
:doc "Var bound to the current namespace. Only used for bootstrapping."}
31+
:doc "Var bound to the current namespace. Only used for bootstrapping."
32+
:jsdoc ["@type {*}"]}
3233
*ns* nil)
3334

3435
(def
35-
^{:dynamic true}
36+
^{:dynamic true
37+
:jsdoc ["@type {*}"]}
3638
*out* nil)
3739

3840
(def
@@ -106,7 +108,8 @@
106108
:doc "When set to logical true, objects will be printed in a way that preserves
107109
their type when read in later.
108110
109-
Defaults to false."}
111+
Defaults to false."
112+
:jsdoc ["@type {null|number}"]}
110113
*print-length* nil)
111114

112115
(def
@@ -118,10 +121,14 @@
118121
collection, its items are at level 1; and so on. If an object is a
119122
collection and is at a level greater than or equal to the value bound to
120123
*print-level*, the printer prints '#' to represent it. The root binding
121-
is nil indicating no limit."}
124+
is nil indicating no limit."
125+
:jsdoc ["@type {null|number}"]}
122126
*print-level* nil)
123127

124-
(defonce ^:dynamic *loaded-libs* nil)
128+
(defonce
129+
^{:dynamic true
130+
:jsdoc ["@type {*}"]}
131+
*loaded-libs* nil)
125132

126133
(defn- pr-opts []
127134
{:flush-on-newline *flush-on-newline*
@@ -9143,7 +9150,9 @@ reduces them without incurring seq initialization"
91439150

91449151
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; gensym ;;;;;;;;;;;;;;;;
91459152
;; Internal - do not use!
9146-
(def gensym_counter nil)
9153+
(def
9154+
^{:jsdoc ["@type {*}"]}
9155+
gensym_counter nil)
91479156

91489157
(defn gensym
91499158
"Returns a new symbol with a unique name. If a prefix string is
@@ -9403,7 +9412,10 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
94039412
"Creates a hierarchy object for use with derive, isa? etc."
94049413
[] {:parents {} :descendants {} :ancestors {}})
94059414

9406-
(def ^:private -global-hierarchy nil)
9415+
(def
9416+
^{:private true
9417+
:jsdoc ["@type {*}"]}
9418+
-global-hierarchy nil)
94079419

94089420
(defn- get-global-hierarchy []
94099421
(when (nil? -global-hierarchy)
@@ -9984,7 +9996,10 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
99849996
{:pre [(symbol? tag)]}
99859997
(TaggedLiteral. tag form))
99869998

9987-
(def ^:private js-reserved-arr
9999+
(def
10000+
^{:private true
10001+
:jsdoc ["@type {*}"]}
10002+
js-reserved-arr
998810003
#js ["abstract" "boolean" "break" "byte" "case"
998910004
"catch" "char" "class" "const" "continue"
999010005
"debugger" "default" "delete" "do" "double"
@@ -9999,7 +10014,9 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
999910014
"volatile" "while" "with" "yield" "methods"
1000010015
"null"])
1000110016

10002-
(def js-reserved nil)
10017+
(def
10018+
^{:jsdoc ["@type {*}"]}
10019+
js-reserved nil)
1000310020

1000410021
(defn- js-reserved? [x]
1000510022
(when (nil? js-reserved)
@@ -10093,7 +10110,9 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
1009310110
(-hash [_]
1009410111
(hash name)))
1009510112

10096-
(def NS_CACHE nil)
10113+
(def
10114+
^{:jsdoc ["@type {*}"]}
10115+
NS_CACHE nil)
1009710116

1009810117
(defn- find-ns-obj* [ctxt xs]
1009910118
(cond

src/main/cljs/cljs/externs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Math.imul = function(a, b) {};
22

3+
Object.prototype.done;
4+
Object.prototype.value;
5+
Object.prototype.next = function() {};
6+
37
/**
48
* @constructor;
59
*/

src/main/clojure/cljs/core.cljc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@
26832683
:arglists-meta (doall (map meta [arglist]))})]
26842684
`(do
26852685
(def ~(with-meta name meta)
2686-
(fn []
2686+
(fn [~'var_args]
26872687
(let [args# (array)]
26882688
(copy-arguments args#)
26892689
(let [argseq# (when (< ~c-1 (alength args#))
@@ -2738,7 +2738,7 @@
27382738
args-sym (gensym "args")]
27392739
`(do
27402740
(def ~(with-meta name meta)
2741-
(fn []
2741+
(fn [~'var_args]
27422742
(let [~args-sym (array)]
27432743
(copy-arguments ~args-sym)
27442744
(case (alength ~args-sym)
@@ -2821,16 +2821,18 @@
28212821
m (conj (if (meta name) (meta name) {}) m)]
28222822
(core/cond
28232823
(multi-arity-fn? fdecl)
2824-
(multi-arity-fn name m fdecl)
2824+
(multi-arity-fn name
2825+
(update-in m [:jsdoc] conj "@param {...*} var_args") fdecl)
28252826

28262827
(variadic-fn? fdecl)
2827-
(variadic-fn name m fdecl)
2828+
(variadic-fn name
2829+
(update-in m [:jsdoc] conj "@param {...*} var_args") fdecl)
28282830

28292831
:else
28302832
(core/list 'def (with-meta name m)
2831-
;;todo - restore propagation of fn name
2832-
;;must figure out how to convey primitive hints to self calls first
2833-
(cons `fn fdecl))))))
2833+
;;todo - restore propagation of fn name
2834+
;;must figure out how to convey primitive hints to self calls first
2835+
(cons `fn fdecl))))))
28342836

28352837
#?(:clj (. (var defn) (setMacro))
28362838
:cljs (set! (. defn -cljs$lang$macro) true))

0 commit comments

Comments
 (0)