Fix :macros support in cherry#160
Conversation
| (is (not (str/includes? result "my_macro")) | ||
| "Should not contain function call")))) | ||
|
|
||
| (deftest unqualified-macro-test |
There was a problem hiding this comment.
If you want to make macros available unqualified I'd add them to the cljs.core or clojure.core namespace in :macros
Don't make them available unquaiified by default.
There was a problem hiding this comment.
Another approach is to make a compiler state and compile a (:require-macros [foo.bar :refer [x y z]) and use the same compiler state over and over again
| (deftest macro-across-ns-change-test | ||
| (testing "macro works after (ns ...) form" | ||
| (let [code "(ns user)\n(my-macro 1)\n(ns other)\n(my-macro 2)" | ||
| result (cherry/compile-string code #js {:macros #js {"my.ns" #js {"my-macro" my-macro-fn}}})] |
There was a problem hiding this comment.
This shouldn't work at all but is related to my remarks about unqualified macros
| (deftest qualified-macro-test | ||
| (testing "namespace-qualified macro call" | ||
| (let [code "(my.ns/my-macro 42)" | ||
| result (cherry/compile-string code #js {:macros #js {"my.ns" #js {"my-macro" my-macro-fn}}})] |
There was a problem hiding this comment.
The default compile-string function doesn't support JS objects I believe?
There was a problem hiding this comment.
OK, it does. It would probably be cleaner to split this out like compileStringEx
Please answer the following questions and leave the below in as part of your PR.
This PR corresponds to an issue with a clear problem statement.
This PR contains a test to prevent against future regressions
I have updated the CHANGELOG.md file with a description of the addressed issue.
This PR addresses this issue by adding
symbolize-macros-map(converts string keys to symbols) andbuild-macro-refers(auto-populates:refersmaps for unqualified calls). Users can now pass macro functions tocompileStringvia:macrosoption, supporting both qualified(my.ns/my-macro x)and unqualified(my-macro x)calls. CLI:require-macrosstill unsupported due to path resolution issues.