Issue #1354, 'in' with splatted arrays.
This commit is contained in:
parent
15ddb8e2ea
commit
d91ccd4003
13
lib/nodes.js
13
lib/nodes.js
|
@ -1727,7 +1727,18 @@
|
|||
In.prototype.children = ['object', 'array'];
|
||||
In.prototype.invert = NEGATE;
|
||||
In.prototype.compileNode = function(o) {
|
||||
if (this.array instanceof Value && this.array.isArray()) {
|
||||
var isArray, obj, splat, _i, _len, _ref2;
|
||||
isArray = this.array instanceof Value && this.array.isArray();
|
||||
if (isArray) {
|
||||
_ref2 = this.array.base.objects;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
obj = _ref2[_i];
|
||||
if (obj instanceof Splat) {
|
||||
splat = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isArray && !splat) {
|
||||
return this.compileOrTest(o);
|
||||
} else {
|
||||
return this.compileLoopTest(o);
|
||||
|
|
|
@ -1355,7 +1355,9 @@ exports.In = class In extends Base
|
|||
invert: NEGATE
|
||||
|
||||
compileNode: (o) ->
|
||||
if @array instanceof Value and @array.isArray()
|
||||
isArray = @array instanceof Value and @array.isArray()
|
||||
splat = obj for obj in @array.base.objects when obj instanceof Splat if isArray
|
||||
if isArray and not splat
|
||||
@compileOrTest o
|
||||
else
|
||||
@compileLoopTest o
|
||||
|
|
|
@ -187,6 +187,10 @@ test "#768: `in` should preserve evaluation order", ->
|
|||
test "#1099: empty array after `in` should compile to `false`", ->
|
||||
eq 1, [5 in []].length
|
||||
eq false, do -> return 0 in []
|
||||
|
||||
test "#1354: optimized `in` checks should not happen when splats are present", ->
|
||||
a = [6, 9]
|
||||
eq 9 in [3, a...], true
|
||||
|
||||
|
||||
# Chained Comparison
|
||||
|
|
Loading…
Reference in New Issue