|
16 | 16 | [cljs.tagged-literals :as tags]
|
17 | 17 | [cljs.analyzer :as ana]
|
18 | 18 | [cljs.source-map :as sm]
|
19 |
| - [clojure.data.json :as json]) |
| 19 | + [clojure.data.json :as json] |
| 20 | + [cljs.js-deps :as deps]) |
20 | 21 | (:import java.lang.StringBuilder
|
21 | 22 | java.io.File))
|
22 | 23 |
|
|
25 | 26 | (def js-reserved ana/js-reserved)
|
26 | 27 |
|
27 | 28 | (def ^:dynamic *dependents* nil)
|
| 29 | +(def ^:dynamic *inputs* nil) |
28 | 30 | (def ^:dynamic *source-map-data* nil)
|
29 | 31 | (def ^:dynamic *lexical-renames* {})
|
30 | 32 |
|
|
1101 | 1103 | ([src dest opts]
|
1102 | 1104 | {:post [map?]}
|
1103 | 1105 | (binding [ana/*file-defs* (atom #{})]
|
1104 |
| - (let [src-file (io/file src) |
| 1106 | + (let [nses (get @env/*compiler* ::ana/namespaces) |
| 1107 | + src-file (io/file src) |
1105 | 1108 | dest-file (io/file dest)
|
1106 | 1109 | opts (merge {:optimizations :none} opts)]
|
1107 | 1110 | (if (.exists src-file)
|
|
1114 | 1117 | (if (requires-compilation? src-file dest-file opts)
|
1115 | 1118 | (do
|
1116 | 1119 | (util/mkdirs dest-file)
|
1117 |
| - (when (and (get-in @env/*compiler* [::ana/namespaces ns :defs]) |
| 1120 | + (when (and (get-in nses [ns :defs]) |
1118 | 1121 | (not= ns 'cljs.core))
|
1119 | 1122 | (swap! env/*compiler* update-in [::ana/namespaces] dissoc ns))
|
1120 | 1123 | (let [ret (compile-file* src-file dest-file opts)]
|
1121 | 1124 | (when *dependents*
|
1122 | 1125 | (swap! *dependents*
|
1123 | 1126 | (fn [{:keys [recompile visited]}]
|
1124 |
| - {:recompile (into recompile (ana/ns-dependents ns)) |
1125 |
| - :visited (conj visited ns)}))) |
| 1127 | + {:recompile (into recompile |
| 1128 | + (ana/ns-dependents ns |
| 1129 | + (merge *inputs* nses))) |
| 1130 | + :visited (conj visited ns)}))) |
1126 | 1131 | ret))
|
1127 | 1132 | (do
|
1128 | 1133 | ;; populate compilation environment with analysis information
|
1129 | 1134 | ;; when constants are optimized
|
1130 | 1135 | (when (and (true? (:optimize-constants opts))
|
1131 |
| - (nil? (get-in @env/*compiler* [::ana/namespaces ns :defs]))) |
| 1136 | + (nil? (get-in nses [ns :defs]))) |
1132 | 1137 | (with-core-cljs opts (fn [] (ana/analyze-file src-file opts))))
|
1133 | 1138 | ns-info)))
|
1134 | 1139 | (catch Exception e
|
|
1158 | 1163 | (compile-root src-dir target-dir nil))
|
1159 | 1164 | ([src-dir target-dir opts]
|
1160 | 1165 | (swap! env/*compiler* assoc :root src-dir)
|
1161 |
| - (let [src-dir-file (io/file src-dir)] |
1162 |
| - (loop [cljs-files (cljs-files-in src-dir-file) |
1163 |
| - output-files []] |
1164 |
| - (if (seq cljs-files) |
1165 |
| - (let [cljs-file (first cljs-files) |
1166 |
| - output-file (util/to-target-file target-dir (ana/parse-ns cljs-file)) |
1167 |
| - ns-info (compile-file cljs-file output-file opts)] |
1168 |
| - (recur (rest cljs-files) (conj output-files (assoc ns-info :file-name (.getPath output-file))))) |
1169 |
| - output-files))))) |
| 1166 | + (let [src-dir-file (io/file src-dir) |
| 1167 | + inputs (deps/dependency-order |
| 1168 | + (map #(ana/parse-ns %) |
| 1169 | + (cljs-files-in src-dir-file)))] |
| 1170 | + (binding [*inputs* (zipmap (map :ns inputs) inputs)] |
| 1171 | + (loop [inputs (seq inputs) compiled []] |
| 1172 | + (if inputs |
| 1173 | + (let [{:keys [source-file] :as ns-info} (first inputs) |
| 1174 | + output-file (util/to-target-file target-dir ns-info) |
| 1175 | + ijs (compile-file source-file output-file opts)] |
| 1176 | + (recur |
| 1177 | + (next inputs) |
| 1178 | + (conj compiled |
| 1179 | + (assoc ijs :file-name (.getPath output-file))))) |
| 1180 | + compiled)))))) |
1170 | 1181 |
|
1171 | 1182 | ;; TODO: needs fixing, table will include other things than keywords - David
|
1172 | 1183 |
|
|
0 commit comments