Metadata on function literal inside of a let produces invalid Javascript

Description

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.

Environment

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

Activity

Show:
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: https://github.com/clojure/clojurescript/commit/d54defd32d6c5ffcf6b0698072184fe8ccecc93a 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
https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/compiler.clj#L575-L576
and
https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/compiler.clj#L488 (https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/compiler.clj#L233)

to be true and emit a "return".

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.

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: http://dev.clojure.org/jira/browse/CLJS-1482

import
January 29, 2016, 12:19 AM

Comment made by: gingenhagen

This issue occurs for me even without a let.

gives me

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.

Assignee

David Nolen

Reporter

import

Labels

None

Approval

None

Patch

None

Fix versions

Affects versions

Priority

Major