mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
fixing an improper-js-output bug when using a loop-compiled inarray clause as part of a larger expression
This commit is contained in:
10
lib/nodes.js
10
lib/nodes.js
@@ -1222,7 +1222,7 @@
|
|||||||
return "(" + (tests.join(' || ')) + ")";
|
return "(" + (tests.join(' || ')) + ")";
|
||||||
};
|
};
|
||||||
InNode.prototype.compileLoopTest = function(o) {
|
InNode.prototype.compileLoopTest = function(o) {
|
||||||
var _b, _c, body, i, l;
|
var _b, _c, i, l, prefix;
|
||||||
_b = this.array.compileReference(o, {
|
_b = this.array.compileReference(o, {
|
||||||
precompile: true
|
precompile: true
|
||||||
});
|
});
|
||||||
@@ -1231,12 +1231,8 @@
|
|||||||
_c = [o.scope.freeVariable(), o.scope.freeVariable()];
|
_c = [o.scope.freeVariable(), o.scope.freeVariable()];
|
||||||
i = _c[0];
|
i = _c[0];
|
||||||
l = _c[1];
|
l = _c[1];
|
||||||
body = ("!!(function(){ for (var " + i + "=0, " + l + "=" + (this.arr1) + ".length; " + i + "<" + l + "; " + i + "++) if (" + (this.arr2) + "[" + i + "] === " + this.obj2 + ") return true; })()");
|
prefix = this.obj1 !== this.obj2 ? this.obj1 + '; ' : '';
|
||||||
if (this.obj1 !== this.obj2) {
|
return "!!(function(){ " + (prefix) + "for (var " + i + "=0, " + l + "=" + (this.arr1) + ".length; " + i + "<" + l + "; " + i + "++) if (" + (this.arr2) + "[" + i + "] === " + this.obj2 + ") return true; })()";
|
||||||
return "" + this.obj1 + ";\n" + this.tab + body;
|
|
||||||
} else {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return InNode;
|
return InNode;
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1046,8 +1046,8 @@ exports.InNode: class InNode extends BaseNode
|
|||||||
compileLoopTest: (o) ->
|
compileLoopTest: (o) ->
|
||||||
[@arr1, @arr2]: @array.compileReference o, {precompile: yes}
|
[@arr1, @arr2]: @array.compileReference o, {precompile: yes}
|
||||||
[i, l]: [o.scope.freeVariable(), o.scope.freeVariable()]
|
[i, l]: [o.scope.freeVariable(), o.scope.freeVariable()]
|
||||||
body: "!!(function(){ for (var $i=0, $l=${@arr1}.length; $i<$l; $i++) if (${@arr2}[$i] === $@obj2) return true; })()"
|
prefix: if @obj1 isnt @obj2 then @obj1 + '; ' else ''
|
||||||
if @obj1 isnt @obj2 then "$@obj1;\n$@tab$body" else body
|
"!!(function(){ ${prefix}for (var $i=0, $l=${@arr1}.length; $i<$l; $i++) if (${@arr2}[$i] === $@obj2) return true; })()"
|
||||||
|
|
||||||
#### TryNode
|
#### TryNode
|
||||||
|
|
||||||
|
|||||||
@@ -46,3 +46,7 @@ ok 100 in [100, 200, 300]
|
|||||||
array: [100, 200, 300]
|
array: [100, 200, 300]
|
||||||
ok 100 in array
|
ok 100 in array
|
||||||
ok 1 not in array
|
ok 1 not in array
|
||||||
|
|
||||||
|
list: [1, 2, 7]
|
||||||
|
result: if list[2] in [7, 10] then 100 else -1
|
||||||
|
ok result is 100
|
||||||
Reference in New Issue
Block a user