Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit 3b746ed

Browse files
committed
move core vars to config
1 parent cd12f05 commit 3b746ed

File tree

7 files changed

+46
-15
lines changed

7 files changed

+46
-15
lines changed

cherry/bb.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{:paths ["src"]
1+
{:paths ["src" "resources"]
22
:tasks {test {:doc "Run tests"
33
:task (clojure "-M:cljs:test")}}}

cherry/corpus/no_core_vars.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(ns no-core-vars)
2+
3+
;; The expectation is that when bundling this, it will only be a couple of bytes.
4+
5+
(defn foo []
6+
[])
7+
8+
(js/console.log (str (foo)))

cherry/corpus/no_core_vars.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { vector, str } from 'cherry-cljs/cljs.core.js'
2+
3+
function foo () {
4+
return (function () {
5+
return vector();
6+
})();
7+
};
8+
console.log(str(foo()));

cherry/deps.edn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
{:deps {borkdude/edamame {:mvn/version "1.0.0"}}
1+
{:paths ["src" "resources"]
2+
:deps {borkdude/edamame {:mvn/version "1.0.0"}
3+
babashka/process {:mvn/version "0.1.7"}
4+
}
25
:aliases
36
{:cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.19.6"}}}
47
:test ;; added by neil

cherry/resources/cherry/cljs.core.edn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{:vars #{map assoc str keyword symbol
2+
dissoc conj vector clj->js js->clj get
3+
hash-map array-map first rest next nth seq}
4+
:to-js {clj->js toJs
5+
js->cljs toCljs
6+
hash-map hashMap
7+
array-map arrayMap}}

cherry/src/cherry/transpiler.clj

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727
(ns #^{:author "Allen Rohner"
2828
:doc "A library for generating javascript from Clojure."}
2929
cherry.transpiler
30-
(:require [clojure.string :as str]
31-
[com.reasonr.string :as rstr]
32-
[edamame.core :as e])
33-
(:use clojure.walk))
30+
(:require
31+
[clojure.edn :as edn]
32+
[clojure.java.io :as io]
33+
[clojure.string :as str]
34+
[clojure.walk :as walk]
35+
[com.reasonr.string :as rstr]
36+
[edamame.core :as e]))
3437

3538
(defn- throwf [& message]
3639
(throw (Exception. (apply format message))))
@@ -98,14 +101,13 @@
98101
'? 'try 'break
99102
'await 'const 'defn 'let 'ns 'def]))
100103

101-
(def core-vars (set '[map assoc str keyword symbol
102-
dissoc conj vector clj->js js->clj get
103-
hash-map array-map first rest next nth seq]))
104+
(def core-config (edn/read-string (slurp (io/resource "cherry/cljs.core.edn"))))
104105

105-
(def core->js '{clj->js toJs
106-
js->cljs toCljs
107-
hash-map hashMap
108-
array-map arrayMap})
106+
(def core-vars (:vars core-config))
107+
108+
(def core->js (:to-js core-config))
109+
110+
(prn core->js)
109111

110112
(def prefix-unary-operators (set ['!]))
111113

@@ -437,7 +439,7 @@
437439
(defn- inner-walk [form]
438440
(cond
439441
(unquote? form) (handle-unquote form)
440-
:else (walk inner-walk outer-walk form)))
442+
:else (walk/walk inner-walk outer-walk form)))
441443

442444
(defn- outer-walk [form]
443445
(cond
@@ -446,7 +448,7 @@
446448
:else form))
447449

448450
(defmacro quasiquote [form]
449-
(let [post-form (walk inner-walk outer-walk form)]
451+
(let [post-form (walk/walk inner-walk outer-walk form)]
450452
post-form))
451453

452454
(defmacro js*

cherry/transpile_and_run.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
'[cherry.transpiler :as cherry]
33
)
44

5+
(when-not (System/getProperty "babashka.version")
6+
(require '[babashka.process.pprint]))
7+
58
(def in-file (first *command-line-args*))
69
(def out-file (:out-file (cherry/transpile-file {:in-file in-file})))
710

0 commit comments

Comments
 (0)