(defn emit-comment
"Emit a nicely formatted comment string."
([doc jsdoc]
(emit-comment nil doc jsdoc))
([env doc jsdoc]
(let [docs (when doc [doc])
docs (if jsdoc (concat docs jsdoc) docs)
docs (remove nil? docs)]
(letfn [(print-comment-lines [e]
(let [[x & ys]
(map #(if (checking-types?) (munge-param-return env %) %)
(string/split-lines e))]
(emitln " * " (string/replace x "*/" "* /"))
(doseq [next-line ys]
(emitln " * "
(-> next-line
(string/replace #"^ " "")
(string/replace "*/" "* /"))))))]
(when (seq docs)
(emitln "/**")
(doseq [e docs]
(when e
(print-comment-lines e)))
(emitln " */"))))))