using Underscore's compact in the code generation, insstead of our home-rolled one.

This commit is contained in:
Jeremy Ashkenas
2010-02-13 02:30:47 -05:00
parent 1ab3b183a8
commit 2c4c4cc93e
2 changed files with 11 additions and 27 deletions

View File

@@ -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, _, compact, 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, dup, flatten, inherit, merge, statement;
var __hasProp = Object.prototype.hasOwnProperty;
process.mixin(require('./scope'));
_ = require('./underscore')._;
@@ -24,18 +24,6 @@
}
return memo;
};
// Remove all null values from an array.
compact = function compact(input) {
var __a, __b, __c, item;
__a = []; __b = input;
for (__c = 0; __c < __b.length; __c++) {
item = __b[__c];
if ((typeof item !== "undefined" && item !== null)) {
__a.push(item);
}
}
return __a;
};
// Dup an array or object.
dup = function dup(input) {
var __a, __b, __c, __d, key, output, val;
@@ -199,7 +187,7 @@
Expressions = (exports.Expressions = inherit(Node, {
type: 'Expressions',
constructor: function constructor(nodes) {
this.children = (this.expressions = compact(flatten(nodes || [])));
this.children = (this.expressions = _.compact(flatten(nodes || [])));
return this;
},
// Tack an expression on to the end of this expression list.
@@ -944,7 +932,7 @@
ASSIGNMENT: ['||=', '&&=', '?='],
PREFIX_OPERATORS: ['typeof', 'delete'],
constructor: function constructor(operator, first, second, flip) {
this.children = compact([(this.first = first), (this.second = second)]);
this.children = _.compact([(this.first = first), (this.second = second)]);
this.operator = this.CONVERSIONS[operator] || operator;
this.flip = !!flip;
return this;
@@ -1016,7 +1004,7 @@
TryNode = (exports.TryNode = inherit(Node, {
type: 'Try',
constructor: function constructor(attempt, error, recovery, ensure) {
this.children = compact([(this.attempt = attempt), (this.recovery = recovery), (this.ensure = ensure)]);
this.children = _.compact([(this.attempt = attempt), (this.recovery = recovery), (this.ensure = ensure)]);
this.error = error;
return this;
},
@@ -1105,7 +1093,7 @@
this.name = __a[0];
this.index = __a[1];
}
this.children = compact([this.body, this.source, this.filter]);
this.children = _.compact([this.body, this.source, this.filter]);
return this;
},
top_sensitive: function top_sensitive() {
@@ -1196,7 +1184,7 @@
this.condition = condition;
this.body = body && body.unwrap();
this.else_body = else_body && else_body.unwrap();
this.children = compact([this.condition, this.body, this.else_body]);
this.children = _.compact([this.condition, this.body, this.else_body]);
this.tags = tags || {};
if (this.condition instanceof Array) {
this.multiple = true;