ClojureScript

A named fn shadows `js/fn-name`

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Description

The function

(fn console [] js/console)

will return a reference to itself when called.
This happens because the function is transpiled to

(function console(){return console;})

Solution proposals

Mangle internal function names like let bindings

The internal name of a generated js function should be treated like a let binding, hence gensymed.
Thus the function would be transpiled to something like

(function console_1337(){return console;})

References

Brought up in https://groups.google.com/d/msg/clojure/QZmGrjNVurs/NxFtq8yDCFIJ

Activity

Hide
Herwig Hochleitner added a comment -

Attached test uses js/eval, because that's one of the shortest global identifiers, that should be available on every js runtime.

Show
Herwig Hochleitner added a comment - Attached test uses js/eval, because that's one of the shortest global identifiers, that should be available on every js runtime.
Hide
Herwig Hochleitner added a comment -

As detailed in the ML thread, CLJS-680 introduced :js-globals in an attempt to fix this issue. :js-globals should be removed along with a proper fix.

Show
Herwig Hochleitner added a comment - As detailed in the ML thread, CLJS-680 introduced :js-globals in an attempt to fix this issue. :js-globals should be removed along with a proper fix.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: