Skip to content

Commit 8226cd2

Browse files
committed
make comment handling less brittle, add js-inline-comment
1 parent 0ca217d commit 8226cd2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/main/clojure/cljs/compiler.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,8 +1025,8 @@
10251025

10261026
(defmethod emit* :js
10271027
[{:keys [op env code segs args]}]
1028-
(if (and code #?(:clj (.startsWith ^String code "/*")
1029-
:cljs (gstring/startsWith code "/*")))
1028+
(if (and code #?(:clj (.startsWith ^String (string/trim code) "/*")
1029+
:cljs (gstring/startsWith (string/trim code) "/*")))
10301030
(emits code)
10311031
(emit-wrap env
10321032
(if code

src/main/clojure/cljs/core.cljc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
unsafe-bit-and bit-shift-right-zero-fill mask bitpos caching-hash
4141
defcurried rfn specify! js-this this-as implements? array js-obj
4242
simple-benchmark gen-apply-to js-str es6-iterable load-file* undefined?
43-
specify copy-arguments goog-define js-comment])])
43+
specify copy-arguments goog-define js-comment js-inline-comment])])
4444
#?(:cljs (:require-macros [cljs.core :as core]))
4545
(:require clojure.walk
4646
clojure.set
@@ -866,8 +866,8 @@
866866
(core/list 'js* "debugger;"))
867867

868868
(core/defmacro js-comment
869-
"Emit top-level JavaScript multi-line comment. New lines will create a
870-
new comment line."
869+
"Emit a top-level JavaScript multi-line comment. New lines will create a
870+
new comment line. Comment block will be preceded and followed by a newline."
871871
[comment]
872872
(core/let [[x & ys] (string/split comment #"\n")]
873873
(core/list 'js*
@@ -879,6 +879,11 @@
879879
(reduce core/str ""))
880880
" */\n"))))
881881

882+
(core/defmacro js-inline-comment
883+
"Emit an inline JavaScript comment."
884+
[comment]
885+
(core/list 'js* (core/str "/**" comment "*/")))
886+
882887
(core/defmacro true? [x]
883888
(bool-expr (core/list 'js* "~{} === true" x)))
884889

0 commit comments

Comments
 (0)