|
165 | 165 | (defn unchecked-arrays? []
|
166 | 166 | *unchecked-arrays*)
|
167 | 167 |
|
| 168 | +(defn compiler-options [] |
| 169 | + (get @env/*compiler* :options)) |
| 170 | + |
168 | 171 | (defn checked-arrays
|
169 | 172 | "Returns false-y, :warn, or :error based on configuration and the
|
170 | 173 | current value of *unchecked-arrays*."
|
171 | 174 | []
|
172 |
| - (when (and (not (-> @env/*compiler* :options :advanced)) |
| 175 | + (when (and (not (:advanced (compiler-options))) |
173 | 176 | (not *unchecked-arrays*))
|
174 | 177 | *checked-arrays*))
|
175 | 178 |
|
|
1070 | 1073 | :op :js-var
|
1071 | 1074 | :ns full-ns})
|
1072 | 1075 |
|
| 1076 | +(defn extern-pre [sym current-ns] |
| 1077 | + (let [pre (into '[Object] (->> (string/split (name sym) #"\.") (map symbol) vec))] |
| 1078 | + (when-not (has-extern? pre) |
| 1079 | + (swap! env/*compiler* update-in |
| 1080 | + (into [::namespaces current-ns :externs] pre) merge {})) |
| 1081 | + pre)) |
| 1082 | + |
| 1083 | +(defn node-like? |
| 1084 | + ([] |
| 1085 | + (node-like? (compiler-options))) |
| 1086 | + ([opts] |
| 1087 | + (and (= :nodejs (:target opts)) |
| 1088 | + (false? (:nodejs-rt opts))))) |
| 1089 | + |
1073 | 1090 | (defmethod resolve* :node
|
1074 | 1091 | [env sym full-ns current-ns]
|
1075 |
| - {:ns current-ns |
1076 |
| - :name (symbol (str current-ns) (str (munge-node-lib full-ns) "." (name sym))) |
1077 |
| - :op :js-var |
1078 |
| - :foreign true}) |
| 1092 | + ;; not actually targeting Node.js, we need to generate externs |
| 1093 | + (if (node-like?) |
| 1094 | + (let [pre (extern-pre sym current-ns)] |
| 1095 | + {:ns current-ns |
| 1096 | + :name (symbol (str current-ns) (str (munge-node-lib full-ns) "." (name sym))) |
| 1097 | + :op :js-var |
| 1098 | + :tag (with-meta 'js {:prefix pre}) |
| 1099 | + :foreign true}) |
| 1100 | + {:ns current-ns |
| 1101 | + :name (symbol (str current-ns) (str (munge-node-lib full-ns) "." (name sym))) |
| 1102 | + :op :js-var |
| 1103 | + :foreign true})) |
1079 | 1104 |
|
1080 | 1105 | (defmethod resolve* :global
|
1081 | 1106 | [env sym full-ns current-ns]
|
1082 |
| - (let [pre (into '[Object] (->> (string/split (name sym) #"\.") (map symbol) vec))] |
1083 |
| - (when-not (has-extern? pre) |
1084 |
| - (swap! env/*compiler* update-in |
1085 |
| - (into [::namespaces current-ns :externs] pre) merge {})) |
| 1107 | + (let [pre (extern-pre sym current-ns)] |
1086 | 1108 | {:ns current-ns
|
1087 | 1109 | :name (symbol (str current-ns) (str (munge-global-export full-ns) "." (name sym)))
|
1088 | 1110 | :op :js-var
|
|
0 commit comments