|
882 | 882 | ana/*cljs-static-fns* static-fns
|
883 | 883 | ana/*fn-invoke-direct* (and static-fns fn-invoke-direct)
|
884 | 884 | *repl-opts* opts]
|
885 |
| - (let [env {:context :expr :locals {}} |
886 |
| - special-fns (merge default-special-fns special-fns) |
887 |
| - is-special-fn? (set (keys special-fns)) |
888 |
| - request-prompt (Object.) |
889 |
| - request-exit (Object.) |
890 |
| - opts (comp/with-core-cljs opts |
891 |
| - (fn [] |
892 |
| - (try |
| 885 | + (try |
| 886 | + (let [env {:context :expr :locals {}} |
| 887 | + special-fns (merge default-special-fns special-fns) |
| 888 | + is-special-fn? (set (keys special-fns)) |
| 889 | + request-prompt (Object.) |
| 890 | + request-exit (Object.) |
| 891 | + opts (comp/with-core-cljs opts |
| 892 | + (fn [] |
893 | 893 | (if-let [merge-opts (:merge-opts (-setup repl-env opts))]
|
894 | 894 | (merge opts merge-opts)
|
895 |
| - opts) |
896 |
| - (catch Throwable e |
897 |
| - (caught e repl-env opts) |
898 |
| - opts)))) |
899 |
| - init (do |
900 |
| - (evaluate-form repl-env env "<cljs repl>" |
901 |
| - `(~'set! ~'cljs.core/*print-namespace-maps* true) |
902 |
| - identity opts) |
903 |
| - (or init |
| 895 | + opts))) |
| 896 | + init (do |
| 897 | + (evaluate-form repl-env env "<cljs repl>" |
| 898 | + `(~'set! ~'cljs.core/*print-namespace-maps* true) |
| 899 | + identity opts) |
| 900 | + (or init |
904 | 901 | #(evaluate-form repl-env env "<cljs repl>"
|
905 | 902 | (with-meta
|
906 | 903 | `(~'ns ~'cljs.user
|
907 | 904 | (:require ~@repl-requires))
|
908 | 905 | {:line 1 :column 1})
|
909 | 906 | identity opts)))
|
910 |
| - read-eval-print |
| 907 | + read-eval-print |
| 908 | + (fn [] |
| 909 | + (let [input (binding [*ns* (create-ns ana/*cljs-ns*) |
| 910 | + reader/resolve-symbol ana/resolve-symbol |
| 911 | + reader/*data-readers* tags/*cljs-data-readers* |
| 912 | + reader/*alias-map* |
| 913 | + (apply merge |
| 914 | + ((juxt :requires :require-macros) |
| 915 | + (ana/get-namespace ana/*cljs-ns*)))] |
| 916 | + (read request-prompt request-exit))] |
| 917 | + (or ({request-exit request-exit |
| 918 | + :cljs/quit request-exit |
| 919 | + request-prompt request-prompt} input) |
| 920 | + (if (and (seq? input) (is-special-fn? (first input))) |
| 921 | + (do |
| 922 | + ((get special-fns (first input)) repl-env env input opts) |
| 923 | + (print nil)) |
| 924 | + (let [value (eval repl-env env input opts)] |
| 925 | + (print value))))))] |
| 926 | + (maybe-install-npm-deps opts) |
| 927 | + (comp/with-core-cljs opts |
911 | 928 | (fn []
|
912 |
| - (let [input (binding [*ns* (create-ns ana/*cljs-ns*) |
913 |
| - reader/resolve-symbol ana/resolve-symbol |
914 |
| - reader/*data-readers* tags/*cljs-data-readers* |
915 |
| - reader/*alias-map* |
916 |
| - (apply merge |
917 |
| - ((juxt :requires :require-macros) |
918 |
| - (ana/get-namespace ana/*cljs-ns*)))] |
919 |
| - (read request-prompt request-exit))] |
920 |
| - (or ({request-exit request-exit |
921 |
| - :cljs/quit request-exit |
922 |
| - request-prompt request-prompt} input) |
923 |
| - (if (and (seq? input) (is-special-fn? (first input))) |
924 |
| - (do |
925 |
| - ((get special-fns (first input)) repl-env env input opts) |
926 |
| - (print nil)) |
927 |
| - (let [value (eval repl-env env input opts)] |
928 |
| - (print value))))))] |
929 |
| - (maybe-install-npm-deps opts) |
930 |
| - (comp/with-core-cljs opts |
931 |
| - (fn [] |
932 |
| - (binding [*repl-opts* opts] |
933 |
| - (try |
934 |
| - (when analyze-path |
935 |
| - (if (vector? analyze-path) |
936 |
| - (run! #(analyze-source % opts) analyze-path) |
937 |
| - (analyze-source analyze-path opts))) |
938 |
| - (init) |
939 |
| - (run-inits repl-env inits) |
940 |
| - (catch Throwable e |
941 |
| - (caught e repl-env opts))) |
942 |
| - (when-let [src (:watch opts)] |
943 |
| - (.start |
944 |
| - (Thread. |
945 |
| - ((ns-resolve 'clojure.core 'binding-conveyor-fn) |
946 |
| - (fn [] |
947 |
| - (let [log-file (io/file (util/output-directory opts) "watch.log")] |
948 |
| - (err-out (println "Watch compilation log available at:" (str log-file))) |
949 |
| - (try |
950 |
| - (let [log-out (FileWriter. log-file)] |
951 |
| - (binding [*err* log-out |
952 |
| - *out* log-out] |
953 |
| - (cljsc/watch src (dissoc opts :watch) |
954 |
| - env/*compiler* done?))) |
955 |
| - (catch Throwable e |
956 |
| - (caught e repl-env opts))))))))) |
957 |
| - ;; let any setup async messages flush |
958 |
| - (Thread/sleep 50) |
959 |
| - (binding [*in* (if (true? (:source-map-inline opts)) |
960 |
| - *in* |
961 |
| - (reader))] |
962 |
| - (quit-prompt) |
963 |
| - (prompt) |
964 |
| - (flush) |
965 |
| - (loop [] |
966 |
| - (when-not |
967 |
| - (try |
968 |
| - (identical? (read-eval-print) request-exit) |
969 |
| - (catch Throwable e |
970 |
| - (caught e repl-env opts) |
971 |
| - nil)) |
972 |
| - (when (need-prompt) |
973 |
| - (prompt) |
974 |
| - (flush)) |
975 |
| - (recur)))))))) |
976 |
| - (reset! done? true) |
977 |
| - (-tear-down repl-env))))) |
| 929 | + (binding [*repl-opts* opts] |
| 930 | + (try |
| 931 | + (when analyze-path |
| 932 | + (if (vector? analyze-path) |
| 933 | + (run! #(analyze-source % opts) analyze-path) |
| 934 | + (analyze-source analyze-path opts))) |
| 935 | + (init) |
| 936 | + (run-inits repl-env inits) |
| 937 | + (catch Throwable e |
| 938 | + (caught e repl-env opts))) |
| 939 | + (when-let [src (:watch opts)] |
| 940 | + (.start |
| 941 | + (Thread. |
| 942 | + ((ns-resolve 'clojure.core 'binding-conveyor-fn) |
| 943 | + (fn [] |
| 944 | + (let [log-file (io/file (util/output-directory opts) "watch.log")] |
| 945 | + (err-out (println "Watch compilation log available at:" (str log-file))) |
| 946 | + (try |
| 947 | + (let [log-out (FileWriter. log-file)] |
| 948 | + (binding [*err* log-out |
| 949 | + *out* log-out] |
| 950 | + (cljsc/watch src (dissoc opts :watch) |
| 951 | + env/*compiler* done?))) |
| 952 | + (catch Throwable e |
| 953 | + (caught e repl-env opts))))))))) |
| 954 | + ;; let any setup async messages flush |
| 955 | + (Thread/sleep 50) |
| 956 | + (binding [*in* (if (true? (:source-map-inline opts)) |
| 957 | + *in* |
| 958 | + (reader))] |
| 959 | + (quit-prompt) |
| 960 | + (prompt) |
| 961 | + (flush) |
| 962 | + (loop [] |
| 963 | + (when-not |
| 964 | + (try |
| 965 | + (identical? (read-eval-print) request-exit) |
| 966 | + (catch Throwable e |
| 967 | + (caught e repl-env opts) |
| 968 | + nil)) |
| 969 | + (when (need-prompt) |
| 970 | + (prompt) |
| 971 | + (flush)) |
| 972 | + (recur)))))))) |
| 973 | + (finally |
| 974 | + (reset! done? true) |
| 975 | + (-tear-down repl-env))))))) |
978 | 976 |
|
979 | 977 | (defn repl
|
980 | 978 | "Generic, reusable, read-eval-print loop. By default, reads from *in* using
|
|
0 commit comments