fixed a bug where `in` malfunctioned in commaed lists
This commit is contained in:
parent
880c5c8083
commit
2f7c076a50
|
@ -192,7 +192,7 @@
|
||||||
if (match = HEREGEX.exec(this.chunk)) {
|
if (match = HEREGEX.exec(this.chunk)) {
|
||||||
return this.heregexToken(match);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(match = REGEX.exec(this.chunk))) {
|
if (!(match = REGEX.exec(this.chunk))) {
|
||||||
|
|
13
lib/nodes.js
13
lib/nodes.js
|
@ -993,7 +993,7 @@
|
||||||
delete o.top;
|
delete o.top;
|
||||||
return ifn.compile(o);
|
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);
|
return this.compileConditional(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1389,7 +1389,7 @@
|
||||||
};
|
};
|
||||||
Op.prototype.isChainable = function() {
|
Op.prototype.isChainable = function() {
|
||||||
var _ref2;
|
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() {
|
Op.prototype.invert = function() {
|
||||||
var op;
|
var op;
|
||||||
|
@ -1486,13 +1486,8 @@
|
||||||
}), {
|
}), {
|
||||||
precompile: true
|
precompile: true
|
||||||
}), sub = _ref2[0], ref = _ref2[1];
|
}), sub = _ref2[0], ref = _ref2[1];
|
||||||
code = utility('indexOf') + (".call(" + (this.array.compile(o)) + ", " + ref + ") ");
|
code = utility('indexOf') + (".call(" + (this.array.compile(o)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
|
||||||
code += this.negated ? '< 0' : '>= 0';
|
return sub === ref ? code : "(" + sub + ", " + code + ")";
|
||||||
if (sub === ref) {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
code = sub + ', ' + code;
|
|
||||||
return this.parenthetical ? code : "(" + code + ")";
|
|
||||||
};
|
};
|
||||||
In.prototype.toString = function(idt) {
|
In.prototype.toString = function(idt) {
|
||||||
return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
|
return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
|
||||||
|
|
|
@ -45,9 +45,9 @@
|
||||||
if (!token || levels < 0) {
|
if (!token || levels < 0) {
|
||||||
return action.call(this, token, i - 1);
|
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;
|
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;
|
levels -= 1;
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -154,7 +154,7 @@
|
||||||
};
|
};
|
||||||
return this.scanTokens(function(token, i, tokens) {
|
return this.scanTokens(function(token, i, tokens) {
|
||||||
var _ref, idx, tag, tok;
|
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);
|
stack.push(tag === 'INDENT' && this.tag(i - 1) === '{' ? '{' : tag);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@
|
||||||
}
|
}
|
||||||
return this.scanTokens(function(token, i, tokens) {
|
return this.scanTokens(function(token, i, tokens) {
|
||||||
var _ref, inv, match, mtag, oppos, tag, val;
|
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);
|
stack.push(token);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1273,11 +1273,9 @@ exports.In = class In extends Base
|
||||||
|
|
||||||
compileLoopTest: (o) ->
|
compileLoopTest: (o) ->
|
||||||
[sub, ref] = @object.compileReference merge(o, top: yes), precompile: yes
|
[sub, ref] = @object.compileReference merge(o, top: yes), precompile: yes
|
||||||
code = utility('indexOf') + ".call(#{ @array.compile o }, #{ref}) "
|
code = utility('indexOf') + ".call(#{ @array.compile o }, #{ref}) " +
|
||||||
code += (if @negated then '< 0' else '>= 0')
|
if @negated then '< 0' else '>= 0'
|
||||||
return code if sub is ref
|
if sub is ref then code else "(#{sub}, #{code})"
|
||||||
code = sub + ', ' + code
|
|
||||||
if @parenthetical then code else "(#{code})"
|
|
||||||
|
|
||||||
toString: (idt) ->
|
toString: (idt) ->
|
||||||
super idt, @constructor.name + if @negated then '!' else ''
|
super idt, @constructor.name + if @negated then '!' else ''
|
||||||
|
|
|
@ -153,6 +153,9 @@ b = -> share++ if share is 1
|
||||||
c = -> share++ if share is 2
|
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.
|
# Operators should respect new lines as spaced.
|
||||||
a = (123) +
|
a = (123) +
|
||||||
|
|
Loading…
Reference in New Issue