|
97 | 97 | [{:keys [source] :as resource}] |
98 | 98 | (js/eval source)) |
99 | 99 |
|
100 | | -(defn wrap-error [ex] |
| 100 | +(defn- wrap-error [ex] |
101 | 101 | {:error ex}) |
102 | 102 |
|
103 | 103 | (defn empty-state |
|
119 | 119 | (let [sm (sm/decode (.parse js/JSON sm-json))] |
120 | 120 | (swap! state assoc-in [:source-maps ns] sm))) |
121 | 121 |
|
122 | | -(defn sm-data [] |
| 122 | +(defn- sm-data [] |
123 | 123 | (atom |
124 | 124 | {:source-map (sorted-map) |
125 | 125 | :gen-col 0 |
126 | 126 | :gen-line 0})) |
127 | 127 |
|
128 | | -(defn prefix [s pre] |
| 128 | +(defn- prefix [s pre] |
129 | 129 | (str pre s)) |
130 | 130 |
|
131 | | -(defn append-source-map |
| 131 | +(defn- append-source-map |
132 | 132 | [state name source sb sm-data {:keys [output-dir asset-path] :as opts}] |
133 | 133 | (let [t (.valueOf (js/Date.)) |
134 | 134 | smn (if name |
|
233 | 233 |
|
234 | 234 | (declare ns-side-effects analyze-deps) |
235 | 235 |
|
236 | | -(defn load-deps |
| 236 | +(defn- load-deps |
237 | 237 | ([bound-vars ana-env lib deps cb] |
238 | 238 | (analyze-deps bound-vars ana-env lib deps nil cb)) |
239 | 239 | ([bound-vars ana-env lib deps opts cb] |
|
256 | 256 | (cb res))))) |
257 | 257 | (cb {:value nil}))))) |
258 | 258 |
|
259 | | -(declare analyze*) |
| 259 | +(declare analyze-str*) |
260 | 260 |
|
261 | | -(defn analyze-deps |
| 261 | +(defn- analyze-deps |
262 | 262 | ([bound-vars ana-env lib deps cb] |
263 | 263 | (analyze-deps bound-vars ana-env lib deps nil cb)) |
264 | 264 | ([bound-vars ana-env lib deps opts cb] |
|
278 | 278 | (if resource |
279 | 279 | (let [{:keys [name lang source]} resource] |
280 | 280 | (condp = lang |
281 | | - :clj (analyze* bound-vars source name opts |
| 281 | + :clj (analyze-str* bound-vars source name opts |
282 | 282 | (fn [res] |
283 | 283 | (if-not (:error res) |
284 | 284 | (analyze-deps bound-vars ana-env lib (next deps) opts cb) |
|
297 | 297 | (str "Could not analyze dep " dep) cause)))))) |
298 | 298 | (cb {:value nil})))))) |
299 | 299 |
|
300 | | -(defn load-macros [bound-vars k macros reload reloads opts cb] |
| 300 | +(defn- load-macros [bound-vars k macros reload reloads opts cb] |
301 | 301 | (if (seq macros) |
302 | 302 | (let [nsym (first (vals macros)) |
303 | 303 | k (or (k reload) |
|
314 | 314 | (cb res))))) |
315 | 315 | (cb {:value nil}))) |
316 | 316 |
|
317 | | -(defn ns-side-effects |
| 317 | +(defn- ns-side-effects |
318 | 318 | ([bound-vars ana-env ast opts cb] |
319 | 319 | (ns-side-effects false bound-vars ana-env ast opts cb)) |
320 | 320 | ([load bound-vars ana-env {:keys [op] :as ast} opts cb] |
|
376 | 376 | (check-uses-and-load-macros {:value nil})))) |
377 | 377 | (cb {:value ast})))) |
378 | 378 |
|
379 | | -(defn analyze* [bound-vars source name opts cb] |
| 379 | +(defn- analyze-str* [bound-vars source name opts cb] |
380 | 380 | (let [rdr (rt/indexing-push-back-reader source 1 name) |
381 | 381 | eof (js-obj) |
382 | 382 | aenv (ana/empty-env) |
|
421 | 421 | (recur ast))))) |
422 | 422 | (cb {:value last-ast}))))))) nil))) |
423 | 423 |
|
424 | | -(defn analyze |
| 424 | +(defn analyze-str |
425 | 425 | "Analyze ClojureScript source. The compiler state will be populated with |
426 | 426 | the results of analyzes. The parameters: |
427 | 427 |
|
|
446 | 446 | map will contain a key :error with an ex-info instance describing the cause |
447 | 447 | of failure." |
448 | 448 | ([state source cb] |
449 | | - (analyze state source nil cb)) |
| 449 | + (analyze-str state source nil cb)) |
450 | 450 | ([state source name cb] |
451 | | - (analyze state source name nil cb)) |
| 451 | + (analyze-str state source name nil cb)) |
452 | 452 | ([state source name opts cb] |
453 | 453 | {:pre [(atom? state) (string? source) |
454 | 454 | (valid-name? name) (valid-opts? opts) (fn? cb)]} |
455 | | - (analyze* |
| 455 | + (analyze-str* |
456 | 456 | {:*compiler* state |
457 | 457 | :*data-readers* tags/*cljs-data-readers* |
458 | 458 | :*passes* (or (:passes opts) ana/*passes*) |
|
465 | 465 | ;; ----------------------------------------------------------------------------- |
466 | 466 | ;; Eval |
467 | 467 |
|
468 | | -(defn eval* [bound-vars form opts cb] |
| 468 | +(defn- eval* [bound-vars form opts cb] |
469 | 469 | (let [the-ns (or (:ns opts) 'cljs.user) |
470 | 470 | bound-vars (cond-> (merge bound-vars {:*cljs-ns* the-ns}) |
471 | 471 | (:source-map opts) (assoc :*sm-data* (sm-data)))] |
|
533 | 533 | ;; ----------------------------------------------------------------------------- |
534 | 534 | ;; Compile |
535 | 535 |
|
536 | | -(defn compile* [bound-vars source name opts cb] |
| 536 | +(defn- compile-str* [bound-vars source name opts cb] |
537 | 537 | (let [rdr (rt/indexing-push-back-reader source 1 name) |
538 | 538 | eof (js-obj) |
539 | 539 | aenv (ana/empty-env) |
|
581 | 581 | name source sb @comp/*source-map-data* opts)) |
582 | 582 | (cb {:value (.toString sb)}))))))))))) |
583 | 583 |
|
584 | | -(defn compile |
| 584 | +(defn compile-str |
585 | 585 | "Compile ClojureScript source into JavaScript. The parameters: |
586 | 586 |
|
587 | 587 | state (atom) |
|
605 | 605 | will contain a key :error with an ex-info instance describing the cause |
606 | 606 | of failure." |
607 | 607 | ([state source cb] |
608 | | - (compile state source nil cb)) |
| 608 | + (compile-str state source nil cb)) |
609 | 609 | ([state source name cb] |
610 | | - (compile state source name nil cb)) |
| 610 | + (compile-str state source name nil cb)) |
611 | 611 | ([state source name opts cb] |
612 | 612 | {:pre [(atom? state) (string? source) |
613 | 613 | (valid-name? name) (valid-opts? opts) (fn? cb)]} |
614 | | - (compile* |
| 614 | + (compile-str* |
615 | 615 | {:*compiler* state |
616 | 616 | :*data-readers* tags/*cljs-data-readers* |
617 | 617 | :*analyze-deps* (or (:analyze-deps opts) true) |
|
624 | 624 | ;; ----------------------------------------------------------------------------- |
625 | 625 | ;; Evaluate String |
626 | 626 |
|
627 | | -(defn eval-str* [bound-vars source name opts cb] |
| 627 | +(defn- eval-str* [bound-vars source name opts cb] |
628 | 628 | (let [rdr (rt/indexing-push-back-reader source 1 name) |
629 | 629 | eof (js-obj) |
630 | 630 | aenv (ana/empty-env) |
|
778 | 778 | (defn elide-env [env ast opts] |
779 | 779 | (dissoc ast :env)) |
780 | 780 |
|
781 | | - (cljs/analyze st "(+ 1 1)" nil |
| 781 | + (cljs/analyze-str st "(+ 1 1)" nil |
782 | 782 | {:passes [ana/infer-type elide-env] |
783 | 783 | :eval node-eval} |
784 | 784 | (fn [{:keys [value]}] |
|
789 | 789 | (fn [res] |
790 | 790 | (println res))) |
791 | 791 |
|
792 | | - (cljs/compile st "(defprotocol IFoo (foo [this]))" |
| 792 | + (cljs/compile-str st "(defprotocol IFoo (foo [this]))" |
793 | 793 | (fn [{:keys [value]}] |
794 | 794 | (println "Source:") |
795 | 795 | (println value))) |
|
830 | 830 | (fn [res] |
831 | 831 | (println res))) |
832 | 832 |
|
833 | | - (cljs/compile st "(defn foo\n[a b]\n(+ a b))" 'cljs.foo |
| 833 | + (cljs/compile-str st "(defn foo\n[a b]\n(+ a b))" 'cljs.foo |
834 | 834 | {:verbose true :source-map true} |
835 | 835 | (fn [js-source] |
836 | 836 | (println "Source:") |
|
0 commit comments