Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

{{(println .aJSMethod)}} produces {{cljs.core.println.call(null,.aJSMethod);}}, which is not valid JavaScript.

3 Answers

0 votes
by

Comment made by: mfikes

For clarity, perhaps this should not be considered dotted interop. Dotted interop looks like {{(. "a" toUpperCase)}}, for which we can alternatively rely on macroexpansion to write idiomatically as {{(.toUpperCase "a")}}

My preference would be to view {{(println .aJSMethod)}} as a call where {{.aJSMethod}} is a symbol. If ClojureScript follows the definition of symbols at https://clojure.org/reference/reader#_symbols, then an argument can be made that {{.aJSMethod}} is a reserved symbol.

Clojure doesn't appear to have a mechanism that prohibits the use of reserved symbols. For example, you can do the following in Clojure.

(def .aJSMethod "hello") (println .aJSMethod)

Perhaps ClojureScript could be revised to also work like Clojure for such cases. Or, alternatively, perhaps an analysis error could be triggered for reserved symbols not in operator position.

0 votes
by

Comment made by: mfikes

Ahh, even Clojure won't let you go down the path of "allow symbols starting with dot" if you do:

(def .quux inc) (.quux 1)

So, I'd argue for treating things like {{(println .aJSMethod)}} and {{(def .aJSMethod "hello")}} as invalid code, with the underlying reason being the attempted use of a reserved symbol.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2070 (reported by alex+import)
...