Skip to content

Commit ffacd23

Browse files
authored
Remove pr-opts calls, backwards compatibility tweaks (#257)
* remove calls to pr-opts - just use dynamic binding - keep it backwards compatible * add long missing infer-tag case for :try
1 parent e34ba40 commit ffacd23

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,31 @@
267267
"Returns true if x is not nil, false otherwise."
268268
[x] (not (nil? x)))
269269

270+
(defn- pr-opts-fnl [opts]
271+
(if-not (nil? opts)
272+
(:flush-on-newline opts)
273+
*flush-on-newline*))
274+
275+
(defn- pr-opts-readably [opts]
276+
(if-not (nil? opts)
277+
(:readably opts)
278+
*print-readably*))
279+
280+
(defn- pr-opts-meta [opts]
281+
(if-not (nil? opts)
282+
(:meta opts)
283+
*print-meta*))
284+
285+
(defn- pr-opts-dup [opts]
286+
(if-not (nil? opts)
287+
(:dup opts)
288+
*print-dup*))
289+
290+
(defn- pr-opts-len [opts]
291+
(if-not (nil? opts)
292+
(:print-length opts)
293+
*print-length*))
294+
270295
(defn object?
271296
"Returns true if x's constructor is Object"
272297
[x]
@@ -907,7 +932,7 @@
907932
[^not-native obj]
908933
(let [sb (StringBuffer.)
909934
writer (StringBufferWriter. sb)]
910-
(-pr-writer obj writer (pr-opts))
935+
(-pr-writer obj writer nil)
911936
(-flush writer)
912937
(.toString sb)))
913938

@@ -10441,13 +10466,13 @@ reduces them without incurring seq initialization"
1044110466
(-write writer "#")
1044210467
(do
1044310468
(-write writer begin)
10444-
(if (zero? (:print-length opts))
10469+
(if (zero? (pr-opts-len opts))
1044510470
(when (seq coll)
1044610471
(-write writer (or (:more-marker opts) "...")))
1044710472
(do
1044810473
(when (seq coll)
1044910474
(print-one (first coll) writer opts))
10450-
(loop [coll (next coll) n (dec (:print-length opts))]
10475+
(loop [coll (next coll) n (dec (pr-opts-len opts))]
1045110476
(if (and coll (or (nil? n) (not (zero? n))))
1045210477
(do
1045310478
(-write writer sep)
@@ -10491,7 +10516,7 @@ reduces them without incurring seq initialization"
1049110516
(declare print-map)
1049210517

1049310518
(defn print-meta? [opts obj]
10494-
(and (boolean (get opts :meta))
10519+
(and (boolean (pr-opts-meta opts))
1049510520
(implements? IMeta obj)
1049610521
(not (nil? (meta obj)))))
1049710522

@@ -10544,7 +10569,7 @@ reduces them without incurring seq initialization"
1054410569
(pr-sequential-writer writer pr-writer "#js [" " " "]" opts obj)
1054510570

1054610571
(string? obj)
10547-
(if (:readably opts)
10572+
(if (pr-opts-readably opts)
1054810573
(-write writer (quote-string obj))
1054910574
(-write writer obj))
1055010575

@@ -10643,57 +10668,61 @@ reduces them without incurring seq initialization"
1064310668
([] (newline nil))
1064410669
([opts]
1064510670
(string-print "\n")
10646-
(when (get opts :flush-on-newline)
10671+
(when (pr-opts-fnl opts)
1064710672
(flush))))
1064810673

1064910674
(defn pr-str
1065010675
"pr to a string, returning it. Fundamental entrypoint to IPrintWithWriter."
1065110676
[& objs]
10652-
(pr-str-with-opts objs (pr-opts)))
10677+
(pr-str-with-opts objs nil))
1065310678

1065410679
(defn prn-str
1065510680
"Same as pr-str followed by (newline)"
1065610681
[& objs]
10657-
(prn-str-with-opts objs (pr-opts)))
10682+
(prn-str-with-opts objs nil))
1065810683

1065910684
(defn pr
1066010685
"Prints the object(s) using string-print. Prints the
1066110686
object(s), separated by spaces if there is more than one.
1066210687
By default, pr and prn print in a way that objects can be
1066310688
read by the reader"
1066410689
[& objs]
10665-
(pr-with-opts objs (pr-opts)))
10690+
(pr-with-opts objs nil))
1066610691

1066710692
(def ^{:doc
1066810693
"Prints the object(s) using string-print.
1066910694
print and println produce output for human consumption."}
1067010695
print
1067110696
(fn cljs-core-print [& objs]
10672-
(pr-with-opts objs (assoc (pr-opts) :readably false))))
10697+
(binding [*print-readably* false]
10698+
(pr-with-opts objs nil))))
1067310699

1067410700
(defn print-str
1067510701
"print to a string, returning it"
1067610702
[& objs]
10677-
(pr-str-with-opts objs (assoc (pr-opts) :readably false)))
10703+
(binding [*print-readably* false]
10704+
(pr-str-with-opts objs nil)))
1067810705

1067910706
(defn println
1068010707
"Same as print followed by (newline)"
1068110708
[& objs]
10682-
(pr-with-opts objs (assoc (pr-opts) :readably false))
10709+
(binding [*print-readably* false]
10710+
(pr-with-opts objs nil))
1068310711
(when *print-newline*
10684-
(newline (pr-opts))))
10712+
(newline nil)))
1068510713

1068610714
(defn println-str
1068710715
"println to a string, returning it"
1068810716
[& objs]
10689-
(prn-str-with-opts objs (assoc (pr-opts) :readably false)))
10717+
(binding [*print-readably* false]
10718+
(prn-str-with-opts objs nil)))
1069010719

1069110720
(defn prn
1069210721
"Same as pr followed by (newline)."
1069310722
[& objs]
10694-
(pr-with-opts objs (pr-opts))
10723+
(pr-with-opts objs nil)
1069510724
(when *print-newline*
10696-
(newline (pr-opts))))
10725+
(newline nil)))
1069710726

1069810727
(defn- strip-ns
1069910728
[named]

src/main/clojure/cljs/analyzer.cljc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@
15681568
:throw impl/IGNORE_SYM
15691569
:let (infer-tag env (:body ast))
15701570
:loop (infer-tag env (:body ast))
1571+
:try (infer-tag env (:body ast))
15711572
:do (infer-tag env (:ret ast))
15721573
:fn-method (infer-tag env (:body ast))
15731574
:def (infer-tag env (:init ast))

0 commit comments

Comments
 (0)