mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 02:51:25 -05:00
Self-compiler: array literals
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(function(){
|
||||
var AccessorNode, AssignNode, CallNode, CommentNode, Expressions, ExtendsNode, IndexNode, LiteralNode, Node, ObjectNode, RangeNode, ReturnNode, SliceNode, TAB, TRAILING_WHITESPACE, ThisNode, ValueNode, any, compact, del, dup, flatten, inherit, merge, statement;
|
||||
var AccessorNode, ArrayNode, AssignNode, CallNode, CommentNode, Expressions, ExtendsNode, IndexNode, LiteralNode, Node, ObjectNode, RangeNode, ReturnNode, SliceNode, TAB, TRAILING_WHITESPACE, ThisNode, 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.
|
||||
@@ -786,6 +786,37 @@
|
||||
return '{\n' + props.join('') + '\n' + this.idt() + '}';
|
||||
}
|
||||
}));
|
||||
// An array literal.
|
||||
ArrayNode = (exports.ArrayNode = inherit(Node, {
|
||||
constructor: function constructor(objects) {
|
||||
this.children = (this.objects = objects || []);
|
||||
return this;
|
||||
},
|
||||
compile_node: function compile_node(o) {
|
||||
var __a, __b, code, ending, i, obj, objects;
|
||||
o.indent = this.idt(1);
|
||||
objects = (function() {
|
||||
__a = []; __b = this.objects;
|
||||
for (i = 0; i < __b.length; i++) {
|
||||
obj = __b[i];
|
||||
__a.push((function() {
|
||||
code = obj.compile(o);
|
||||
if (obj instanceof CommentNode) {
|
||||
return '\n' + code + '\n' + o.indent;
|
||||
} else if (i === this.objects.length - 1) {
|
||||
return code;
|
||||
} else {
|
||||
return code + ', ';
|
||||
}
|
||||
}).call(this));
|
||||
}
|
||||
return __a;
|
||||
}).call(this);
|
||||
objects = objects.join('');
|
||||
ending = objects.indexOf('\n') >= 0 ? "\n" + this.idt() + ']' : ']';
|
||||
return '[' + objects + ending;
|
||||
}
|
||||
}));
|
||||
// Setting the value of a local variable, or the value of an object property.
|
||||
AssignNode = (exports.AssignNode = inherit(Node, {
|
||||
// Keep the identifier regex in sync with the Lexer.
|
||||
|
||||
Reference in New Issue
Block a user