cherry

borkdude 2022-07-22T12:03:21.788589Z

@borkdude has joined the channel

borkdude 2022-07-22T12:03:22.034309Z

set the channel description: Cherry CLJS transpiler

borkdude 2022-07-22T12:03:41.465079Z

set the channel topic: https://github.com/borkdude/cherry

borkdude 2022-07-22T12:03:48.172679Z

set the channel description: https://github.com/borkdude/cherry

borkdude 2022-07-22T13:25:16.599009Z

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
Alexis Vincent 2022-07-22T13:25:27.588439Z

@mail024 has joined the channel

mkvlr 2022-07-22T13:25:32.719049Z

@mkvlr has joined the channel

mkvlr 2022-07-22T13:48:29.972499Z

πŸ‘‹

mkvlr 2022-07-22T13:48:42.494919Z

πŸ’

πŸ’ 1
borkdude 2022-07-22T13:49:50.377979Z

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 ...)

borkdude 2022-07-22T13:50:02.975859Z

set the channel topic: https://github.com/borkdude/cherry πŸ’

mkvlr 2022-07-22T13:51:54.420999Z

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

borkdude 2022-07-22T13:53:21.703439Z

what renaming exactly?

mkvlr 2022-07-22T13:53:40.672629Z

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

mkvlr 2022-07-22T13:54:24.801249Z

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

borkdude 2022-07-22T13:54:26.261989Z

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

borkdude 2022-07-22T13:54:33.542769Z

since that's a final file

borkdude 2022-07-22T13:54:45.305399Z

shouldn't matter right?

borkdude 2022-07-22T13:57:12.150389Z

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

borkdude 2022-07-22T13:58:16.036159Z

I'll go with automatic for every defn for now

πŸ‘πŸ» 1
mkvlr 2022-07-22T14:04:18.723159Z

@borkdude what’s the export for?

mkvlr 2022-07-22T14:04:30.895079Z

isn’t that only for closure?

borkdude 2022-07-22T14:04:45.254589Z

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

mkvlr 2022-07-22T14:05:05.254509Z

ah right

mkvlr 2022-07-22T14:05:16.971999Z

in js that’s explicit, right?

borkdude 2022-07-22T14:05:20.306179Z

yes

mkvlr 2022-07-22T14:06:06.055139Z

automatic for public vars sounds like a good start

πŸ‘ 2
borkdude 2022-07-22T15:01:49.026319Z

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

borkdude 2022-07-22T15:02:12.692569Z

(ns exports)

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

console.log(foo());

borkdude 2022-07-22T15:05:15.853029Z

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!");
  },
};

borkdude 2022-07-22T15:06:25.000989Z

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

borkdude 2022-07-22T15:43:57.984539Z

Went with (def default ...) :)

πŸ‘ 1
borkdude 2022-07-22T15:52:57.923569Z

In action: https://twitter.com/borkdude/status/1550508930438242304

borkdude 2022-07-22T15:55:49.886899Z

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

borkdude 2022-07-22T18:47:29.942339Z

Works now

gdubs 2022-07-22T15:56:39.689299Z

@gdwarner has joined the channel

Alexis Vincent 2022-07-22T17:39:04.881289Z

Export by default

borkdude 2022-07-22T17:46:58.299819Z

already done :)

armed 2022-07-22T19:43:35.134289Z

@armed has joined the channel