ClojureScript compiler generates invalid JavaScript code when name contains emoji

Description

Clojure (for JVM) handles code that contains emoji just fine, as shown in this example REPL session:

However, in ClojureScript, it generates an invalid JavaScript code:

This is because πŸ–Œ is not a valid JavaScript name.

If this name should not be acceptable in ClojureScript as well, I think the compiler should raise an error during compilation instead of producing an invalid JavaScript code. However, it would be better such names are supported, because 1) Clojure works with such name and 2) it would allow writing code more expressively.

Actual result: Invalid JavaScript code is generated:

Expected result: Invalid JavaScript identifiers that's allowed in Clojure should be escaped:

Environment

ClojureScript Compiler 1.9.495 (note: I selected 1.9.293 because 1.9.495, the currently released version, is not available)

Activity

Show:
Thai Pangsakulyanont
March 31, 2017, 2:24 PM

I added a simple patch that fixes this problem. Also a test is added to verify the fix. I have already signed the Clojure CA.


To give an example of how emojis might be useful in ClojureScript, I am creating a web page using ClojureScript and I want to define a color scheme. I could use the β€œartist palette” emoji to refer to the color palette.

This allows the code to be used like this:

One could also take advantage of the colors to make the code easier to understand:


Current workaround: It is possible to use an emoji when referring to other namespaces, like this:

In this case, 🎨 can be used without generating a syntax error, because after compilation they will be replaced by mysite.theme.colors

Mike Fikes
June 25, 2017, 10:10 PM

Attached patch no longer applies cleanly.

Assignee

Unassigned

Reporter

Thai Pangsakulyanont

Labels

Approval

None

Patch

None

Affects versions

Priority

Trivial
Configure