|
298 | 298 | (or (-> x meta :column) (:column env)))
|
299 | 299 |
|
300 | 300 | (defn intern-macros
|
| 301 | + "Given a Clojure namespace intern all macros into the ambient ClojureScript |
| 302 | + analysis environment." |
301 | 303 | ([ns] (intern-macros ns false))
|
302 | 304 | ([ns reload]
|
303 | 305 | (when (or (nil? (get-in @env/*compiler* [::namespaces ns :macros]))
|
|
338 | 340 | *cljs-macros-is-classpath* false]
|
339 | 341 | ~@body)))
|
340 | 342 |
|
341 |
| -(defn empty-env [] |
| 343 | +(defn empty-env |
| 344 | + "Construct an empty analysis environment. Required to analyze forms." |
| 345 | + [] |
342 | 346 | (env/ensure
|
343 | 347 | {:ns (get-namespace *cljs-ns*)
|
344 | 348 | :context :statement
|
|
427 | 431 | (let [sym (symbol name)]
|
428 | 432 | (get (:require-macros (:ns env)) sym sym)))
|
429 | 433 |
|
430 |
| -(defn confirm-ns [env ns-sym] |
| 434 | +(defn confirm-ns |
| 435 | + "Given env, an analysis environment, and ns-sym, a symbol identifying a |
| 436 | + namespace, confirm that the namespace exists. Warn if not found." |
| 437 | + [env ns-sym] |
431 | 438 | (when (and (nil? (get '#{cljs.core goog Math goog.string} ns-sym))
|
432 | 439 | (nil? (get (-> env :ns :requires) ns-sym))
|
433 | 440 | ;; something else may have loaded the namespace, i.e. load-file
|
|
512 | 519 | {:name (symbol (str full-ns) (str sym))
|
513 | 520 | :ns full-ns})))))))
|
514 | 521 |
|
515 |
| -(defn resolve-existing-var [env sym] |
| 522 | +(defn resolve-existing-var |
| 523 | + "Given env, an analysis environment, and sym, a symbol, resolve an existing var. |
| 524 | + Emits a warning if no such var exists." |
| 525 | + [env sym] |
516 | 526 | (if-not (-> sym meta ::no-resolve)
|
517 | 527 | (resolve-var env sym confirm-var-exists)
|
518 | 528 | (resolve-var env sym)))
|
519 | 529 |
|
520 |
| -(defn confirm-bindings [env names] |
| 530 | +(defn confirm-bindings |
| 531 | + "Given env, an analysis environment env, and names, a list of symbols, confirm |
| 532 | + that all correspond to declared dynamic vars." |
| 533 | + [env names] |
521 | 534 | (doseq [name names]
|
522 | 535 | (let [env (assoc env :ns (get-namespace *cljs-ns*))
|
523 | 536 | ev (resolve-existing-var env name)]
|
524 | 537 | (when (and ev (not (-> ev :dynamic)))
|
525 | 538 | (warning :dynamic env {:ev ev :name (:name ev)})))))
|
526 | 539 |
|
527 |
| -(defn resolve-macro-var [env sym] |
| 540 | +(defn resolve-macro-var |
| 541 | + "Given env, an analysis environment, and sym, a symbol, resolve a macro." |
| 542 | + [env sym] |
528 | 543 | (let [ns (-> env :ns :name)
|
529 | 544 | namespaces (get @env/*compiler* ::namespaces)]
|
530 | 545 | (cond
|
|
619 | 634 | ('#{cljs.core/PersistentHashMap
|
620 | 635 | cljs.core/List} t)))))
|
621 | 636 |
|
622 |
| -(defn infer-tag [env e] |
| 637 | +(defn infer-tag |
| 638 | + "Given env, an analysis environment, and e, an AST node, return the inferred |
| 639 | + type of the node" |
| 640 | + [env e] |
623 | 641 | (if-let [tag (get-tag e)]
|
624 | 642 | tag
|
625 | 643 | (case (:op e)
|
|
1249 | 1267 | false)))
|
1250 | 1268 |
|
1251 | 1269 | (defn analyze-deps
|
| 1270 | + "Given a lib, a namespace, deps, its dependencies, env, an analysis environment |
| 1271 | + and opts, compiler options - analyze all of the dependencies. Required to |
| 1272 | + correctly analyze usage of other namespaces." |
1252 | 1273 | ([lib deps env] (analyze-deps lib deps env nil))
|
1253 | 1274 | ([lib deps env opts]
|
1254 | 1275 | (let [compiler @env/*compiler*]
|
|
1793 | 1814 | (resolve-var env sym)))
|
1794 | 1815 | (assoc ret :op :var :info (resolve-var env sym)))))))
|
1795 | 1816 |
|
1796 |
| -(defn get-expander [sym env] |
| 1817 | +(defn get-expander |
| 1818 | + "Given a sym, a symbol identifying a macro, and env, an analysis environment |
| 1819 | + return the corresponding Clojure macroexpander." |
| 1820 | + [sym env] |
1797 | 1821 | (let [mvar
|
1798 | 1822 | (when-not (or (-> env :locals sym) ;locals hide macros
|
1799 | 1823 | (and (or (-> env :ns :excludes sym)
|
|
1814 | 1838 | (when (and mvar (.isMacro ^clojure.lang.Var mvar))
|
1815 | 1839 | (with-meta @mvar (meta mvar)))))
|
1816 | 1840 |
|
1817 |
| -(defn macroexpand-1 [env form] |
| 1841 | +(defn macroexpand-1 |
| 1842 | + "Given a env, an analysis environment, and form, a ClojureScript form, |
| 1843 | + macroexpand the form once." |
| 1844 | + [env form] |
1818 | 1845 | (env/ensure
|
1819 | 1846 | (wrapping-errors env
|
1820 | 1847 | (let [op (first form)]
|
|
2121 | 2148 | (io/file (str target-file ".cache.edn"))))))
|
2122 | 2149 |
|
2123 | 2150 | (defn requires-analysis?
|
| 2151 | + "Given a src, a resource, and output-dir, a compilation output directory |
| 2152 | + return true or false depending on whether src needs to be (re-)analyzed. |
| 2153 | + Can optionally pass cache, the analysis cache file." |
2124 | 2154 | ([src] (requires-analysis? src "out"))
|
2125 | 2155 | ([src output-dir]
|
2126 | 2156 | (let [cache (cache-file src output-dir)]
|
|
0 commit comments