|
65 | 65 | ([state] |
66 | 66 | (get @state :js-dependency-index))) |
67 | 67 |
|
68 | | -(defn analyze |
69 | | - "Given an environment, a map containing {:locals (mapping of names to bindings), :context |
70 | | - (one of :statement, :expr, :return), :ns (a symbol naming the |
71 | | - compilation ns)}, and form, returns an expression object (a map |
72 | | - containing at least :form, :op and :env keys). If expr has any (immediately) |
73 | | - nested exprs, must have :children [exprs...] entry. This will |
74 | | - facilitate code walking without knowing the details of the op set." |
75 | | - ([env form] (analyze env form nil)) |
76 | | - ([env form name] (analyze env form name nil)) |
77 | | - ([env form name opts] |
78 | | - (analyze |
79 | | - (if-not (nil? env/*compiler*) |
80 | | - env/*compiler* |
81 | | - (env/default-compiler-env opts)) |
82 | | - env form name opts)) |
83 | | - ([state env form name opts] |
84 | | - (env/with-compiler-env state |
85 | | - (binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)] |
86 | | - (ana/analyze env form name opts))))) |
87 | | - |
88 | | -(defn forms-seq |
89 | | - "Seq of Clojure/ClojureScript forms from rdr, a java.io.Reader. Optionally |
90 | | - accepts a filename argument which will be used in any emitted errors." |
91 | | - ([rdr] (ana/forms-seq* rdr nil)) |
92 | | - ([rdr filename] (ana/forms-seq* rdr filename))) |
93 | | - |
94 | | -(defn parse-ns |
95 | | - "Helper for parsing only the essential namespace information from a |
96 | | - ClojureScript source file and returning a cljs.closure/IJavaScript compatible |
97 | | - map _not_ a namespace AST node. |
98 | | -
|
99 | | - By default does not load macros or perform any analysis of dependencies. If |
100 | | - opts parameter provided :analyze-deps and :load-macros keys their values will |
101 | | - be used for *analyze-deps* and *load-macros* bindings respectively. This |
102 | | - function does _not_ side-effect the ambient compilation environment unless |
103 | | - requested via opts where :restore is false." |
104 | | - ([src] (parse-ns src nil nil)) |
105 | | - ([src opts] (parse-ns src nil opts)) |
106 | | - ([src dest opts] |
107 | | - (parse-ns |
108 | | - (if-not (nil? env/*compiler*) |
109 | | - env/*compiler* |
110 | | - (env/default-compiler-env opts)) |
111 | | - src dest opts)) |
112 | | - ([state src dest opts] |
113 | | - (env/with-compiler-env state |
114 | | - (binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)] |
115 | | - (ana/parse-ns src dest opts))))) |
116 | | - |
117 | | -(defn analyze-file |
118 | | - "Given a java.io.File, java.net.URL or a string identifying a resource on the |
119 | | - classpath attempt to analyze it. |
120 | | -
|
121 | | - This function side-effects the ambient compilation environment |
122 | | - `cljs.env/*compiler*` to aggregate analysis information. opts argument is |
123 | | - compiler options, if :cache-analysis true will cache analysis to |
124 | | - \":output-dir/some/ns/foo.cljs.cache.edn\". This function does not return a |
125 | | - meaningful value." |
126 | | - ([f] (analyze-file f nil)) |
127 | | - ([f opts] |
128 | | - (analyze-file |
129 | | - (if-not (nil? env/*compiler*) |
130 | | - env/*compiler* |
131 | | - (env/default-compiler-env opts)) |
132 | | - f opts)) |
133 | | - ([state f opts] |
134 | | - (env/with-compiler-env state |
135 | | - (binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)] |
136 | | - (ana/analyze-file f opts))))) |
| 68 | +#?(:clj |
| 69 | + (defn analyze |
| 70 | + "Given an environment, a map containing {:locals (mapping of names to bindings), :context |
| 71 | + (one of :statement, :expr, :return), :ns (a symbol naming the |
| 72 | + compilation ns)}, and form, returns an expression object (a map |
| 73 | + containing at least :form, :op and :env keys). If expr has any (immediately) |
| 74 | + nested exprs, must have :children [exprs...] entry. This will |
| 75 | + facilitate code walking without knowing the details of the op set." |
| 76 | + ([env form] (analyze env form nil)) |
| 77 | + ([env form name] (analyze env form name nil)) |
| 78 | + ([env form name opts] |
| 79 | + (analyze |
| 80 | + (if-not (nil? env/*compiler*) |
| 81 | + env/*compiler* |
| 82 | + (env/default-compiler-env opts)) |
| 83 | + env form name opts)) |
| 84 | + ([state env form name opts] |
| 85 | + (env/with-compiler-env state |
| 86 | + (binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)] |
| 87 | + (ana/analyze env form name opts)))))) |
| 88 | + |
| 89 | +#?(:clj |
| 90 | + (defn forms-seq |
| 91 | + "Seq of Clojure/ClojureScript forms from rdr, a java.io.Reader. Optionally |
| 92 | + accepts a filename argument which will be used in any emitted errors." |
| 93 | + ([rdr] (ana/forms-seq* rdr nil)) |
| 94 | + ([rdr filename] (ana/forms-seq* rdr filename)))) |
| 95 | + |
| 96 | +#?(:clj |
| 97 | + (defn parse-ns |
| 98 | + "Helper for parsing only the essential namespace information from a |
| 99 | + ClojureScript source file and returning a cljs.closure/IJavaScript compatible |
| 100 | + map _not_ a namespace AST node. |
| 101 | + |
| 102 | + By default does not load macros or perform any analysis of dependencies. If |
| 103 | + opts parameter provided :analyze-deps and :load-macros keys their values will |
| 104 | + be used for *analyze-deps* and *load-macros* bindings respectively. This |
| 105 | + function does _not_ side-effect the ambient compilation environment unless |
| 106 | + requested via opts where :restore is false." |
| 107 | + ([src] (parse-ns src nil nil)) |
| 108 | + ([src opts] (parse-ns src nil opts)) |
| 109 | + ([src dest opts] |
| 110 | + (parse-ns |
| 111 | + (if-not (nil? env/*compiler*) |
| 112 | + env/*compiler* |
| 113 | + (env/default-compiler-env opts)) |
| 114 | + src dest opts)) |
| 115 | + ([state src dest opts] |
| 116 | + (env/with-compiler-env state |
| 117 | + (binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)] |
| 118 | + (ana/parse-ns src dest opts)))))) |
| 119 | +#?(:clj |
| 120 | + (defn analyze-file |
| 121 | + "Given a java.io.File, java.net.URL or a string identifying a resource on the |
| 122 | + classpath attempt to analyze it. |
| 123 | + |
| 124 | + This function side-effects the ambient compilation environment |
| 125 | + `cljs.env/*compiler*` to aggregate analysis information. opts argument is |
| 126 | + compiler options, if :cache-analysis true will cache analysis to |
| 127 | + \":output-dir/some/ns/foo.cljs.cache.edn\". This function does not return a |
| 128 | + meaningful value." |
| 129 | + ([f] (analyze-file f nil)) |
| 130 | + ([f opts] |
| 131 | + (analyze-file |
| 132 | + (if-not (nil? env/*compiler*) |
| 133 | + env/*compiler* |
| 134 | + (env/default-compiler-env opts)) |
| 135 | + f opts)) |
| 136 | + ([state f opts] |
| 137 | + (env/with-compiler-env state |
| 138 | + (binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)] |
| 139 | + (ana/analyze-file f opts)))))) |
137 | 140 |
|
138 | 141 | ;; ============================================================================= |
139 | 142 | ;; Main API |
|
146 | 149 | (try |
147 | 150 | (ana/resolve-var env sym |
148 | 151 | (ana/confirm-var-exists-throw)) |
149 | | - (catch Exception e |
| 152 | + (catch #?(:clj Exception :cljs :default) e |
150 | 153 | (ana/resolve-macro-var env sym)))) |
151 | 154 |
|
152 | 155 | (defn all-ns |
|
0 commit comments