mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 02:51:25 -05:00
CoffeeScript-in-CoffeeScript is now able to compile subClass extends superClass
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(function(){
|
||||
var CallNode, CommentNode, Expressions, LiteralNode, Node, ReturnNode, TAB, TRAILING_WHITESPACE, ValueNode, any, compact, del, dup, flatten, inherit, merge, statement;
|
||||
var CallNode, CommentNode, Expressions, ExtendsNode, LiteralNode, Node, ReturnNode, TAB, TRAILING_WHITESPACE, ValueNode, any, compact, del, dup, flatten, inherit, merge, statement;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
process.mixin(require('./scope'));
|
||||
// The abstract base class for all CoffeeScript nodes.
|
||||
@@ -257,17 +257,14 @@
|
||||
};
|
||||
// Merge objects.
|
||||
merge = function merge(src, dest) {
|
||||
var __a, __b, key, val;
|
||||
dest[key] = (function() {
|
||||
__a = []; __b = src;
|
||||
for (key in __b) {
|
||||
val = __b[key];
|
||||
if (__hasProp.call(__b, key)) {
|
||||
__a.push(val);
|
||||
}
|
||||
var __a, key, val;
|
||||
__a = src;
|
||||
for (key in __a) {
|
||||
val = __a[key];
|
||||
if (__hasProp.call(__a, key)) {
|
||||
((dest[key] = val));
|
||||
}
|
||||
return __a;
|
||||
}).call(this);
|
||||
}
|
||||
return dest;
|
||||
};
|
||||
// Do any of the elements in the list pass a truth test?
|
||||
@@ -361,7 +358,7 @@
|
||||
var __a, __b, __c, __d, i, idt;
|
||||
idt = (this.indent || '');
|
||||
__c = 0; __d = (tabs || 0);
|
||||
for (__b=0, i=__c; (__c <= __d ? i <= __d : i >= __d); (__c <= __d ? i += 1 : i -= 1), __b++) {
|
||||
for (__b=0, i=__c; (__c <= __d ? i < __d : i > __d); (__c <= __d ? i += 1 : i -= 1), __b++) {
|
||||
idt += TAB;
|
||||
}
|
||||
return idt;
|
||||
@@ -702,4 +699,23 @@
|
||||
return [call, reference];
|
||||
}
|
||||
}));
|
||||
// Node to extend an object's prototype with an ancestor object.
|
||||
// After goog.inherits from the Closure Library.
|
||||
ExtendsNode = (exports.ExtendsNode = inherit(Node, {
|
||||
constructor: function constructor(child, parent) {
|
||||
this.child = child;
|
||||
this.parent = parent;
|
||||
this.children = [child, parent];
|
||||
return this;
|
||||
},
|
||||
// Hooking one constructor into another's prototype chain.
|
||||
compile_node: function compile_node(o) {
|
||||
var child, constructor, parent;
|
||||
constructor = o.scope.free_variable();
|
||||
child = this.child.compile(o);
|
||||
parent = this.parent.compile(o);
|
||||
return this.idt() + constructor + ' = function(){};\n' + this.idt() + constructor + '.prototype = ' + parent + ".prototype;\n" + this.idt() + child + '.__superClass__ = ' + parent + ".prototype;\n" + this.idt() + child + '.prototype = new ' + constructor + "();\n" + this.idt() + child + '.prototype.constructor = ' + child + ';';
|
||||
}
|
||||
}));
|
||||
statement(ExtendsNode);
|
||||
})();
|
||||
Reference in New Issue
Block a user