Skip to content

Commit

Permalink
Fix #455: don't export public vars (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Feb 2, 2024
1 parent 8b98c07 commit efca94f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

[Squint](https://github.com/squint-cljs/squint): Light-weight ClojureScript dialect

## v0.6.89 (2024-02-01)

- [#455](https://github.com/squint-cljs/squint/issues/455): don't export non-public vars

## v0.6.88 (2024-01-10)

- Fix infix operator in return position
Expand Down
6 changes: 3 additions & 3 deletions src/squint/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#?(:cljs format)
*aliases* *cljs-ns* *excluded-core-vars* *imported-vars* *public-vars*
comma-list emit emit-args emit-infix emit-return escape-jsx
expr-env infix-operator? prefix-unary? statement suffix-unary?]]
expr-env infix-operator? prefix-unary? suffix-unary?]]
[squint.defclass :as defclass]
[squint.internal.deftype :as deftype]
[squint.internal.destructure :refer [core-let]]
[squint.internal.fn :refer [core-defmacro core-defn core-fn]]
[squint.internal.fn :refer [core-defmacro core-defn core-defn- core-fn]]
[squint.internal.loop :as loop]
[squint.internal.macros :as macros]
[squint.internal.protocols :as protocols])
Expand Down Expand Up @@ -83,7 +83,7 @@
'extend-type protocols/core-extend-type
'deftype deftype/core-deftype
'defn core-defn
'defn- core-defn
'defn- core-defn-
'instance? macros/core-instance?
'time macros/core-time
'declare macros/core-declare
Expand Down
3 changes: 2 additions & 1 deletion src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@
(defmethod emit-special 'def [_type env [_const & more :as expr]]
(let [name (first more)]
;; TODO: move *public-vars* to :ns-state atom
(swap! *public-vars* conj (munge* name))
(when-not (:private (meta name))
(swap! *public-vars* conj (munge* name)))
(swap! (:ns-state env) (fn [state]
(let [current (:current state)]
(assoc-in state [current name] {}))))
Expand Down
3 changes: 3 additions & 0 deletions src/squint/internal/fn.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@
(with-meta (cons `fn fdecl)
(assoc m ::def true)))))

(defn core-defn- [_&form _&env name & args]
`(clojure.core/defn ~(vary-meta name assoc :private true) ~@args))

(defn core-defmacro
"Like defn, but the resulting function name is declared as a
macro and will be used as a macro by the compiler when it is
Expand Down
5 changes: 5 additions & 0 deletions test/squint/compiler_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2215,5 +2215,10 @@ new Foo();")
(deftest infix-return-test
(is (true? (jsv! "(defn foo [x] (and (int? x) (< 10 x 18))) (foo 12)"))))

(deftest no-private-export-test
(let [exports (:exports (compiler/compile-string* "(defn- foo []) (defn bar [])"))]
(is (not (str/includes? exports "foo")))
(is (str/includes? exports "bar"))))

(defn init []
(t/run-tests 'squint.compiler-test 'squint.jsx-test 'squint.string-test))

0 comments on commit efca94f

Please sign in to comment.