1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

fixes #1100: precedence in or-test compilation of in

This commit is contained in:
Michael Ficarra 2011-08-07 03:43:41 -04:00
parent 803a7d06e3
commit 6608a7aa98
3 changed files with 8 additions and 3 deletions

View file

@ -1541,7 +1541,7 @@
_results = []; _results = [];
for (i = 0, _len = _ref4.length; i < _len; i++) { for (i = 0, _len = _ref4.length; i < _len; i++) {
item = _ref4[i]; item = _ref4[i];
_results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_OP)); _results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_ACCESS));
} }
return _results; return _results;
}).call(this); }).call(this);

View file

@ -1376,7 +1376,7 @@ exports.In = class In extends Base
[sub, ref] = @object.cache o, LEVEL_OP [sub, ref] = @object.cache o, LEVEL_OP
[cmp, cnj] = if @negated then [' !== ', ' && '] else [' === ', ' || '] [cmp, cnj] = if @negated then [' !== ', ' && '] else [' === ', ' || ']
tests = for item, i in @array.base.objects tests = for item, i in @array.base.objects
(if i then ref else sub) + cmp + item.compile o, LEVEL_OP (if i then ref else sub) + cmp + item.compile o, LEVEL_ACCESS
return 'false' if tests.length is 0 return 'false' if tests.length is 0
tests = tests.join cnj tests = tests.join cnj
if o.level < LEVEL_OP then tests else "(#{tests})" if o.level < LEVEL_OP then tests else "(#{tests})"

View file

@ -187,11 +187,16 @@ test "#768: `in` should preserve evaluation order", ->
test "#1099: empty array after `in` should compile to `false`", -> test "#1099: empty array after `in` should compile to `false`", ->
eq 1, [5 in []].length eq 1, [5 in []].length
eq false, do -> return 0 in [] eq false, do -> return 0 in []
test "#1354: optimized `in` checks should not happen when splats are present", -> test "#1354: optimized `in` checks should not happen when splats are present", ->
a = [6, 9] a = [6, 9]
eq 9 in [3, a...], true eq 9 in [3, a...], true
test "#1100: precedence in or-test compilation of `in`", ->
ok 0 in [1 and 0]
ok 0 in [1, 1 and 0]
ok not (0 in [1, 0 or 1])
# Chained Comparison # Chained Comparison