Created
August 27, 2014 20:39
-
-
Save noprompt/130197e3c1ede9567bc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; In cljs.analyzer | |
(defmethod parse 'ns | |
[_ env [_ name & args :as form] _ opts] | |
(when-not (symbol? name) | |
(throw (error env "Namespaces must be named by a symbol."))) | |
(let [docstring (if (string? (first args)) (first args)) | |
args (if docstring (next args) args) | |
metadata (if (map? (first args)) (first args)) | |
args (desugar-ns-specs (if metadata (next args) args)) | |
name (vary-meta name merge metadata) ;; <-- Added | |
;; ... | |
] | |
;; ... | |
(set! *cljs-ns* name) | |
;; ... | |
(swap! env/*compiler* update-in [::namespaces name] assoc | |
:name name | |
:doc docstring | |
:excludes excludes | |
:uses uses | |
:requires requires | |
:use-macros use-macros | |
:require-macros require-macros | |
:imports imports) | |
{:env env :op :ns :form form :name name :doc docstring :uses uses :requires requires :imports imports | |
:use-macros use-macros :require-macros require-macros :excludes excludes})) | |
;; In the tests | |
;; Unsure if whether to test (meta a/*cljs-ns*) or (meta (:name ...)). | |
(deftest test-namespace-metadata | |
(binding [a/*cljs-ns* a/*cljs-ns*] | |
;; | |
(is (= (do (a/analyze ns-env '(ns weeble {:foo bar})) | |
(meta a/*cljs-ns*)) | |
{:foo 'bar})) | |
(is (= (do (a/analyze ns-env '(ns ^{:foo bar} weeble)) | |
(meta a/*cljs-ns*)) | |
{:foo 'bar})) | |
(is (= (do (a/analyze ns-env '(ns ^{:foo bar} weeble {:baz quux})) | |
(meta a/*cljs-ns*)) | |
{:foo 'bar :baz 'quux})) | |
(is (= (do (a/analyze ns-env '(ns ^{:foo bar} weeble {:foo baz})) | |
(meta a/*cljs-ns*)) | |
{:foo 'baz})) | |
;; | |
(is (= (meta (:name (a/analyze ns-env '(ns weeble {:foo bar})))) | |
{:foo 'bar})) | |
(is (= (meta (:name (a/analyze ns-env '(ns ^{:foo bar} weeble)))) | |
{:foo 'bar})) | |
(is (= (meta (:name (a/analyze ns-env '(ns ^{:foo bar} weeble {:baz quux})))) | |
{:foo 'bar :baz 'quux})) | |
(is (= (meta (:name (a/analyze ns-env '(ns ^{:foo bar} weeble {:foo baz})))) | |
{:foo 'baz})))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment