squint-cljs / squint

Light-weight ClojureScript dialect
https://squint-cljs.github.io/squint
645 stars 39 forks source link

cljs is not defined when using `case` #515

Closed benjamin-asdf closed 5 months ago

benjamin-asdf commented 5 months ago

version 0.6.89

problem

Example code:

(ns foo)

(defn Foo [a]
  (case (:foo a)
    'b))

output:

import * as squint_core from 'squint-cljs/core.js';
;
var Foo = function (a) {
let G__51451 = squint_core.get(a, "foo");
switch (G__51451) {default:
return cljs.core.symbol("b")}
};

export { Foo }

-> ReferenceError: cljs is not defined

benjamin-asdf commented 5 months ago

Ah the repro doesn't have to do with case. That is simply from 'b.

here is the issue with form I have in real life:

(ns foo)

(defn Foo
  [a]
  (case (:optimistic-audio? audioItem)
    #jsx [UploadedAudioCardOptimistic
          {:description {:name audioItem}}]
      #jsx [UploadedAudioCard {}]))
import * as squint_core from 'squint-cljs/core.js';
;
var Foo = function (a) {
let G__51481 = squint_core.get(audioItem, "optimistic-audio?");
if ((cljs.core.symbol("squint-compiler-jsx") === G__51481)) {
return <UploadedAudioCard></UploadedAudioCard>} else {
if (([UploadedAudioCardOptimistic, ({ "description": ({ "name": audioItem }) })] === G__51481)) {
return <UploadedAudioCard></UploadedAudioCard>} else {
if ("else") {
throw new Error(squint_core.str("No matching clause: ", G__51481))} else {
return null}}}
};

export { Foo }

this has to do with "squint-compiler-jsx" somehow.

Update: I just realized my issue is using case instead of cond :sweat_smile:

borkdude commented 5 months ago

tl;dr: the issue isn't with case or cond, but with using a symbol 'b. squint (as of today) doesn't have symbols. just use a keyword or a string.

benjamin-asdf commented 5 months ago

Additionally. In my second foo example there was an error, using {} instead of (). Then I got a react error "using object as child".