|
288 | 288 | "*load-fn* may only return a map or nil") |
289 | 289 | (if resource |
290 | 290 | (let [{:keys [lang source cache source-map file]} resource] |
291 | | - (condp = lang |
| 291 | + (condp keyword-identical? lang |
292 | 292 | :clj (do |
293 | 293 | (pre-file-side-effects (:*compiler* bound-vars) aname file opts) |
294 | 294 | (eval-str* bound-vars source name (assoc opts :cljs-file file) |
|
374 | 374 | (debug-prn "Loading dependencies for" lib)) |
375 | 375 | (binding [ana/*cljs-dep-set* (vary-meta (conj (:*cljs-dep-set* bound-vars) lib) |
376 | 376 | update-in [:dep-path] conj lib)] |
377 | | - (assert (every? #(not (contains? (:*cljs-dep-set* bound-vars) %)) deps) |
378 | | - (str "Circular dependency detected " |
379 | | - (-> (:*cljs-dep-set* bound-vars) meta :dep-path))) |
380 | | - (if (seq deps) |
381 | | - (let [dep (first deps) |
382 | | - opts' (-> opts |
383 | | - (dissoc :context) |
384 | | - (dissoc :ns))] |
385 | | - (require bound-vars dep reload opts' |
386 | | - (fn [res] |
387 | | - (when (:verbose opts) |
388 | | - (debug-prn "Loading result:" res)) |
389 | | - (if-not (:error res) |
390 | | - (load-deps bound-vars ana-env lib (next deps) nil opts cb) |
391 | | - (if-let [cljs-dep (let [cljs-ns (ana/clj-ns->cljs-ns dep)] |
392 | | - (get {dep nil} cljs-ns cljs-ns))] |
393 | | - (require bound-vars cljs-dep opts' |
394 | | - (fn [res] |
395 | | - (if (:error res) |
396 | | - (cb res) |
397 | | - (do |
398 | | - (patch-alias-map (:*compiler* bound-vars) lib dep cljs-dep) |
399 | | - (load-deps bound-vars ana-env lib (next deps) nil opts |
400 | | - (fn [res] |
401 | | - (if (:error res) |
402 | | - (cb res) |
403 | | - (cb (update res :aliased-loads assoc dep cljs-dep))))))))) |
404 | | - (cb res)))))) |
405 | | - (cb {:value nil}))))) |
| 377 | + (let [bound-vars (assoc bound-vars :*cljs-dep-set* ana/*cljs-dep-set*)] |
| 378 | + (if-not (every? #(not (contains? ana/*cljs-dep-set* %)) deps) |
| 379 | + (cb (wrap-error |
| 380 | + (ana/error ana-env |
| 381 | + (str "Circular dependency detected " |
| 382 | + (apply str |
| 383 | + (interpose " -> " |
| 384 | + (conj (-> ana/*cljs-dep-set* meta :dep-path) |
| 385 | + (some ana/*cljs-dep-set* deps)))))))) |
| 386 | + (if (seq deps) |
| 387 | + (let [dep (first deps) |
| 388 | + opts' (-> opts |
| 389 | + (dissoc :context) |
| 390 | + (dissoc :ns))] |
| 391 | + (require bound-vars dep reload opts' |
| 392 | + (fn [res] |
| 393 | + (when (:verbose opts) |
| 394 | + (debug-prn "Loading result:" res)) |
| 395 | + (if-not (:error res) |
| 396 | + (load-deps bound-vars ana-env lib (next deps) nil opts cb) |
| 397 | + (if-let [cljs-dep (let [cljs-ns (ana/clj-ns->cljs-ns dep)] |
| 398 | + (get {dep nil} cljs-ns cljs-ns))] |
| 399 | + (require bound-vars cljs-dep opts' |
| 400 | + (fn [res] |
| 401 | + (if (:error res) |
| 402 | + (cb res) |
| 403 | + (do |
| 404 | + (patch-alias-map (:*compiler* bound-vars) lib dep cljs-dep) |
| 405 | + (load-deps bound-vars ana-env lib (next deps) nil opts |
| 406 | + (fn [res] |
| 407 | + (if (:error res) |
| 408 | + (cb res) |
| 409 | + (cb (update res :aliased-loads assoc dep cljs-dep))))))))) |
| 410 | + (cb res)))))) |
| 411 | + (cb {:value nil}))))))) |
406 | 412 |
|
407 | 413 | (declare analyze-str*) |
408 | 414 |
|
409 | 415 | (defn- analyze-deps |
410 | 416 | ([bound-vars ana-env lib deps cb] |
411 | 417 | (analyze-deps bound-vars ana-env lib deps nil cb)) |
412 | 418 | ([bound-vars ana-env lib deps opts cb] |
413 | | - (let [compiler @(:*compiler* bound-vars)] |
414 | | - (binding [ana/*cljs-dep-set* (vary-meta (conj (:*cljs-dep-set* bound-vars) lib) |
415 | | - update-in [:dep-path] conj lib)] |
416 | | - (assert (every? #(not (contains? (:*cljs-dep-set* bound-vars) %)) deps) |
417 | | - (str "Circular dependency detected " |
418 | | - (-> (:*cljs-dep-set* bound-vars) meta :dep-path))) |
419 | | - (if (seq deps) |
420 | | - (let [dep (first deps)] |
421 | | - (try |
422 | | - ((:*load-fn* bound-vars) {:name dep :path (ns->relpath dep)} |
423 | | - (fn [resource] |
424 | | - (assert (or (map? resource) (nil? resource)) |
425 | | - "*load-fn* may only return a map or nil") |
426 | | - (if-not resource |
427 | | - (if-let [cljs-dep (let [cljs-ns (ana/clj-ns->cljs-ns dep)] |
428 | | - (get {dep nil} cljs-ns cljs-ns))] |
429 | | - (do |
430 | | - (patch-alias-map (:*compiler* bound-vars) lib dep cljs-dep) |
431 | | - (analyze-deps bound-vars ana-env lib (cons cljs-dep (next deps)) opts |
432 | | - (fn [res] |
433 | | - (if (:error res) |
434 | | - (cb res) |
435 | | - (cb (update res :aliased-loads assoc dep cljs-dep)))))) |
436 | | - (cb (wrap-error |
| 419 | + (binding [ana/*cljs-dep-set* (vary-meta (conj (:*cljs-dep-set* bound-vars) lib) |
| 420 | + update-in [:dep-path] conj lib)] |
| 421 | + (let [compiler @(:*compiler* bound-vars) |
| 422 | + bound-vars (assoc bound-vars :*cljs-dep-set* ana/*cljs-dep-set*)] |
| 423 | + (if-not (every? #(not (contains? ana/*cljs-dep-set* %)) deps) |
| 424 | + (cb (wrap-error |
| 425 | + (ana/error ana-env |
| 426 | + (str "Circular dependency detected " |
| 427 | + (apply str |
| 428 | + (interpose " -> " |
| 429 | + (conj (-> ana/*cljs-dep-set* meta :dep-path) |
| 430 | + (some ana/*cljs-dep-set* deps)))))))) |
| 431 | + (if (seq deps) |
| 432 | + (let [dep (first deps)] |
| 433 | + (try |
| 434 | + ((:*load-fn* bound-vars) {:name dep :path (ns->relpath dep)} |
| 435 | + (fn [resource] |
| 436 | + (assert (or (map? resource) (nil? resource)) |
| 437 | + "*load-fn* may only return a map or nil") |
| 438 | + (if-not resource |
| 439 | + (if-let [cljs-dep (let [cljs-ns (ana/clj-ns->cljs-ns dep)] |
| 440 | + (get {dep nil} cljs-ns cljs-ns))] |
| 441 | + (do |
| 442 | + (patch-alias-map (:*compiler* bound-vars) lib dep cljs-dep) |
| 443 | + (analyze-deps bound-vars ana-env lib (cons cljs-dep (next deps)) opts |
| 444 | + (fn [res] |
| 445 | + (if (:error res) |
| 446 | + (cb res) |
| 447 | + (cb (update res :aliased-loads assoc dep cljs-dep)))))) |
| 448 | + (cb (wrap-error |
| 449 | + (ana/error ana-env |
| 450 | + (ana/error-message :undeclared-ns |
| 451 | + {:ns-sym dep :js-provide (name dep)}))))) |
| 452 | + (let [{:keys [name lang source file]} resource] |
| 453 | + (condp keyword-identical? lang |
| 454 | + :clj (do |
| 455 | + (pre-file-side-effects (:*compiler* bound-vars) name file opts) |
| 456 | + (analyze-str* bound-vars source name (assoc opts :cljs-file file) |
| 457 | + (fn [res] |
| 458 | + (post-file-side-effects file opts) |
| 459 | + (if-not (:error res) |
| 460 | + (analyze-deps bound-vars ana-env lib (next deps) opts cb) |
| 461 | + (cb res))))) |
| 462 | + :js (analyze-deps bound-vars ana-env lib (next deps) opts cb) |
| 463 | + (wrap-error |
437 | 464 | (ana/error ana-env |
438 | | - (ana/error-message :undeclared-ns |
439 | | - {:ns-sym dep :js-provide (name dep)}))))) |
440 | | - (let [{:keys [name lang source file]} resource] |
441 | | - (condp = lang |
442 | | - :clj (do |
443 | | - (pre-file-side-effects (:*compiler* bound-vars) name file opts) |
444 | | - (analyze-str* bound-vars source name (assoc opts :cljs-file file) |
445 | | - (fn [res] |
446 | | - (post-file-side-effects file opts) |
447 | | - (if-not (:error res) |
448 | | - (analyze-deps bound-vars ana-env lib (next deps) opts cb) |
449 | | - (cb res))))) |
450 | | - :js (analyze-deps bound-vars ana-env lib (next deps) opts cb) |
451 | | - (wrap-error |
452 | | - (ana/error ana-env |
453 | | - (str "Invalid :lang specified " lang ", only :clj or :js allowed")))))))) |
454 | | - (catch :default cause |
455 | | - (cb (wrap-error |
456 | | - (ana/error ana-env |
457 | | - (str "Could not analyze dep " dep) cause)))))) |
458 | | - (cb {:value nil})))))) |
| 465 | + (str "Invalid :lang specified " lang ", only :clj or :js allowed")))))))) |
| 466 | + (catch :default cause |
| 467 | + (cb (wrap-error |
| 468 | + (ana/error ana-env |
| 469 | + (str "Could not analyze dep " dep) cause)))))) |
| 470 | + (cb {:value nil}))))))) |
459 | 471 |
|
460 | 472 | (defn- load-macros [bound-vars k macros lib reload reloads opts cb] |
461 | 473 | (if (seq macros) |
|
738 | 750 | :*data-readers* tags/*cljs-data-readers* |
739 | 751 | :*passes* (or (:passes opts) ana/*passes*) |
740 | 752 | :*analyze-deps* (:analyze-deps opts true) |
| 753 | + :*cljs-dep-set* ana/*cljs-dep-set* |
741 | 754 | :*load-macros* (:load-macros opts true) |
742 | 755 | :*load-fn* (or (:load opts) *load-fn*) |
743 | 756 | :*eval-fn* (or (:eval opts) *eval-fn*)} |
|
845 | 858 | {:*compiler* state |
846 | 859 | :*data-readers* tags/*cljs-data-readers* |
847 | 860 | :*analyze-deps* (:analyze-deps opts true) |
| 861 | + :*cljs-dep-set* ana/*cljs-dep-set* |
848 | 862 | :*load-macros* (:load-macros opts true) |
849 | 863 | :*load-fn* (or (:load opts) *load-fn*) |
850 | 864 | :*eval-fn* (or (:eval opts) *eval-fn*)} |
|
972 | 986 | (compile-str* |
973 | 987 | {:*compiler* state |
974 | 988 | :*data-readers* tags/*cljs-data-readers* |
| 989 | + :*cljs-dep-set* ana/*cljs-dep-set* |
975 | 990 | :*analyze-deps* (:analyze-deps opts true) |
976 | 991 | :*load-macros* (:load-macros opts true) |
977 | 992 | :*load-fn* (or (:load opts) *load-fn*) |
|
1140 | 1155 | {:*compiler* state |
1141 | 1156 | :*data-readers* tags/*cljs-data-readers* |
1142 | 1157 | :*analyze-deps* (:analyze-deps opts true) |
| 1158 | + :*cljs-dep-set* ana/*cljs-dep-set* |
1143 | 1159 | :*load-macros* (:load-macros opts true) |
1144 | 1160 | :*load-fn* (or (:load opts) *load-fn*) |
1145 | 1161 | :*eval-fn* (or (:eval opts) *eval-fn*)} |
|
0 commit comments