Skip to content

Commit 6c5fb67

Browse files
anmonteirodnolen
authored andcommitted
CLJS-1943: Self-host: cljs.pprint's macros can't be compiled
1 parent 7326d79 commit 6c5fb67

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/main/cljs/cljs/pprint.clj renamed to src/main/cljs/cljs/pprint.cljc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
;; You must not remove this notice, or any other, from this software.
88

99
(ns cljs.pprint
10-
(:refer-clojure :exclude [deftype])
11-
(:require [clojure.walk :as walk]))
10+
(:refer-clojure :exclude [deftype #?(:cljs macroexpand)])
11+
(:require [clojure.walk :as walk]
12+
#?(:cljs [cljs.analyzer :as ana])))
1213

1314

1415
;; required the following changes:
@@ -78,10 +79,19 @@
7879
(cljs.pprint/end-block cljs.core/*out*))))
7980
nil)))
8081

81-
(defn- pll-mod-body [var-sym body]
82+
#?(:cljs
83+
(defn macroexpand [env form]
84+
(loop [form form
85+
form' (ana/macroexpand-1 env form)]
86+
(if-not (identical? form form')
87+
(recur form' (ana/macroexpand-1 env form'))
88+
form'))))
89+
90+
(defn- pll-mod-body [env var-sym body]
8291
(letfn [(inner [form]
8392
(if (seq? form)
84-
(let [form (macroexpand form)]
93+
(let [form #?(:clj (macroexpand form)
94+
:cljs (macroexpand env form))]
8595
(condp = (first form)
8696
'loop* form
8797
'recur (concat `(recur (inc ~var-sym)) (rest form))
@@ -94,7 +104,7 @@
94104
for use in pretty-printer dispatch functions."
95105
[bindings & body]
96106
(let [count-var (gensym "length-count")
97-
mod-body (pll-mod-body count-var body)]
107+
mod-body (pll-mod-body &env count-var body)]
98108
`(loop ~(apply vector count-var 0 bindings)
99109
(if (or (not cljs.core/*print-length*) (< ~count-var cljs.core/*print-length*))
100110
(do ~@mod-body)
@@ -154,4 +164,4 @@ format-in can be either a control string or a previously compiled format."
154164
"A convenience macro that pretty prints the last thing output. This is
155165
exactly equivalent to (pprint *1)."
156166
{:added "1.2"}
157-
[] `(cljs.pprint/pprint *1))
167+
[] `(cljs.pprint/pprint *1))

src/test/cljs/cljs/pprint_test.clj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
;; You must not remove this notice, or any other, from this software.
88

99
(ns cljs.pprint-test
10-
(:require [cljs.test :refer [deftest is]]))
10+
(:require cljs.test))
1111

1212
(defmacro simple-tests [name & test-pairs]
13-
`(deftest ~name
13+
`(cljs.test/deftest ~name
1414
~@(for [[x y] (partition 2 test-pairs)]
1515
`(cond
16-
(cljs.core/regexp? ~y) (is (.exec ~y ~x))
17-
(cljs.core/string? ~y) (is (= ~x ~y))
18-
:else (is (= ~x ~y))))))
16+
(cljs.core/regexp? ~y) (cljs.test/is (.exec ~y ~x))
17+
(cljs.core/string? ~y) (cljs.test/is (= ~x ~y))
18+
:else (cljs.test/is (= ~x ~y))))))
1919

2020
(defmacro code-block
2121
"Read a string then print it with code-dispatch and succeed if it comes out the same"
@@ -28,4 +28,3 @@
2828
(cljs.pprint/with-pprint-dispatch cljs.pprint/code-dispatch
2929
(cljs.pprint/pprint (cljs.reader/read-string ~block)))))
3030
(clojure.string/split-lines ~block)]))))
31-

src/test/self/self_parity/test.cljs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,13 @@
170170
technical issues)."
171171
[name macros]
172172
((if macros
173-
#{'cljs.core
174-
'cljs.pprint}
173+
#{'cljs.core}
175174
#{'goog.object
176175
'goog.string
177176
'goog.string.StringBuffer
178177
'goog.array
179178
'cljs.core
180179
'cljs.env
181-
'cljs.pprint
182180
'cljs.tools.reader
183181
'clojure.walk}) name))
184182

@@ -288,8 +286,8 @@
288286
#_[cljs.keyword-test]
289287
[cljs.import-test]
290288
[cljs.ns-test.foo]
291-
#_[cljs.pprint]
292-
#_[cljs.pprint-test]
289+
[cljs.pprint]
290+
[cljs.pprint-test]
293291
[cljs.spec-test]
294292
#_[cljs.spec.test-test]
295293
[cljs.clojure-alias-test]
@@ -325,8 +323,8 @@
325323
'cljs.ns-test.foo
326324
'foo.ns-shadow-test
327325
'cljs.import-test
328-
#_'cljs.pprint
329-
#_'cljs.pprint-test
326+
'cljs.pprint
327+
'cljs.pprint-test
330328
'cljs.spec-test
331329
#_'cljs.spec.test-test
332330
'cljs.clojure-alias-test

0 commit comments

Comments
 (0)