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

+1 vote
in ClojureScript by

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.

7 Answers

0 votes
by

Comment made by: bobby.eickhoff

I forgot to try with-meta. Using with-meta does not produce this syntax error, so it's only a problem with the reader macro for metadata.

0 votes
by

Comment made by: dnolen

Any quick thoughts about this one Nicola? Quite possibly a compiler issue on the CLJS side.

0 votes
by
_Comment made by: bronsa_

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:

{:op :meta
 :env {:context :return}
 :expr {:op :fn
        :env {:context :expr}
        :methods [{:op :fn-method
                   :env {:context :return} ..}]
        ..}
 ..}


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".

0 votes
by

Comment made by: dnolen

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

0 votes
by

Comment made by: bendlas

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

0 votes
by

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]

`

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