Skip to content

Commit

Permalink
CLJS-1869: Regression importing goog.Uri
Browse files Browse the repository at this point in the history
Employ a new `canonicalize-import-specs` when using the new import
macro (in lieu of `canonicalize-specs`) which is faithful to the
original REPL code in a couple of respects:

* It doesn't put bare libspec symbols into vectors
* It simply allows sequential libspecs to pass through

The first change is important because it allows `parse-import-spec`'s
handling of non sequential lib specs to be applied when forming the
import map.

As a concrete example, `parse-import-spec` will convert both '[goog Uri]
and 'goog.Uri to the import map '{Uri goog.Uri}.

Without this change, for the form (import 'goog.Uri), `parse-import-spec`
will instead be passed '[goog.Uri], which is converted to an empty
import map.

The second bullet point, which we get for free with the change to a
faithful canonicalize fn, allows, for example: (import '(goog Uri)) as
was previously possible.
  • Loading branch information
mfikes authored and dnolen committed Dec 13, 2016
1 parent 0ea1e4c commit 3ca51dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2215,6 +2215,13 @@
(if (vector? spec) spec [spec]))))]
(map canonicalize specs)))

(defn canonicalize-import-specs [specs]
(letfn [(canonicalize [quoted-spec-or-kw]
(if (keyword? quoted-spec-or-kw)
quoted-spec-or-kw
(second quoted-spec-or-kw)))]
(map canonicalize specs)))

(defn desugar-ns-specs
"Given an original set of ns specs desugar :include-macros and :refer-macros
usage into only primitive spec forms - :use, :require, :use-macros,
Expand Down Expand Up @@ -2402,7 +2409,9 @@
(when-not *allow-ns*
(throw (error env (str "Calls to `" (name (first quoted-specs))
"` must appear at the top-level."))))
(let [specs (canonicalize-specs quoted-specs)
(let [specs (if (= :import (first quoted-specs))
(canonicalize-import-specs quoted-specs)
(canonicalize-specs quoted-specs))
name (-> env :ns :name)
args (desugar-ns-specs
#?(:clj (list (process-rewrite-form
Expand Down
12 changes: 11 additions & 1 deletion src/test/clojure/cljs/analyzer_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,17 @@
(is (= (a/canonicalize-specs '(:exclude (quote [map mapv])))
'(:exclude [map mapv])))
(is (= (a/canonicalize-specs '(:require (quote [clojure.set :as set])))
'(:require [clojure.set :as set]))))
'(:require [clojure.set :as set])))
(is (= (a/canonicalize-specs '(:require (quote clojure.set)))
'(:require [clojure.set]))))

(deftest test-canonicalize-import-specs
(is (= (a/canonicalize-import-specs '(:import (quote [goog Uri])))
'(:import [goog Uri])))
(is (= (a/canonicalize-import-specs '(:import (quote (goog Uri))))
'(:import (goog Uri))))
(is (= (a/canonicalize-import-specs '(:import (quote goog.Uri)))
'(:import goog.Uri))))

(deftest test-cljs-1346
(testing "`ns*` special form conformance"
Expand Down

0 comments on commit 3ca51dc

Please sign in to comment.