Skip to content

Commit 5cc8f04

Browse files
ndrluisdnolen
authored andcommitted
CLJS-1294: Let macroexpand(-1) accept any quoted argument.
Fixed by Julien Eluard
1 parent e024283 commit 5cc8f04

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/clojure/cljs/core.cljc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,7 +2763,9 @@
27632763
(core/assert (core/= (core/first quoted) 'quote)
27642764
"Argument to macroexpand-1 must be quoted")
27652765
(core/let [form (second quoted)]
2766-
`(quote ~(ana/macroexpand-1 &env form))))
2766+
(if (seq? form)
2767+
`(quote ~(ana/macroexpand-1 &env form))
2768+
form)))
27672769

27682770
(core/defmacro macroexpand
27692771
"Repeatedly calls macroexpand-1 on form until it no longer
@@ -2774,10 +2776,12 @@
27742776
"Argument to macroexpand must be quoted")
27752777
(core/let [form (second quoted)
27762778
env &env]
2777-
(core/loop [form form form' (ana/macroexpand-1 env form)]
2778-
(core/if-not (core/identical? form form')
2779-
(recur form' (ana/macroexpand-1 env form'))
2780-
`(quote ~form')))))
2779+
(if (seq? form)
2780+
(core/loop [form form form' (ana/macroexpand-1 env form)]
2781+
(core/if-not (core/identical? form form')
2782+
(recur form' (ana/macroexpand-1 env form'))
2783+
`(quote ~form')))
2784+
form)))
27812785

27822786
(core/defn- multi-arity-fn? [fdecl]
27832787
(core/< 1 (count fdecl)))

src/test/cljs/cljs/macro_test.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313

1414
(deftest test-macros
1515
(is (= (== 1 1) 2)))
16+
17+
(deftest macroexpansion
18+
(is (= 1 (macroexpand-1 '1)))
19+
(is (= '(if true (do 1)) (macroexpand-1 '(when true 1))))
20+
(is (= 1 (macroexpand '1)))
21+
(is (= '(if true (do 1)) (macroexpand '(when true 1)))))

0 commit comments

Comments
 (0)