Skip to content

Commit 532c54c

Browse files
committed
Box cherry user dynvars too, keeping its cljs.core vars plain
1 parent 858d0d5 commit 532c54c

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/squint/compiler_common.cljc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,18 @@
619619
(let [m (munged-name expr)]
620620
m)))))]
621621
;; a reference to a dynamic var (earmuffed, not a local) reads the
622-
;; box's .val. Cherry has real CLJS dynamic vars, no box.
622+
;; box's .val. Cherry boxes user dynvars too (cross-module set! in
623+
;; per-file ESM output), but its cljs.core vars are real CLJS vars:
624+
;; a reference resolved to the core module alias stays plain.
623625
(emit-return (escape-jsx
624-
(cond-> expr
625-
(and (not= :cherry (:target env))
626-
(dynamic-name? orig-sym)
627-
(not (contains? (:var->ident env) orig-sym)))
628-
(str ".val"))
626+
(let [core-ref? (when-let [core-alias (:core-alias env)]
627+
(str/starts-with? (str expr) (str core-alias ".")))]
628+
(cond-> expr
629+
(and (dynamic-name? orig-sym)
630+
(not (contains? (:var->ident env) orig-sym))
631+
(or (not= :cherry (:target env))
632+
(not core-ref?)))
633+
(str ".val")))
629634
env)
630635
env))))))
631636

@@ -802,9 +807,8 @@
802807
init (emit expr (expr-env env*))
803808
;; a dynamic var (earmuffed) compiles to a mutable box {value ...} so
804809
;; set!/binding can mutate it across ESM modules; references read .value.
805-
;; Cherry has real CLJS dynamic vars, no box.
806-
init (if (and (not= :cherry (:target env))
807-
(dynamic-name? name))
810+
;; Cherry too: only its cljs.core vars are plain (see the symbol emit).
811+
init (if (dynamic-name? name)
808812
(str "({val: " init "})")
809813
init)]
810814
(str "var " ident " = "

0 commit comments

Comments
 (0)