Metadata on function literal inside of a let produces invalid Javascript


Here is a minimal test case that produces the invalid Javascript:

The compiled Javascript includes the invalid token sequence "return return". (Per Chrome: Uncaught SyntaxError: Unexpected token return)

The problem does not occur if the metadata applies to a map literal instead of a function literal.
The problem only occurs when the function and metadata are inside of a let.


Originally found with [org.clojure/clojurescript "0.0-2496"]
Still reproducible with the latest cljsc (b5e9a5116259fc9f201bee4b9c6564f35306f9a5)


David Nolen
June 9, 2020, 12:59 PM

Another case:

All these cases should be a part of test cases included in any proposed patch.

January 29, 2016, 12:19 AM

Comment made by: gingenhagen

This issue occurs for me even without a let.

gives me

Herwig Hochleitner
December 11, 2015, 4:52 PM

I just randomly ran into this, when upgrading an old project. There is also a duplicate already:

David Nolen
May 7, 2015, 1:15 AM

Hrm, it appears analyze-wrap-meta may need to defer to a helper to change the :context of the given AST node.

Nicola Mometto
January 8, 2015, 2:07 PM

David, I understand why this happens but I don't know enough about how cljs's js emission to propose a fix.
The issue is that with this commit: the following scenario is possible:

i.e. analyze-wrap-meta changes the context of the :fn node to :expr but keeps the context of the :fn-methods to :return.

This causes both
and (

to be true and emit a "return".

Your pinned fields
Click on the next to a field label to start pinning.


David Nolen