let's try to merge these indexOf patches.

This commit is contained in:
Jeremy Ashkenas
2010-10-19 23:27:15 -04:00
parent c1d24944dc
commit 113d7ce98f
9 changed files with 113 additions and 114 deletions

View File

@@ -1,14 +1,17 @@
(function() {
var Accessor, ArrayLiteral, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, Literal, NO, NUMBER, ObjectLiteral, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, _ref, compact, del, ends, flatten, include, last, merge, starts, utility;
var Accessor, ArrayLiteral, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, Literal, NO, NUMBER, ObjectLiteral, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, _ref, compact, del, ends, flatten, last, merge, starts, utility;
var __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
}, __indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) if (this[i] === item) return i;
return -1;
};
Scope = require('./scope').Scope;
_ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, merge = _ref.merge, del = _ref.del, include = _ref.include, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
_ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, merge = _ref.merge, del = _ref.del, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
YES = function() {
return true;
};
@@ -983,7 +986,7 @@
Assign.prototype.children = ['variable', 'value'];
Assign.prototype.topSensitive = YES;
Assign.prototype.compileNode = function(o) {
var ifn, isValue, match, name, stmt, top, val;
var _ref2, ifn, isValue, match, name, stmt, top, val;
if (isValue = this.variable instanceof Value) {
if (this.variable.isArray() || this.variable.isObject()) {
return this.compilePatternMatch(o);
@@ -995,7 +998,7 @@
delete o.top;
return ifn.compile(o);
}
if (include(this.CONDITIONAL, this.context)) {
if (_ref2 = this.context, __indexOf.call(this.CONDITIONAL, _ref2) >= 0) {
return this.compileConditional(o);
}
}
@@ -1391,7 +1394,8 @@
return this.operator !== '!' || this.first.isComplex();
};
Op.prototype.isChainable = function() {
return include(this.CHAINABLE, this.operator);
var _ref2;
return (_ref2 = this.operator, __indexOf.call(this.CHAINABLE, _ref2) >= 0);
};
Op.prototype.invert = function() {
var _ref2;
@@ -1404,12 +1408,12 @@
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
};
Op.prototype.compileNode = function(o) {
var ifn;
var _ref2, ifn;
if (this.isChainable() && this.first.unwrap().isChainable()) {
return this.compileChain(o);
}
if (this.isUnary()) {
if (include(this.MUTATORS, this.operator) && (ifn = If.unfoldSoak(o, this, 'first'))) {
if ((_ref2 = this.operator, __indexOf.call(this.MUTATORS, _ref2) >= 0) && (ifn = If.unfoldSoak(o, this, 'first'))) {
return ifn.compile(o);
}
return this.compileUnary(o);
@@ -1439,8 +1443,8 @@
return new Existence(fst).compile(o) + (" ? " + ref + " : " + (this.second.compile(o)));
};
Op.prototype.compileUnary = function(o) {
var parts, space;
space = include(this.PREFIX_OPERATORS, this.operator) ? ' ' : '';
var _ref2, parts, space;
space = (_ref2 = this.operator, __indexOf.call(this.PREFIX_OPERATORS, _ref2) >= 0) ? ' ' : '';
parts = [this.operator, space, this.first.compile(o)];
return (this.flip ? parts.reverse() : parts).join('');
};
@@ -1480,14 +1484,15 @@
return "(" + (tests.join(' || ')) + ")";
};
In.prototype.compileLoopTest = function(o) {
var _ref2, obj1, obj2, prefix;
var _ref2, code, obj1, obj2, prefix;
_ref2 = this.object.compileReference(merge(o, {
top: true
}), {
precompile: true
}), obj1 = _ref2[0], obj2 = _ref2[1];
prefix = obj1 !== obj2 ? ("" + obj1 + ", ") : '';
return "(" + prefix + (utility('indexOf')) + ".call(" + (this.array.compile(o)) + ", " + obj2 + ") >= 0)";
code = ("" + prefix + (utility('indexOf')) + ".call(" + (this.array.compile(o)) + ", " + obj2 + ") >= 0");
return this.parenthetical ? code : ("(" + code + ")");
};
return In;
})();