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}
catch err
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', ->

View file

@ -881,41 +881,28 @@
return _results;
};
Class.prototype.walkBody = function(name) {
var exps, _fn, _len, _ref;
_ref = exps = this.body.expressions;
_fn = function(node, i) {
if (node instanceof Value && node.isObject(true)) {
return exps[i] = compact(this.addProperties(node, name));
} else if (node instanceof Code) {
if (this.ctor) {
throw new Error('cannot define more than one constructor in a class');
}
if (node.bound) {
throw new Error('cannot define a constructor as a bound function');
}
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 this.traverseChildren(false, __bind(function(child) {
var exps, i, node, _len, _ref;
if (child instanceof Expressions) {
_ref = exps = child.expressions;
for (i = 0, _len = _ref.length; i < _len; i++) {
node = _ref[i];
if (node instanceof Value && node.isObject(true)) {
exps[i] = compact(this.addProperties(node, name));
} else if (node instanceof Code) {
if (this.ctor) {
throw new Error('cannot define more than one constructor in a class');
}
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));
}
};
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));
}, this));
};
Class.prototype.ensureConstructor = function(name) {
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.
walkBody: (name) ->
for node, i in exps = @body.expressions
if node instanceof Value and node.isObject(true)
exps[i] = compact @addProperties node, name
else if node instanceof Code
if @ctor
throw new Error 'cannot define more than one constructor in a class'
if node.bound
throw new Error 'cannot define a constructor as a bound function'
@ctor = node
exps[i] = null
else
node.traverseChildren false, (n2) =>
if n2 instanceof Expressions
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
@traverseChildren false, (child) =>
if child instanceof Expressions
for node, i in exps = child.expressions
if node instanceof Value and node.isObject(true)
exps[i] = compact @addProperties node, name
else if node instanceof Code
if @ctor
throw new Error 'cannot define more than one constructor in a class'
if node.bound
throw new Error 'cannot define a constructor as a bound function'
@ctor = node
exps[i] = null
child.expressions = exps = compact flatten exps
# Make sure that a constructor is defined for the class, and properly
# configured.