Skip to content

Commit

Permalink
CLJS-3273 preserve ns-name when processing an :ns* op
Browse files Browse the repository at this point in the history
This happens when a namespace contains both an `ns` form and a `require`
statement. The `require` will expand to `(ns* (require ...))`, and when
processed will generate a namespace name of the form `cljs.user.*` which ends up
replacing the ns-name set in the `ns` declaration.
  • Loading branch information
plexus authored and swannodette committed Aug 7, 2020
1 parent f884af0 commit b5b099a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/clojure/cljs/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,9 @@

(= :ns* (:op ast))
(let [ns-emitted? (some? ns-name)
ns-name (ana/gen-user-ns src)]
ns-name (if-not ns-emitted?
(ana/gen-user-ns src)
ns-name)]
(if-not ns-emitted?
(emit (assoc ast :name ns-name :op :ns))
(emit ast))
Expand Down
8 changes: 8 additions & 0 deletions src/test/clojure/cljs/compiler_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@
(def hist (Html5History.))]))
"(new goog.history.Html5History());"))))

(deftest emit-source-ns*-retains-ns-name ;; CLJS-3273
(let [input (java.io.File/createTempFile "foo" ".cljs")
output (java.io.File/createTempFile "foo" ".js")
_ (spit input "(ns foo.foo) (require 'clojure.string)")
ns-info (env/ensure (comp/emit-source input output "cljs" {}))]
(is (= 'foo.foo (:ns ns-info)))))


;; CLJS-1225

(comment
Expand Down

0 comments on commit b5b099a

Please sign in to comment.