Skip to content

Commit 7972430

Browse files
committed
include original JS docstring when parsing externs
1 parent 13fde33 commit 7972430

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/main/clojure/cljs/externs.clj

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
(:import [java.util.logging Level]
1515
[com.google.javascript.jscomp
1616
CompilerOptions SourceFile JsAst CommandLineRunner]
17+
[com.google.javascript.jscomp.parsing Config$JsDocParsing]
1718
[com.google.javascript.rhino
1819
Node Token JSTypeExpression]))
1920

@@ -38,16 +39,19 @@
3839
(when node
3940
(let [info (.getJSDocInfo node)]
4041
(when info
41-
(if-let [^JSTypeExpression ty (.getType info)]
42-
{:tag (get-type* ty)}
43-
(if (or (.isConstructor info) (.isInterface info))
44-
(let [qname (symbol (.. node getFirstChild getQualifiedName))]
45-
(cond-> {:tag 'Function}
46-
(.isConstructor info) (merge {:ctor qname})
47-
(.isInterface info) (merge {:iface qname})))
48-
(if (.hasReturnType info)
49-
{:tag 'Function
50-
:ret-tag (get-type* (.getReturnType info))})))))))
42+
(merge
43+
(if-let [^JSTypeExpression ty (.getType info)]
44+
{:tag (get-type* ty)}
45+
(if (or (.isConstructor info) (.isInterface info))
46+
(let [qname (symbol (.. node getFirstChild getQualifiedName))]
47+
(cond-> {:tag 'Function}
48+
(.isConstructor info) (merge {:ctor qname})
49+
(.isInterface info) (merge {:iface qname})))
50+
(if (.hasReturnType info)
51+
{:tag 'Function
52+
:ret-tag (get-type* (.getReturnType info))})))
53+
(when-let [doc (.getOriginalCommentString info)]
54+
{:doc doc}))))))
5155

5256
(defmulti parse-extern-node
5357
(fn [^Node node]
@@ -108,7 +112,10 @@
108112
(defmethod parse-extern-node :default [node])
109113

110114
(defn parse-externs [^SourceFile source-file]
111-
(let [^CompilerOptions compiler-options (CompilerOptions.)
115+
(let [^CompilerOptions compiler-options
116+
(doto (CompilerOptions.)
117+
(.setParseJsDocDocumentation
118+
Config$JsDocParsing/INCLUDE_DESCRIPTIONS_WITH_WHITESPACE))
112119
closure-compiler
113120
(doto
114121
(let [compiler (com.google.javascript.jscomp.Compiler.)]

0 commit comments

Comments
 (0)