squint-cljs / squint

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

`nil` keys in map #518

Closed brandonstubbs closed 5 months ago

brandonstubbs commented 5 months ago

version

v0.7.105

problem

The value "null" and nil conflict in a map

repro

npx squint-cljs -e '(prn {nil 10 "null" 20})'
# => {"null":20}

expected behavior

nil and "null" should be in the map

borkdude commented 5 months ago

I don't think this is a correct assumption since JS objects only support string keys

borkdude commented 5 months ago

Here is a counter-example from CLJS:

cljs.user=> (js-obj nil 1 "null" 2)
#js {:null 1}
brandonstubbs commented 5 months ago

Ok understood. This is another difference from squint compared to Clojurescript/Cherry.

Other keys that will not work:

As squint is using Objects vs Maps this is a good reference of differences https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#objects_vs._maps image

For anyone coming across this issue in the future, I used an ES6 map, see playground example