fixing the extends keyword when the expressions are complex, and should only be run once -- not that it's good style -- ticket #143

This commit is contained in:
Jeremy Ashkenas
2010-02-16 23:23:43 -05:00
parent bedc005d67
commit 0610e20a3c
6 changed files with 39 additions and 11 deletions

View File

@@ -480,11 +480,22 @@
},
// Hooking one constructor into another's prototype chain.
compile_node: function compile_node(o) {
var child, construct, parent;
var child, child_var, construct, parent, parent_var, prefix;
construct = o.scope.free_variable();
child = this.child.compile(o);
parent = this.parent.compile(o);
return this.idt() + construct + ' = function(){};\n' + this.idt() + construct + '.prototype = ' + parent + ".prototype;\n" + this.idt() + child + '.__superClass__ = ' + parent + ".prototype;\n" + this.idt() + child + '.prototype = new ' + construct + "();\n" + this.idt() + child + '.prototype.constructor = ' + child + ';';
prefix = '';
if (!(this.child instanceof ValueNode) || this.child.has_properties() || !(this.child.unwrap() instanceof LiteralNode)) {
child_var = o.scope.free_variable();
prefix += this.idt() + child_var + ' = ' + child + ';\n';
child = child_var;
}
if (!(this.parent instanceof ValueNode) || this.parent.has_properties() || !(this.parent.unwrap() instanceof LiteralNode)) {
parent_var = o.scope.free_variable();
prefix += this.idt() + parent_var + ' = ' + parent + ';\n';
parent = parent_var;
}
return prefix + this.idt() + construct + ' = function(){};\n' + this.idt() + construct + '.prototype = ' + parent + ".prototype;\n" + this.idt() + child + '.__superClass__ = ' + parent + ".prototype;\n" + this.idt() + child + '.prototype = new ' + construct + "();\n" + this.idt() + child + '.prototype.constructor = ' + child + ';';
}
}));
statement(ExtendsNode);