CoffeeScript-in-CoffeeScript can compile dotted accessors

This commit is contained in:
Jeremy Ashkenas
2010-02-08 23:42:03 -05:00
parent 32098e5a13
commit cb57a1ca1f
4 changed files with 45 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
(function(){
var CallNode, CommentNode, Expressions, ExtendsNode, LiteralNode, Node, ReturnNode, TAB, TRAILING_WHITESPACE, ValueNode, any, compact, del, dup, flatten, inherit, merge, statement;
var AccessorNode, 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.
@@ -553,7 +553,8 @@
},
push: function push(prop) {
this.properties.push(prop);
return this.children.push(prop);
this.children.push(prop);
return this;
},
has_properties: function has_properties() {
return this.properties.length || this.base instanceof ThisNode;
@@ -640,7 +641,8 @@
},
push: function push(arg) {
this.args.push(arg);
return this.children.push(arg);
this.children.push(arg);
return this;
},
// Compile a vanilla function call.
compile_node: function compile_node(o) {
@@ -718,4 +720,18 @@
}
}));
statement(ExtendsNode);
// A dotted accessor into a part of a value, or the :: shorthand for
// an accessor into the object's prototype.
AccessorNode = (exports.AccessorNode = inherit(Node, {
constructor: function constructor(name, tag) {
this.name = name;
this.children = [this.name];
this.prototype = tag === 'prototype';
this.soak = tag === 'soak';
return this;
},
compile_node: function compile_node(o) {
return '.' + (this.prototype ? 'prototype.' : '') + this.name.compile(o);
}
}));
})();