|
949 | 949 | (defn compile-file*
|
950 | 950 | ([src dest] (compile-file* src dest nil))
|
951 | 951 | ([src dest opts]
|
952 |
| - (env/ensure |
953 |
| - (with-core-cljs opts |
954 |
| - (fn [] |
955 |
| - (when (or ana/*verbose* (:verbose opts)) |
956 |
| - (util/debug-prn "Compiling " src)) |
957 |
| - (with-open [out ^java.io.Writer (io/make-writer dest {})] |
958 |
| - (binding [*out* out |
959 |
| - ana/*cljs-ns* 'cljs.user |
960 |
| - ana/*cljs-file* (.getPath ^File src) |
961 |
| - reader/*alias-map* (or reader/*alias-map* {}) |
962 |
| - ana/*cljs-static-fns* (or ana/*cljs-static-fns* (:static-fns opts)) |
963 |
| - *source-map-data* (when (:source-map opts) |
964 |
| - (atom |
965 |
| - {:source-map (sorted-map) |
966 |
| - :gen-col 0 |
967 |
| - :gen-line 0}))] |
968 |
| - (emitln (compiled-by-string opts)) |
969 |
| - (loop [forms (ana/forms-seq src) |
970 |
| - ns-name nil |
971 |
| - deps nil] |
972 |
| - (if (seq forms) |
973 |
| - (let [env (ana/empty-env) |
974 |
| - ast (ana/analyze env (first forms) nil opts)] |
975 |
| - (emit ast) |
976 |
| - (if (= (:op ast) :ns) |
977 |
| - (recur (rest forms) (:name ast) (merge (:uses ast) (:requires ast))) |
978 |
| - (recur (rest forms) ns-name deps))) |
979 |
| - (let [sm-data (when *source-map-data* @*source-map-data*) |
980 |
| - ret (merge |
981 |
| - {:ns (or ns-name 'cljs.user) |
982 |
| - :provides [ns-name] |
983 |
| - :requires (if (= ns-name 'cljs.core) |
984 |
| - (set (vals deps)) |
985 |
| - (cond-> (conj (set (vals deps)) 'cljs.core) |
986 |
| - (get-in @env/*compiler* [:opts :emit-constants]) |
987 |
| - (conj 'constants-table))) |
988 |
| - :file dest |
989 |
| - :source-file src} |
990 |
| - (when sm-data |
991 |
| - {:source-map (:source-map sm-data)}))] |
992 |
| - (when (and sm-data (= (:optimizations opts) :none)) |
993 |
| - (let [sm-file (io/file (str (.getPath ^File dest) ".map"))] |
994 |
| - (emits "\n//# sourceMappingURL=" (.getName sm-file) |
995 |
| - (if (true? (:source-map-timestamp opts)) |
996 |
| - (str "?rel=" (System/currentTimeMillis)) |
997 |
| - "")) |
998 |
| - (spit sm-file |
999 |
| - (sm/encode {(url-path src) (:source-map sm-data)} |
1000 |
| - {:lines (+ (:gen-line sm-data) 2) |
1001 |
| - :file (url-path dest) |
1002 |
| - :source-map-timestamp (:source-map-timestamp opts) |
1003 |
| - :source-map-pretty-print (:source-map-pretty-print opts)})))) |
1004 |
| - (let [path (.getPath (.toURL ^File dest))] |
1005 |
| - (swap! env/*compiler* assoc-in [::compiled-cljs path] ret) |
1006 |
| - (swap! env/*compiler* assoc-in [::ana/analyzed-cljs path] true)) |
1007 |
| - (let [{:keys [output-dir cache-analysis]} opts] |
1008 |
| - (when (and (true? cache-analysis) output-dir) |
1009 |
| - (ana/write-analysis-cache ns-name |
1010 |
| - (ana/cache-file src output-dir))) |
1011 |
| - ret))))))))))) |
| 952 | + (env/ensure |
| 953 | + (with-core-cljs opts |
| 954 | + (fn [] |
| 955 | + (when (or ana/*verbose* (:verbose opts)) |
| 956 | + (util/debug-prn "Compiling " src)) |
| 957 | + (if-let [cached (and (= (:optimizations opts) :none) |
| 958 | + (= (:ns (ana/parse-ns src)) 'cljs.core) |
| 959 | + (io/resource "cljs/core.aot.js"))] |
| 960 | + ;; no need to bother with analysis cache reading, handled by |
| 961 | + ;; with-core-cljs |
| 962 | + (do |
| 963 | + (when (or ana/*verbose* (:verbose opts)) |
| 964 | + (util/debug-prn "Using cached cljs.core " src)) |
| 965 | + (spit dest (slurp cached)) |
| 966 | + (when (true? (:source-map opts)) |
| 967 | + (spit (io/file (str dest ".map")) |
| 968 | + (slurp (io/resource "cljs/core.aot.js.map")))) |
| 969 | + (ana/parse-ns src dest nil)) |
| 970 | + (with-open [out ^java.io.Writer (io/make-writer dest {})] |
| 971 | + (binding [*out* out |
| 972 | + ana/*cljs-ns* 'cljs.user |
| 973 | + ana/*cljs-file* (.getPath ^File src) |
| 974 | + reader/*alias-map* (or reader/*alias-map* {}) |
| 975 | + ana/*cljs-static-fns* (or ana/*cljs-static-fns* (:static-fns opts)) |
| 976 | + *source-map-data* (when (:source-map opts) |
| 977 | + (atom |
| 978 | + {:source-map (sorted-map) |
| 979 | + :gen-col 0 |
| 980 | + :gen-line 0}))] |
| 981 | + (emitln (compiled-by-string opts)) |
| 982 | + (loop [forms (ana/forms-seq src) |
| 983 | + ns-name nil |
| 984 | + deps nil] |
| 985 | + (if (seq forms) |
| 986 | + (let [env (ana/empty-env) |
| 987 | + ast (ana/analyze env (first forms) nil opts)] |
| 988 | + (emit ast) |
| 989 | + (if (= (:op ast) :ns) |
| 990 | + (recur (rest forms) (:name ast) (merge (:uses ast) (:requires ast))) |
| 991 | + (recur (rest forms) ns-name deps))) |
| 992 | + (let [sm-data (when *source-map-data* @*source-map-data*) |
| 993 | + ret (merge |
| 994 | + {:ns (or ns-name 'cljs.user) |
| 995 | + :provides [ns-name] |
| 996 | + :requires (if (= ns-name 'cljs.core) |
| 997 | + (set (vals deps)) |
| 998 | + (cond-> (conj (set (vals deps)) 'cljs.core) |
| 999 | + (get-in @env/*compiler* [:opts :emit-constants]) |
| 1000 | + (conj 'constants-table))) |
| 1001 | + :file dest |
| 1002 | + :source-file src} |
| 1003 | + (when sm-data |
| 1004 | + {:source-map (:source-map sm-data)}))] |
| 1005 | + (when (and sm-data (= (:optimizations opts) :none)) |
| 1006 | + (let [sm-file (io/file (str (.getPath ^File dest) ".map"))] |
| 1007 | + (emits "\n//# sourceMappingURL=" (.getName sm-file) |
| 1008 | + (if (true? (:source-map-timestamp opts)) |
| 1009 | + (str "?rel=" (System/currentTimeMillis)) |
| 1010 | + "")) |
| 1011 | + (spit sm-file |
| 1012 | + (sm/encode {(url-path src) (:source-map sm-data)} |
| 1013 | + {:lines (+ (:gen-line sm-data) 2) |
| 1014 | + :file (url-path dest) |
| 1015 | + :source-map-timestamp (:source-map-timestamp opts) |
| 1016 | + :source-map-pretty-print (:source-map-pretty-print opts)})))) |
| 1017 | + (let [path (.getPath (.toURL ^File dest))] |
| 1018 | + (swap! env/*compiler* assoc-in [::compiled-cljs path] ret) |
| 1019 | + (swap! env/*compiler* assoc-in [::ana/analyzed-cljs path] true)) |
| 1020 | + (let [{:keys [output-dir cache-analysis]} opts] |
| 1021 | + (when (and (true? cache-analysis) output-dir) |
| 1022 | + (ana/write-analysis-cache ns-name |
| 1023 | + (ana/cache-file src output-dir))) |
| 1024 | + ret)))))))))))) |
1012 | 1025 |
|
1013 | 1026 | (defn requires-compilation?
|
1014 | 1027 | "Return true if the src file requires compilation."
|
|
0 commit comments