Skip to content

Commit 5800cfb

Browse files
committed
emit defs w/o :init, tweak js-comment, no extra newline
1 parent 8226cd2 commit 5800cfb

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

src/main/clojure/cljs/compiler.cljc

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -527,36 +527,36 @@
527527
(defmethod emit* :def
528528
[{:keys [name var init env doc jsdoc export test var-ast]}]
529529
(let [mname (munge name)]
530+
(emit-comment doc (concat jsdoc (:jsdoc init)))
531+
(when (:def-emits-var env)
532+
(when (= :return (:context env))
533+
(emitln "return ("))
534+
(emitln "(function (){"))
535+
(emits var)
530536
(when init
531-
(emit-comment doc (concat jsdoc (:jsdoc init)))
532-
(when (:def-emits-var env)
533-
(when (= :return (:context env))
534-
(emitln "return ("))
535-
(emitln "(function (){"))
536-
(emits var)
537537
(emits " = "
538-
(if-let [define (get-define mname jsdoc)]
539-
define
540-
init))
541-
(when (:def-emits-var env)
542-
(emitln "; return (")
543-
(emits (merge
544-
{:op :var-special
545-
:env (assoc env :context :expr)}
546-
var-ast))
547-
(emitln ");})()")
548-
(when (= :return (:context env))
549-
(emitln ")")))
550-
;; NOTE: JavaScriptCore does not like this under advanced compilation
551-
;; this change was primarily for REPL interactions - David
552-
;(emits " = (typeof " mname " != 'undefined') ? " mname " : undefined")
553-
(when-not (= :expr (:context env)) (emitln ";"))
554-
(when export
555-
(emitln "goog.exportSymbol('" (munge export) "', " mname ");"))
556-
(when (and ana/*load-tests* test)
557-
(when (= :expr (:context env))
558-
(emitln ";"))
559-
(emitln var ".cljs$lang$test = " test ";")))))
538+
(if-let [define (get-define mname jsdoc)]
539+
define
540+
init)))
541+
(when (:def-emits-var env)
542+
(emitln "; return (")
543+
(emits (merge
544+
{:op :var-special
545+
:env (assoc env :context :expr)}
546+
var-ast))
547+
(emitln ");})()")
548+
(when (= :return (:context env))
549+
(emitln ")")))
550+
;; NOTE: JavaScriptCore does not like this under advanced compilation
551+
;; this change was primarily for REPL interactions - David
552+
;(emits " = (typeof " mname " != 'undefined') ? " mname " : undefined")
553+
(when-not (= :expr (:context env)) (emitln ";"))
554+
(when export
555+
(emitln "goog.exportSymbol('" (munge export) "', " mname ");"))
556+
(when (and ana/*load-tests* test)
557+
(when (= :expr (:context env))
558+
(emitln ";"))
559+
(emitln var ".cljs$lang$test = " test ";"))))
560560

561561
(defn emit-apply-to
562562
[{:keys [name params env]}]

src/main/clojure/cljs/core.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@
867867

868868
(core/defmacro js-comment
869869
"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."
870+
new comment line. Comment block will be preceded by a newline."
871871
[comment]
872872
(core/let [[x & ys] (string/split comment #"\n")]
873873
(core/list 'js*
@@ -877,7 +877,7 @@
877877
(core/->> ys
878878
(map #(core/str " * " (string/replace % #"^ " "") "\n"))
879879
(reduce core/str ""))
880-
" */\n"))))
880+
" */"))))
881881

882882
(core/defmacro js-inline-comment
883883
"Emit an inline JavaScript comment."

0 commit comments

Comments
 (0)