nodes: no longer uses helpers.indexOf

This commit is contained in:
satyr
2010-10-11 09:40:41 +09:00
parent c437f0b14b
commit acafb1b53a
2 changed files with 32 additions and 37 deletions

View File

@@ -1,5 +1,5 @@
(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, indexOf, 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, include, last, merge, starts, utility;
var __extends = function(child, parent) {
var ctor = function() {};
ctor.prototype = parent.prototype;
@@ -9,7 +9,7 @@
child.__super__ = parent.prototype;
};
Scope = require('./scope').Scope;
_ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, merge = _ref.merge, del = _ref.del, include = _ref.include, indexOf = _ref.indexOf, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
_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;
YES = function() {
return true;
};
@@ -843,24 +843,22 @@
return Splat.compileSplattedArray(this.objects, o);
};
ArrayLiteral.prototype.compileNode = function(o) {
var _len, _ref2, code, i, obj, objects;
var _i, _len, _len2, _ref2, _ref3, code, i, obj, objects;
o.indent = this.idt(1);
objects = [];
for (i = 0, _len = (_ref2 = this.objects).length; i < _len; i++) {
obj = _ref2[i];
code = obj.compile(o);
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
obj = _ref2[_i];
if (obj instanceof Splat) {
return this.compileSplatLiteral(o);
} else if (obj instanceof Comment) {
objects.push("\n" + code + "\n" + (o.indent));
} else if (i === this.objects.length - 1) {
objects.push(code);
} else {
objects.push("" + code + ", ");
}
}
objects = [];
for (i = 0, _len2 = (_ref3 = this.objects).length; i < _len2; i++) {
obj = _ref3[i];
code = obj.compile(o);
objects.push(obj instanceof Comment ? ("\n" + code + "\n" + (o.indent)) : (i === this.objects.length - 1 ? code : code + ', '));
}
objects = objects.join('');
return indexOf(objects, '\n') >= 0 ? ("[\n" + (this.idt(1)) + objects + "\n" + (this.tab) + "]") : ("[" + objects + "]");
return 0 < objects.indexOf('\n') ? ("[\n" + (o.indent) + objects + "\n" + (this.tab) + "]") : ("[" + objects + "]");
};
return ArrayLiteral;
})();
@@ -919,7 +917,7 @@
func.name = className;
func.body.push(new Return(new Literal('this')));
variable = new Value(variable);
variable.namespaced = include(func.name, '.');
variable.namespaced = 0 < className.indexOf('.');
constructor = func;
continue;
}
@@ -1383,7 +1381,7 @@
if (this.isChainable() && this.first.unwrap() instanceof Op && this.first.unwrap().isChainable()) {
return this.compileChain(o);
}
if (indexOf(this.ASSIGNMENT, this.operator) >= 0) {
if (include(this.ASSIGNMENT, this.operator)) {
return this.compileAssignment(o);
}
if (this.isUnary()) {
@@ -1426,12 +1424,9 @@
};
Op.prototype.compileUnary = function(o) {
var parts, space;
space = indexOf(this.PREFIX_OPERATORS, this.operator) >= 0 ? ' ' : '';
space = include(this.PREFIX_OPERATORS, this.operator) ? ' ' : '';
parts = [this.operator, space, this.first.compile(o)];
if (this.flip) {
parts = parts.reverse();
}
return parts.join('');
return (this.flip ? parts.reverse() : parts).join('');
};
return Op;
})();