Fixing external constructors / order of execution for once and for all ... knock on wood.

This commit is contained in:
Jeremy Ashkenas
2011-05-10 09:24:20 -04:00
parent f4b8e19c7f
commit 6d6e07604e
3 changed files with 24 additions and 21 deletions

View File

@@ -1032,12 +1032,12 @@
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
bvar = _ref2[_i];
bname = bvar.compile(o);
_results.push(this.ctor.body.unshift(new Literal("this." + bname + " = " + (utility('bind')) + "(this." + bname + ", this);")));
_results.push(this.ctor.body.unshift(new Literal("this." + bname + " = " + (utility('bind')) + "(this." + bname + ", this)")));
}
return _results;
}
};
Class.prototype.addProperties = function(node, name) {
Class.prototype.addProperties = function(node, name, o) {
var assign, base, exprs, func, props;
props = node.base.properties.slice(0);
exprs = (function() {
@@ -1058,8 +1058,8 @@
if (func instanceof Code) {
assign = this.ctor = func;
} else {
assign = null;
this.ctor = new Assign(new Value(new Literal(name)), func);
this.externalCtor = o.scope.freeVariable('class');
assign = new Assign(new Literal(this.externalCtor), func);
}
} else {
if (!assign.variable["this"]) {
@@ -1077,7 +1077,7 @@
}).call(this);
return compact(exprs);
};
Class.prototype.walkBody = function(name) {
Class.prototype.walkBody = function(name, o) {
return this.traverseChildren(false, __bind(function(child) {
var exps, i, node, _len, _ref2;
if (child instanceof Class) {
@@ -1088,7 +1088,7 @@
for (i = 0, _len = _ref2.length; i < _len; i++) {
node = _ref2[i];
if (node instanceof Value && node.isObject(true)) {
exps[i] = this.addProperties(node, name);
exps[i] = this.addProperties(node, name, o);
}
}
return child.expressions = exps = flatten(exps);
@@ -1099,7 +1099,10 @@
if (!this.ctor) {
this.ctor = new Code;
if (this.parent) {
this.ctor.body.push(new Call('super', [new Splat(new Literal('arguments'))]));
this.ctor.body.push(new Literal("" + name + ".__super__.constructor.apply(this, arguments)"));
}
if (this.externalCtor) {
this.ctor.body.push(new Literal("return " + this.externalCtor + ".apply(this, arguments)"));
}
this.body.expressions.unshift(this.ctor);
}
@@ -1113,7 +1116,7 @@
name = decl || this.name || '_Class';
lname = new Literal(name);
this.setContext(name);
this.walkBody(name);
this.walkBody(name, o);
this.ensureConstructor(name);
if (this.parent) {
this.body.expressions.unshift(new Extends(lname, this.parent));