mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
made In node invertible
This commit is contained in:
47
lib/nodes.js
47
lib/nodes.js
@@ -1019,6 +1019,10 @@
|
||||
};
|
||||
Assign.prototype.compilePatternMatch = function(o) {
|
||||
var _len, _ref2, _ref3, accessClass, assigns, code, i, idx, isObject, obj, objects, olength, otop, ref, splat, top, val, valVar, value;
|
||||
top = del(o, 'top');
|
||||
otop = merge(o, {
|
||||
top: true
|
||||
});
|
||||
if ((value = this.value).isStatement(o)) {
|
||||
value = Closure.wrap(value);
|
||||
}
|
||||
@@ -1027,7 +1031,7 @@
|
||||
return value.compile(o);
|
||||
}
|
||||
isObject = this.variable.isObject();
|
||||
if (o.top && olength === 1 && !((obj = objects[0]) instanceof Splat)) {
|
||||
if (top && olength === 1 && !((obj = objects[0]) instanceof Splat)) {
|
||||
if (obj instanceof Assign) {
|
||||
_ref2 = obj, idx = _ref2.variable.base, obj = _ref2.value;
|
||||
} else {
|
||||
@@ -1035,12 +1039,8 @@
|
||||
}
|
||||
accessClass = IDENTIFIER.test(idx.value) ? Accessor : Index;
|
||||
(value = Value.wrap(value)).properties.push(new accessClass(idx));
|
||||
return new Assign(obj, value).compile(o);
|
||||
return new Assign(obj, value).compile(otop);
|
||||
}
|
||||
top = del(o, 'top');
|
||||
otop = merge(o, {
|
||||
top: true
|
||||
});
|
||||
valVar = value.compile(o);
|
||||
assigns = [];
|
||||
splat = false;
|
||||
@@ -1345,6 +1345,9 @@
|
||||
exports.Op = (function() {
|
||||
Op = (function() {
|
||||
function Op(op, first, second, flip) {
|
||||
if (op === 'in') {
|
||||
return new In(first, second);
|
||||
}
|
||||
if (op === 'new') {
|
||||
if (first instanceof Call) {
|
||||
return first.newInstance();
|
||||
@@ -1452,25 +1455,29 @@
|
||||
})();
|
||||
__extends(In, Base);
|
||||
In.prototype.children = ['object', 'array'];
|
||||
In.prototype.invert = function() {
|
||||
this.negated = !this.negated;
|
||||
return this;
|
||||
};
|
||||
In.prototype.compileNode = function(o) {
|
||||
var code;
|
||||
code = this.array instanceof Value && this.array.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
|
||||
return this.parenthetical ? code : "(" + code + ")";
|
||||
return this.array instanceof Value && this.array.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
|
||||
};
|
||||
In.prototype.compileOrTest = function(o) {
|
||||
var _len, _ref2, _ref3, _result, i, item, ref, sub, tests;
|
||||
var _len, _ref2, _ref3, _ref4, _result, cmp, cnj, i, item, ref, sub, tests;
|
||||
_ref2 = this.object.compileReference(o, {
|
||||
precompile: true
|
||||
}), sub = _ref2[0], ref = _ref2[1];
|
||||
_ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
|
||||
tests = (function() {
|
||||
_result = [];
|
||||
for (i = 0, _len = (_ref3 = this.array.base.objects).length; i < _len; i++) {
|
||||
item = _ref3[i];
|
||||
_result.push("" + (i ? ref : sub) + " === " + (item.compile(o)));
|
||||
for (i = 0, _len = (_ref4 = this.array.base.objects).length; i < _len; i++) {
|
||||
item = _ref4[i];
|
||||
_result.push((i ? ref : sub) + cmp + item.compile(o));
|
||||
}
|
||||
return _result;
|
||||
}).call(this);
|
||||
return tests.join(' || ');
|
||||
tests = tests.join(cnj);
|
||||
return this.parenthetical ? tests : "(" + tests + ")";
|
||||
};
|
||||
In.prototype.compileLoopTest = function(o) {
|
||||
var _ref2, code, ref, sub;
|
||||
@@ -1479,8 +1486,16 @@
|
||||
}), {
|
||||
precompile: true
|
||||
}), sub = _ref2[0], ref = _ref2[1];
|
||||
code = utility('indexOf') + (".call(" + (this.array.compile(o)) + ", " + ref + ") >= 0");
|
||||
return sub === ref ? code : sub + ', ' + code;
|
||||
code = utility('indexOf') + (".call(" + (this.array.compile(o)) + ", " + ref + ") ");
|
||||
code += this.negated ? '< 0' : '>= 0';
|
||||
if (sub === ref) {
|
||||
return code;
|
||||
}
|
||||
code = sub + ', ' + code;
|
||||
return this.parenthetical ? code : "(" + code + ")";
|
||||
};
|
||||
In.prototype.toString = function(idt) {
|
||||
return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
|
||||
};
|
||||
return In;
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user