This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-21
Channels
- # adventofcode (47)
- # aleph (18)
- # announcements (20)
- # babashka (81)
- # beginners (23)
- # biff (6)
- # calva (5)
- # cider (50)
- # clojure (34)
- # clojure-europe (19)
- # clojure-norway (11)
- # clojure-spec (6)
- # clojure-uk (1)
- # clojurescript (2)
- # conjure (2)
- # cursive (14)
- # datomic (1)
- # humbleui (11)
- # hyperfiddle (3)
- # introduce-yourself (5)
- # joyride (1)
- # nbb (7)
- # off-topic (19)
- # podcasts-discuss (1)
- # reagent (3)
- # reitit (19)
- # releases (1)
- # ring-swagger (1)
- # shadow-cljs (29)
- # sql (6)
- # squint (56)
Are there any examples on how to create and require macros using squint? Or are macros unsupported? My use case is that i want to get rid of js*
boilerplate 🙂
I tried using macros the same way it works in cherry but I guess that's not working atm? https://github.com/squint-cljs/compiler-common/blob/17ace939c44023d56f060a4e9fe8492e3c843b83/cherry/corpus/macro_usage.cljs
I keep on running into “mymacro is not defined”
Thanks :star-struck:
example here, still getting undefined for my macro. Does the macro ns file have to be defined in root src? https://github.com/Dangercoder/svelte-cljs-example/tree/macros/src/lib
ah, thought there were some special rules to how this was done in squint 🙂
currently it's only possible to add the macros in src
, let's say this is the classpath and then every nesting from there yields another segment in the namespace name
in the future this is going to be more flexible, but this was just a shortcut to get them working quickly
I’m trying to import the macros ns which is defined in src/macros.cljc
thanks
nope still getting “reactive is not defined”
ok, the issue is that compile-string doesn't resolve any macros (yet) but compile-file does... the reason for this is that compile-string is platform agnostic, e.g. in a browser we don't load files
What about a hack:
(def $:foo 1)
which outputs:
var $_COLON_foo = 1
and then string/replace this afterwards in the svelte preprocessor, e.g. var \$_COLON_\S+
=> $: foo
@UBN9SNVB4 any idea how to return a promise from the svelte preprocessor?
@UBN9SNVB4 I've got something working, but I get
Error while preprocessing /private/tmp/svelte-cljs-example/src/routes/+page.svelte - Cannot read properties of undefined (reading 'dependencies')
Is it possible to restore your macros branch in a state that's working but without the macro?@UBN9SNVB4 I have a working example here:
https://github.com/borkdude/dangercoder-svelte-cljs-example/tree/macros2
You need to check out a branch of squint-cljs/compiler-common (svelte-macros), then compile this with bb build
and then change the package.json
entry to refer to your local build
I want to review this a bit more before I decide on the API, but in theory this now works
(ns lib.code
(:require ["../components/Nested.svelte$default" :as Nested])
(:require-macros [macros :refer [defreactive]]))
(def cats [])
(defreactive answer (* 2 (count cats)))
(defn addCat []
(let [_new-cat-id (+ 1 (count cats))
new-cat {:id 1 :name "Danger Cat"}]
(set! cats (conj! cats new-cat))))
Hey thanks for looking into this, exciting! Was afk. I’ll check out your branch and try it out 🙂
Another way of doing it is to import the emitted .js
file directly as src
in the scripts tag 💭, doesn’t utilise the pre-processor though but it’s an acceptable workaround
The power of emitting es6 compatible javascript ♨️
I added a file watcher which runs squint compile on any changed cljc/cljs files but I agree, cool to use the pre-processor 🙂
correct
Perhaps svelte can be extended though but for now I’m using babashka tasks
I think squint itself should have a watch mode but if svelte / vite whatever doesn't see that an included js file changed, then it won't help much there
> I guess the preprocessor doesn’t watch .cljs files right? I think my previous answer is incorrect. I got Svelte to hot reload code when I changed .cljs files which were referred in <script lang=“cljs”>
the reason I wanted the bb file-watcher is when e.g. doing svelte server-side things, e.g.
https://github.com/sveltejs/realworld/blob/master/src/routes/login/%2Bpage.server.js
+page.server.cljs
->
+page.server.js
It get’s automatically picked up by Svelte by naming conventions
@UBN9SNVB4 So I added a Node.js API that supports macros now and you can see it in action here: https://github.com/borkdude/dangercoder-svelte-cljs-example/tree/macros2
👍 thank you!
@borkdude so compileString via the node API supports macros now? any other gotchas to be aware of?
@UPH6EL9DH yes, but not that the CLI has always already supported this. macros are expected to be in the src
directory (at this moment)