Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit 4eecfbb

Browse files
committed
slightly better formatting
1 parent ae671de commit 4eecfbb

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

cherry/corpus/foo.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(log (+ 1 2 3))
77

88
(let [y (let [x (do (log "in do")
9-
12)]
10-
(log "x + 1 =" (inc x))
11-
(+ x 13))]
9+
12)]
10+
(log "x + 1 =" (inc x))
11+
(+ x 13))]
1212
(log "y =" y))

cherry/corpus/foo.mjs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
const log = console.log;
2-
;
32
log("hello");
43
log((1 + 2 + 3));
5-
(function () { const y = (function () { const x = (function () { log("in do");
6-
return 12; })();
7-
return (function () { log("x + 1 =", (x + 1));
8-
return (x + 13); })(); })();
9-
return (function () { return log("y =", y); })(); })();
4+
(function () {
5+
const y = (function () {
6+
const x = (function () {
7+
log("in do");
8+
return 12;
9+
})();
10+
return (function () {
11+
log("x + 1 =", (x + 1));
12+
return (x + 13);
13+
})();
14+
})();
15+
return (function () {
16+
return log("y =", y);
17+
})();
18+
})();

cherry/src/cherry/transpiler.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
(wrap-await (emit more)))
164164

165165
(defn wrap-iife [s & [{:keys [async?]}]]
166-
(cond-> (format "(%sfunction () { %s })()" (if async? "async " "") s)
166+
(cond-> (format "(%sfunction () {\n %s\n})()" (if async? "async " "") s)
167167
async? (wrap-await)))
168168

169169
(defn return [s]
@@ -301,7 +301,7 @@
301301
(assert (vector? sig))
302302
(let [body (return (emit-do body {:async? async?}))]
303303
(str (when-not elide-function? "function ") (comma-list sig) " {\n"
304-
(emit-var-declarations) body " }")))
304+
(emit-var-declarations) body "\n}")))
305305

306306
(defn emit-function* [expr]
307307
(let [name (when (symbol? (first expr)) (first expr))
@@ -480,9 +480,8 @@
480480
(let [next-form (e/parse-next rdr)]
481481
(if (= ::e/eof next-form)
482482
transpiled
483-
(let [next-js (js (clj next-form))]
484-
(recur (str transpiled next-js (when-not (str/blank? next-js)
485-
";\n")))))))))
483+
(let [next-js (some-> (js (clj next-form)) not-empty (statement))]
484+
(recur (str transpiled next-js))))))))
486485

487486
(defn transpile-file [{:keys [in-file out-file]}]
488487
(let [out-file (or out-file

0 commit comments

Comments
 (0)