File tree Expand file tree Collapse file tree 3 files changed +28
-12
lines changed
test/clojure/cljs/compiler Expand file tree Collapse file tree 3 files changed +28
-12
lines changed Original file line number Diff line number Diff line change 8
8
9
9
(ns cljs.loader
10
10
(:require [goog.object :as gobj]
11
- [goog.html.legacyconversions :as legacy]
12
- [goog.module.ModuleLoader :as ModuleLoader])
13
- ( :import [goog.module ModuleManager ]))
11
+ [goog.html.legacyconversions :as legacy])
12
+ ( :import [goog.module ModuleManager]
13
+ [goog.module ModuleLoader ]))
14
14
15
15
(def module-infos MODULE_INFOS ) ; ; set by compiler
16
16
(def module-uris
Original file line number Diff line number Diff line change 1016
1016
(str " node$module$" (munge (string/replace (str name) #"[.\/ ]" #?(:clj " \\ $"
1017
1017
:cljs " $$" )))))
1018
1018
1019
- (defn munge-goog-module-lib [name]
1020
- (str " goog$module$" (munge (string/replace (str name) #"[.\/ ]" #?(:clj " \\ $" :cljs " $$" )))))
1019
+ (defn munge-goog-module-lib
1020
+ ([name]
1021
+ (str " goog$module$" (munge (string/replace (str name) #"[.\/ ]" #?(:clj " \\ $" :cljs " $$" )))))
1022
+ ([ns name]
1023
+ (str (munge ns ) " ." (munge-goog-module-lib name))))
1021
1024
1022
1025
(defn munge-global-export [name]
1023
1026
(str " global$module$" (munge (string/replace (str name) #"[.\/ ]" #?(:clj " \\ $"
1151
1154
:op :js-var
1152
1155
:ns current-ns})))
1153
1156
1157
+ (defn resolve-import
1158
+ " goog.modules are deterministically assigned to a property of the namespace,
1159
+ we cannot expect the reference will be globally available, so we resolve to
1160
+ namespace local reference."
1161
+ [env import ]
1162
+ (if (goog-module-dep? import )
1163
+ (symbol (munge-goog-module-lib (-> env :ns :name ) import ))
1164
+ import ))
1165
+
1154
1166
; ; core.async calls `macroexpand-1` manually with an ill-formed
1155
1167
; ; :locals map. Normally :locals maps symbols maps, but
1156
1168
; ; core.async adds entries mapping symbols to symbols. We work
Original file line number Diff line number Diff line change 6
6
7
7
(deftest test-glib-module-compile
8
8
(testing " glib modules compiled to Closure Compile expectations"
9
- (env/with-compiler-env (env/default-compiler-env )
10
- (comp-tests/compile-form-seq
11
- '[(ns test.foo
12
- (:require [goog.module.ModuleLoader :as module-loader]))
13
- (def EVENTS module-loader /EVENTS )]))))
9
+ (let [src (env/with-compiler-env (env/default-compiler-env )
10
+ (comp-tests/compile-form-seq
11
+ '[(ns test.foo
12
+ (:import [goog.module ModuleLoader]))
13
+ (def module-loader (ModuleLoader. ))]))]
14
+ (is (re-find #"goog\. require\( 'goog\. module\. ModuleLoader'\) " src))
15
+ (is (re-find #"test\. foo\. goog\$ module\$ goog\$ module\$ ModuleLoader = goog\. module\. get\( 'goog.module.ModuleLoader'\) " src)))))
14
16
15
17
(comment
16
18
19
+ (test/run-tests )
20
+
17
21
(println
18
22
(env/with-compiler-env (env/default-compiler-env )
19
23
(comp-tests/compile-form-seq
20
24
'[(ns test.foo
21
- (:require [goog.module.ModuleLoader :as module-loader ]))
22
- (def EVENTS module-loader / EVENTS )])))
25
+ (:import [goog.module ModuleLoader ]))
26
+ (def module-loader ( ModuleLoader. ) )])))
23
27
24
28
)
You can’t perform that action at this time.
0 commit comments