Metadata on function literal inside of a let produces invalid Javascript

Description

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

(defn f [] (let [a 0] ^{"meta" "data"} (fn [] true)))

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:

Ambrose Bonnaire-Sergeant November 5, 2021 at 10:15 PM

Also worth testing the metadata is evaluated as an expression:

(defn make [] ^{:foo (inc 1)} (fn [x] x)) (= {:foo 2} (meta (make)))

FWIW this bug came up in https://github.com/plumatic/schema/pull/430

David Nolen June 9, 2020 at 12:59 PM

Another case:

(defn make [] ^:matcher? (fn [x] x)) (meta (make))

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

import January 29, 2016 at 12:19 AM

Comment made by: gingenhagen

This issue occurs for me even without a let.

(fn [] ^{"meta" "data"} (fn [] true))

gives me

#object[SyntaxError SyntaxError: Unexpected token return]

Herwig Hochleitner December 11, 2015 at 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

David Nolen May 7, 2015 at 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.

Details

Assignee

Reporter

Fix versions

Affects versions

Priority

Created January 8, 2015 at 3:33 AM
Updated November 5, 2021 at 10:15 PM

Flag notifications