New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: simple support for psuedo-namespaces #878
Comments
Another possibility discussed in IRC is that the output of:
could be identical to the output of this syntax:
In this case, |
How do the names conflict? Aren't they only referenced within the local closure? Are you talking about |
You're right, they are only referenced within the closure. However, if I create a class called It's definitely not a major problem (I'm using namespaced types right now with no issues), but I can see the potential for problems in certain edge cases. After tinkering with the CS source a bit more it does look like the second solution (in the comment after the OP) is the most correct one. |
Thanks for opening the ticket -- inner class names should have been used to name the function, but should not have been leaking to outer scope. Here's a patch that fixes the issue, with a test case. Please give it a read-over if you have a minute: Closing the ticket... |
When using JS frameworks, it's a common practice to create psuedo-namespaces for classes by creating a tree of dummy objects. For example:
While CoffeeScript technically supports this behavior, it names classes based on the last property access for the variable used in a
class
definition. For example, if I have a class namedA.B.SomeClass
, it will result in the following JavaScript to be generated:What I propose is that CoffeeScript instead name classes based on a concatenation of the property names used in the
class
definition. That is, for the same classA.B.SomeClass
, CS would generate:This would ensure that if
SomeClass
was also defined in another namespace, the two classes would not conflict. For classes not using psuedo-namespaces, their names would be unchanged.I believe this requires a simple change to
determineName
in theClass
node. I've implemented a working version on my fork at: nkohari/coffee-script@bff2261af7045010502c7d68d1a0da3a6ff5ecf3Any thoughts on the value of this?
Edit: noticed that my implementation clobbers the names of classes like Rewriter. So that's probably a bad thing. :)
The text was updated successfully, but these errors were encountered: