mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fixing external constructors / order of execution for once and for all ... knock on wood.
This commit is contained in:
19
lib/nodes.js
19
lib/nodes.js
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user