mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 03:21:20 -05:00
using underscore's clone() for code generation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(function(){
|
||||
var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, _, del, dup, flatten, inherit, merge, statement;
|
||||
var AccessorNode, ArrayNode, AssignNode, CallNode, ClosureNode, CodeNode, CommentNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, Node, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThisNode, ThrowNode, TryNode, ValueNode, WhileNode, _, del, flatten, inherit, merge, statement;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
process.mixin(require('./scope'));
|
||||
_ = require('./underscore')._;
|
||||
@@ -24,28 +24,6 @@
|
||||
}
|
||||
return memo;
|
||||
};
|
||||
// Dup an array or object.
|
||||
dup = function dup(input) {
|
||||
var __a, __b, __c, __d, key, output, val;
|
||||
if (input instanceof Array) {
|
||||
__a = []; __b = input;
|
||||
for (__c = 0; __c < __b.length; __c++) {
|
||||
val = __b[__c];
|
||||
__a.push(val);
|
||||
}
|
||||
return __a;
|
||||
} else {
|
||||
output = {};
|
||||
__d = input;
|
||||
for (key in __d) {
|
||||
val = __d[key];
|
||||
if (__hasProp.call(__d, key)) {
|
||||
((output[key] = val));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
};
|
||||
// Merge objects.
|
||||
merge = function merge(src, dest) {
|
||||
var __a, __b, fresh, key, val;
|
||||
@@ -116,7 +94,7 @@
|
||||
// already been asked to return the result.
|
||||
Node.prototype.compile = function compile(o) {
|
||||
var closure, top;
|
||||
this.options = dup(o || {});
|
||||
this.options = _.clone(o || {});
|
||||
this.indent = o.indent;
|
||||
top = this.top_sensitive() ? this.options.top : del(this.options, 'top');
|
||||
closure = this.is_statement() && !this.is_statement_only() && !top && !this.options.returns && !(this instanceof CommentNode) && !this.contains(function(node) {
|
||||
@@ -226,7 +204,7 @@
|
||||
__a = []; __b = this.expressions;
|
||||
for (__c = 0; __c < __b.length; __c++) {
|
||||
node = __b[__c];
|
||||
__a.push(this.compile_expression(node, dup(o)));
|
||||
__a.push(this.compile_expression(node, _.clone(o)));
|
||||
}
|
||||
return __a;
|
||||
}).call(this)).join("\n");
|
||||
@@ -1257,7 +1235,7 @@
|
||||
compile_statement: function compile_statement(o) {
|
||||
var body, child, com_dent, cond_o, else_part, if_dent, if_part, prefix;
|
||||
child = del(o, 'chain_child');
|
||||
cond_o = dup(o);
|
||||
cond_o = _.clone(o);
|
||||
del(cond_o, 'returns');
|
||||
o.indent = this.idt(1);
|
||||
o.top = true;
|
||||
|
||||
Reference in New Issue
Block a user