Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CLJS-642: deftype/record should not emit goog.provide

A misfeature as multiple provides should not appear in the same source
file - would wreak havoc when using :optimizations :none.

:import is now only for Closure style libraries that make the
constructor the same as the namespace. Enhance :import to support
[lib.ns Ctor*] syntax like Clojure.

Fix tests.
  • Loading branch information...
commit dbf31380b925815d832a6cc53364d063a59dafad 1 parent 513e04a
@swannodette swannodette authored
View
19 src/clj/cljs/analyzer.clj
@@ -836,12 +836,19 @@
(throw (error env (error-msg spec "Only [lib.ns :only (names)] specs supported in :use / :use-macros"))))
[lib :refer referred])
parse-import-spec (fn parse-import-spec [spec]
- (when-not (and (symbol? spec) (nil? (namespace spec)))
- (throw (error env (error-msg spec "Only lib.Ctor specs supported in :import"))))
- (swap! deps conj spec)
- (let [ctor-sym (symbol (last (string/split (str spec) #"\.")))]
- {:import {ctor-sym spec}
- :require {ctor-sym spec}}))
+ (when-not (or (and (vector? spec)
+ (every? symbol? spec))
+ (and (symbol? spec) (nil? (namespace spec))))
+ (throw (error env (error-msg spec "Only lib.ns.Ctor or [lib.ns Ctor*] spec supported in :import"))))
+ (let [import-map (if (vector? spec)
+ (->> (rest spec)
+ (map #(vector % (symbol (str (first spec) "." %))))
+ (into {}))
+ {(symbol (last (string/split (str spec) #"\."))) spec})]
+ (doseq [[_ spec] import-map]
+ (swap! deps conj spec))
+ {:import import-map
+ :require import-map}))
spec-parsers {:require (partial parse-require-spec false)
:require-macros (partial parse-require-spec true)
:use (comp (partial parse-require-spec false) use->require)
View
2  src/clj/cljs/compiler.clj
@@ -755,7 +755,6 @@
(defmethod emit :deftype*
[{:keys [t fields pmasks]}]
(let [fields (map munge fields)]
- (emit-provide t)
(emitln "")
(emitln "/**")
(emitln "* @constructor")
@@ -770,7 +769,6 @@
(defmethod emit :defrecord*
[{:keys [t fields pmasks]}]
(let [fields (concat (map munge fields) '[__meta __extmap])]
- (emit-provide t)
(emitln "")
(emitln "/**")
(emitln "* @constructor")
View
7 test/cljs/cljs/import_test.cljs
@@ -1,11 +1,10 @@
(ns cljs.import-test
(:import goog.math.Long
- cljs.import-test.foo.Bar
- cljs.import-test.foo.Quux))
+ [goog.math Vec2 Vec3]))
(defn test-import []
(assert (fn? Long))
(assert (.equals (Long. 4 6) (.add (Long. 1 2) (Long. 3 4))))
(assert (= "12" (str (Long/fromInt 12))))
- (assert (= 12 (.-x (Bar. 12))))
- (assert (= 12 (.-x (Quux. 12)))))
+ (assert (not (nil? (Vec2. 1 2))))
+ (assert (not (nil? (Vec3. 1 2 3)))))
View
5 test/cljs/cljs/import_test/foo.cljs
@@ -1,5 +0,0 @@
-(ns cljs.import-test.foo)
-
-(defrecord Bar [x])
-
-(deftype Quux [x])
Please sign in to comment.
Something went wrong with that request. Please try again.