fixed a bug where `in` malfunctioned in commaed lists

This commit is contained in:
satyr 2010-10-21 22:13:39 +09:00
parent 880c5c8083
commit 2f7c076a50
5 changed files with 16 additions and 20 deletions

View File

@ -192,7 +192,7 @@
if (match = HEREGEX.exec(this.chunk)) {
return this.heregexToken(match);
}
if (_ref2 = this.tag(), __indexOf.call(NOT_REGEX, _ref2) >= 0) {
if ((_ref2 = this.tag(), __indexOf.call(NOT_REGEX, _ref2) >= 0)) {
return false;
}
if (!(match = REGEX.exec(this.chunk))) {

View File

@ -993,7 +993,7 @@
delete o.top;
return ifn.compile(o);
}
if (_ref2 = this.context, __indexOf.call(this.CONDITIONAL, _ref2) >= 0) {
if ((_ref2 = this.context, __indexOf.call(this.CONDITIONAL, _ref2) >= 0)) {
return this.compileConditional(o);
}
}
@ -1389,7 +1389,7 @@
};
Op.prototype.isChainable = function() {
var _ref2;
return _ref2 = this.operator, __indexOf.call(this.CHAINABLE, _ref2) >= 0;
return (_ref2 = this.operator, __indexOf.call(this.CHAINABLE, _ref2) >= 0);
};
Op.prototype.invert = function() {
var op;
@ -1486,13 +1486,8 @@
}), {
precompile: true
}), sub = _ref2[0], ref = _ref2[1];
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 + ")";
code = utility('indexOf') + (".call(" + (this.array.compile(o)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
return sub === ref ? code : "(" + sub + ", " + code + ")";
};
In.prototype.toString = function(idt) {
return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));

View File

@ -45,9 +45,9 @@
if (!token || levels < 0) {
return action.call(this, token, i - 1);
}
if (_ref = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) {
if ((_ref = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0)) {
levels += 1;
} else if (_ref2 = token[0], __indexOf.call(EXPRESSION_END, _ref2) >= 0) {
} else if ((_ref2 = token[0], __indexOf.call(EXPRESSION_END, _ref2) >= 0)) {
levels -= 1;
}
i += 1;
@ -154,7 +154,7 @@
};
return this.scanTokens(function(token, i, tokens) {
var _ref, idx, tag, tok;
if (_ref = tag = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) {
if ((_ref = tag = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0)) {
stack.push(tag === 'INDENT' && this.tag(i - 1) === '{' ? '{' : tag);
return 1;
}
@ -326,7 +326,7 @@
}
return this.scanTokens(function(token, i, tokens) {
var _ref, inv, match, mtag, oppos, tag, val;
if (_ref = tag = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0) {
if ((_ref = tag = token[0], __indexOf.call(EXPRESSION_START, _ref) >= 0)) {
stack.push(token);
return 1;
}

View File

@ -1273,11 +1273,9 @@ exports.In = class In extends Base
compileLoopTest: (o) ->
[sub, ref] = @object.compileReference merge(o, top: yes), precompile: yes
code = utility('indexOf') + ".call(#{ @array.compile o }, #{ref}) "
code += (if @negated then '< 0' else '>= 0')
return code if sub is ref
code = sub + ', ' + code
if @parenthetical then code else "(#{code})"
code = utility('indexOf') + ".call(#{ @array.compile o }, #{ref}) " +
if @negated then '< 0' else '>= 0'
if sub is ref then code else "(#{sub}, #{code})"
toString: (idt) ->
super idt, @constructor.name + if @negated then '!' else ''

View File

@ -151,7 +151,10 @@ share = 0
a = -> share++ if share is 0
b = -> share++ if share is 1
c = -> share++ if share is 2
ok a() not in [b(),c()] and share is 3
ok a() not in [b(),c()] and share is 3
# `in` with cache and `__indexOf` should work in commaed lists
eq [Object() in Array()].length, 1
# Operators should respect new lines as spaced.