cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
2021-01-03T04:23:56.133300Z

Hi. I would like to build a CLI tool which extracts CSS classnames from the user’s CLJS source code and I am not sure where to start. The class names could be isolated strings in the source code like ["mx-2" "my-1"], inside keywords like :div.mx-2.my-1, or if possible tagged by meta-data ^:css ["mx-2" "my-1"] My first (dummy) approach will be to scan source file as edn, but I may get false positives and miss the classe-name which could be generated using macro. I feel that the compiler could help, but I don’t know how exactly. Which path would you recommend? Do you have some links to relevant articles?

lilactown 2021-01-03T18:46:24.133800Z

you might look into the machinery underneath clj-kondo. it already has a lot of static analysis tools that @borkdude has built for it that have a high likelihood of being useful

borkdude 2021-01-03T18:48:37.134Z

@vincent.cantin A few pointers: you can use https://github.com/borkdude/edamame for parsing Clojure code. You can also use tools.reader directly but it's likely that edamame works better with GraalVM native-image, if you want to make a native CLI. Another pointer: I think your code search can be implemented directly using https://github.com/borkdude/grasp.

👍 1
borkdude 2021-01-03T18:49:03.134500Z

As reference, grasp can search through my entire .m2 dir in 15 seconds (when parallelized)

🔥 1
borkdude 2021-01-03T18:49:16.134700Z

and you get to use specs for what you want to search

2021-01-04T18:23:25.136800Z

@borkdude Thanks, I will take a look.

2021-01-03T06:00:34.133400Z

I found some leads: • https://cljdoc.org/d/leiningen/leiningen/2.9.5/doc/leiningen-plugins#evaluating-in-project-context, so that I can use macro expanded source code. • all-ns, ns-interns and ns-map to list the root vars in a namepace, from which I can read associated metadata. • I can ask the user to wrap its reagent functions in a macro which adds the ^:css metadata derived from the body of the function. If I missed something else, I would be glad to know - I am a beginner in this area.