|
13 | 13 | [clojure.string :as string]) |
14 | 14 | (:import [com.google.javascript.jscomp |
15 | 15 | CompilerOptions CompilerOptions$Environment SourceFile CompilerInput CommandLineRunner] |
16 | | - [com.google.javascript.jscomp.parsing Config$JsDocParsing] |
| 16 | + [com.google.javascript.jscomp.parsing Config$JsDocParsing JsDocInfoParser$ExtendedTypeInfo] |
17 | 17 | [com.google.javascript.rhino |
18 | | - Node Token JSTypeExpression JSDocInfo$Visibility] |
| 18 | + Node Token JSTypeExpression JSDocInfo JSDocInfo$Visibility] |
19 | 19 | [java.util.logging Level] |
20 | 20 | [java.net URL])) |
21 | 21 |
|
|
88 | 88 | (some-> (.getRoot texpr) parse-texpr simplify-texpr)) |
89 | 89 |
|
90 | 90 | (defn params->method-params [xs] |
91 | | - (letfn [(not-opt? [x] |
92 | | - (not (string/starts-with? (name x) "opt_")))] |
93 | | - (let [required (into [] (take-while not-opt? xs)) |
94 | | - opts (drop-while not-opt? xs)] |
95 | | - (loop [ret [required] opts opts] |
96 | | - (if-let [opt (first opts)] |
97 | | - (recur (conj ret (conj (last ret) opt)) (drop 1 opts)) |
98 | | - (seq ret)))))) |
| 91 | + (let [not-opt? (complement :optional?) |
| 92 | + required (into [] (map :name (take-while not-opt? xs))) |
| 93 | + opts (map :name (drop-while not-opt? xs))] |
| 94 | + (loop [ret [required] opts opts] |
| 95 | + (if-let [opt (first opts)] |
| 96 | + (recur (conj ret (conj (last ret) opt)) (drop 1 opts)) |
| 97 | + (seq ret))))) |
99 | 98 |
|
100 | 99 | (defn generic? [t] |
101 | 100 | (let [s (name t)] |
|
108 | 107 | (= t 'Array) 'array |
109 | 108 | :else t))) |
110 | 109 |
|
| 110 | +(defn get-params |
| 111 | + "Return param information in JSDoc appearance order. GCL is relatively |
| 112 | + civilized, so this isn't really a problem." |
| 113 | + [^JSDocInfo info] |
| 114 | + (map |
| 115 | + (fn [n] |
| 116 | + (let [t (.getParameterType info n)] |
| 117 | + {:name (symbol n) |
| 118 | + :optional? (.isOptionalArg t) |
| 119 | + :var-args? (.isVarArgs t)})) |
| 120 | + (.getParameterNames info))) |
| 121 | + |
111 | 122 | (defn get-var-info [^Node node] |
112 | 123 | (when node |
113 | 124 | (let [info (.getJSDocInfo node)] |
|
124 | 135 | (if (or (.hasReturnType info) |
125 | 136 | (as-> (.getParameterCount info) c |
126 | 137 | (and c (pos? c)))) |
127 | | - (let [arglist (into [] (map symbol (.getParameterNames info))) |
| 138 | + (let [arglist (get-params info) |
128 | 139 | arglists (params->method-params arglist)] |
129 | 140 | {:tag 'Function |
130 | 141 | :js-fn-var true |
131 | 142 | :ret-tag (or (some-> (.getReturnType info) |
132 | 143 | get-tag gtype->cljs-type) |
133 | 144 | 'clj-nil) |
134 | | - :variadic? (boolean (some '#{var_args} arglist)) |
135 | | - :max-fixed-arity (count (take-while #(not= 'var_args %) arglist)) |
| 145 | + :variadic? (boolean (some :var-args? arglist)) |
| 146 | + :max-fixed-arity (count (take-while (complement :var-args?) arglist)) |
136 | 147 | :method-params arglists |
137 | 148 | :arglists arglists})))) |
138 | 149 | {:file *source-file* |
|
0 commit comments