ClojureScript

Function names clash with namespace names

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Related to this thread: https://groups.google.com/forum/?hl=en#!topic/clojure/AINvE8fUjAM

The issue is that, if you have a namespace called 'foo.core' and a function called 'foo', foo clashes with the namespace inside the generated JavaScript code and results in odd and generally indecipherable errors. Here is some example code that fails:

(def net (node/require "net"))

(defn portal
  [port host] (.createConnection net port host))

(defn -main [& args] ; Note that only one of these -main functions is in the file at any given time, of course.
  (.createConnection net 1337 "localhost"))

(defn -main [& args]
  (portal 1337 "localhost"))

(set! *main-cli-fn* -main)

The first main is the one that works. The second main is a failwhale. Running the second main results in this error:

TypeError: Cannot read property 'net' of undefined
and this generated JavaScript:

portal.core.net = cljs.nodejs.require.call(null, "net");
portal.core.portal = function portal(b, c) {
  return portal.core.net.createConnection(b, c)
};
portal.core._main = function(a) {
  cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0);
  return portal.core.portal.call(null, 1337, "localhost")
};

And here is the generated JS for the working -main:

portal.core._main = function(a) {
  cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0);
  return portal.core.net.createConnection(1337, "localhost")
};

Activity

Hide
David Nolen added a comment -

Is this still a problem? I don't see anything in the generated source that looks problematic. Do you have an testable example of the issue that doesn't involve Node?

Show
David Nolen added a comment - Is this still a problem? I don't see anything in the generated source that looks problematic. Do you have an testable example of the issue that doesn't involve Node?
Hide
David Nolen added a comment -

Already resolved

Show
David Nolen added a comment - Already resolved

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: