1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Issue #878. Namespaced classes should not leak their function name.

This commit is contained in:
Jeremy Ashkenas 2010-11-28 10:08:49 -08:00
parent adeace8f62
commit 1254efaddb
4 changed files with 16 additions and 7 deletions

View file

@ -1001,7 +1001,7 @@
return this.ctor.noReturn = true;
};
Class.prototype.compileNode = function(o) {
var decl, klass, lname, name, _ref;
var decl, klass, lname, name;
decl = this.determineName();
name = decl || this.name || '_Class';
lname = new Literal(name);
@ -1015,9 +1015,6 @@
this.body.expressions.push(lname);
this.addBoundFunctions(o);
klass = new Parens(new Call(new Code([], this.body)), true);
if (decl && ((_ref = this.variable) != null ? _ref.isComplex() : void 0)) {
klass = new Assign(new Value(lname), klass);
}
if (this.variable) {
klass = new Assign(this.variable, klass);
}

View file

@ -1,12 +1,12 @@
(function() {
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref;
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref;
var __indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (this[i] === item) return i;
}
return -1;
}, __slice = Array.prototype.slice;
exports.Rewriter = Rewriter = function() {
exports.Rewriter = function() {
function Rewriter() {}
Rewriter.prototype.rewrite = function(tokens) {
this.tokens = tokens;

View file

@ -819,7 +819,6 @@ exports.Class = class Class extends Base
@addBoundFunctions o
klass = new Parens new Call(new Code [], @body), true
klass = new Assign new Value(lname), klass if decl and @variable?.isComplex()
klass = new Assign @variable, klass if @variable
klass.compile o

View file

@ -305,3 +305,16 @@ eq robby.power(), 11
eq robby.speed(), Infinity
# Namespaced classes do not reserve their function name in outside scope.
one = {}
two = {}
class one.Klass
@label = "one"
class two.Klass
@label = "two"
eq typeof Klass, 'undefined'
eq one.Klass.label, 'one'
eq two.Klass.label, 'two'