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

done refactoring Class for now...

This commit is contained in:
Jeremy Ashkenas 2010-11-13 18:02:50 -05:00
parent 9a5546c8e9
commit 6f47364392
3 changed files with 33 additions and 51 deletions

View file

@ -149,7 +149,7 @@ runTests = (CoffeeScript) ->
CoffeeScript.run code.toString(), {fileName} CoffeeScript.run code.toString(), {fileName}
catch err catch err
failedTests += 1 failedTests += 1
log "failed #{fileName}", red, '\n' + err.stack.toString() log "failed #{fileName}", red, '\n' + err.stack?.toString()
task 'test', 'run the CoffeeScript language test suite', -> task 'test', 'run the CoffeeScript language test suite', ->

View file

@ -881,41 +881,28 @@
return _results; return _results;
}; };
Class.prototype.walkBody = function(name) { Class.prototype.walkBody = function(name) {
var exps, _fn, _len, _ref; return this.traverseChildren(false, __bind(function(child) {
_ref = exps = this.body.expressions; var exps, i, node, _len, _ref;
_fn = function(node, i) { if (child instanceof Expressions) {
if (node instanceof Value && node.isObject(true)) { _ref = exps = child.expressions;
return exps[i] = compact(this.addProperties(node, name)); for (i = 0, _len = _ref.length; i < _len; i++) {
} else if (node instanceof Code) { node = _ref[i];
if (this.ctor) { if (node instanceof Value && node.isObject(true)) {
throw new Error('cannot define more than one constructor in a class'); exps[i] = compact(this.addProperties(node, name));
} } else if (node instanceof Code) {
if (node.bound) { if (this.ctor) {
throw new Error('cannot define a constructor as a bound function'); throw new Error('cannot define more than one constructor in a class');
}
this.ctor = node;
return exps[i] = null;
} else {
return node.traverseChildren(false, __bind(function(n2) {
var expr2, j, _len, _ref;
if (n2 instanceof Expressions) {
_ref = n2.expressions;
for (j = 0, _len = _ref.length; j < _len; j++) {
expr2 = _ref[j];
if (expr2 instanceof Value && expr2.isObject(true)) {
n2.expressions[j] = compact(this.addProperties(expr2, name));
}
} }
return n2.expressions = flatten(n2.expressions); if (node.bound) {
throw new Error('cannot define a constructor as a bound function');
}
this.ctor = node;
exps[i] = null;
} }
}, this)); }
return child.expressions = exps = compact(flatten(exps));
} }
}; }, this));
for (i = 0, _len = _ref.length; i < _len; i++) {
node = _ref[i];
_fn.call(this, node, i);
}
return this.body.expressions = exps = compact(flatten(exps));
}; };
Class.prototype.ensureConstructor = function(name) { Class.prototype.ensureConstructor = function(name) {
if (!this.ctor) { if (!this.ctor) {

View file

@ -712,24 +712,19 @@ exports.Class = class Class extends Base
# Walk the body of the class, looking for prototype properties to be converted. # Walk the body of the class, looking for prototype properties to be converted.
walkBody: (name) -> walkBody: (name) ->
for node, i in exps = @body.expressions @traverseChildren false, (child) =>
if node instanceof Value and node.isObject(true) if child instanceof Expressions
exps[i] = compact @addProperties node, name for node, i in exps = child.expressions
else if node instanceof Code if node instanceof Value and node.isObject(true)
if @ctor exps[i] = compact @addProperties node, name
throw new Error 'cannot define more than one constructor in a class' else if node instanceof Code
if node.bound if @ctor
throw new Error 'cannot define a constructor as a bound function' throw new Error 'cannot define more than one constructor in a class'
@ctor = node if node.bound
exps[i] = null throw new Error 'cannot define a constructor as a bound function'
else @ctor = node
node.traverseChildren false, (n2) => exps[i] = null
if n2 instanceof Expressions child.expressions = exps = compact flatten exps
for expr2, j in n2.expressions
if expr2 instanceof Value and expr2.isObject(true)
n2.expressions[j] = compact @addProperties expr2, name
n2.expressions = flatten n2.expressions
@body.expressions = exps = compact flatten exps
# Make sure that a constructor is defined for the class, and properly # Make sure that a constructor is defined for the class, and properly
# configured. # configured.