cherry 2022-07-22

@borkdude has joined the channel

set the channel description: Cherry CLJS transpiler

Ns form with imports work

(ns index
  (:require ["fs" :as fs]
            ["url" :refer [fileURLToPath]]))

(prn (subs (fs/readFileSync (fileURLToPath js/import.meta.url) "utf-8")
           0 100))

(defn foo [{:keys [a b c]}]
  (+ a b c))

(js/console.log (foo {:a 1 :b 2 :c 3}))

2

@mail024 has joined the channel

@mkvlr has joined the channel

πŸ’

πŸ’ 1

So one thing I'm contemplating: should functions with (defn foo ...) be automatically exported with:

export { foo }
unless they are defined with defn- ? Or should exported functions be explicitly marked with (defn ^:export foo ...)

how do js bundlers handle this? (this = renaming)

what renaming exactly?

how do they decide what names to keep stable and what to rename?

I think keeping the names is good for now, this probably compresses pretty well with gzip

oh that. I think once you are bundling, you can rename everything

since that's a final file

shouldn't matter right?

@mkvlr My thoughts weren't about renaming, it was about generating exports automatically for every defn, or only when marked as exported

I'll go with automatic for every defn for now

πŸ‘πŸ» 1

@borkdude what’s the export for?

isn’t that only for closure?

ES6 modules work with exports: you can't import what isn't exported

in js that’s explicit, right?

automatic for public vars sounds like a good start

πŸ‘ 2

ok, export now working in version 0.0.0-alpha.17

(ns exports)

(def foo (fn [] "Hello"))
import { foo } from './exports.mjs';

console.log(foo());

I think we also need a way to do the default export, to be able to write this (bun) example:

export default {
  port: 3000,
  fetch(request) {
    return new Response("Welcome to Bun!");
  },
};

Not sure what syntax would be appropriate for that. Perhaps shadow-cljs already has something for this

Went with (def default ...) :)

πŸ‘ 1

I think a bun cherry run serve.cljs command would be good, which compiles + also runs

@gdwarner has joined the channel

Export by default

already done :)

@armed has joined the channel