mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
fixes #1723: operator precedence in unbounded splice compilation
This commit is contained in:
parent
3b5c889040
commit
08762a101c
3 changed files with 22 additions and 7 deletions
|
@ -1402,7 +1402,7 @@
|
|||
to = +to.compile(o) - +fromRef;
|
||||
if (!exclusive) to += 1;
|
||||
} else {
|
||||
to = to.compile(o) + ' - ' + fromRef;
|
||||
to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef;
|
||||
if (!exclusive) to += ' + 1';
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1062,7 +1062,7 @@ exports.Assign = class Assign extends Base
|
|||
to = +to.compile(o) - +fromRef
|
||||
to += 1 unless exclusive
|
||||
else
|
||||
to = to.compile(o) + ' - ' + fromRef
|
||||
to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef
|
||||
to += ' + 1' unless exclusive
|
||||
else
|
||||
to = "9e9"
|
||||
|
|
|
@ -52,6 +52,13 @@ test "string slicing", ->
|
|||
ok str[0..4] is "abcde"
|
||||
ok str[-5..] is "vwxyz"
|
||||
|
||||
test "#1722: operator precedence in unbounded slice compilation", ->
|
||||
list = [0..9]
|
||||
n = 2 # some truthy number in `list`
|
||||
arrayEq [0..n], list[..n]
|
||||
arrayEq [0..n], list[..n or 0]
|
||||
arrayEq [0..n], list[..if n then n else 0]
|
||||
|
||||
|
||||
# Splicing
|
||||
|
||||
|
@ -115,9 +122,17 @@ test "the return value of a splice literal should be the RHS", ->
|
|||
|
||||
arrayEq [ary[0..0] = 0], [0]
|
||||
|
||||
test "#1722: operator precedence in unbounded slice compilation", ->
|
||||
test "#1723: operator precedence in unbounded splice compilation", ->
|
||||
n = 4 # some truthy number in `list`
|
||||
|
||||
list = [0..9]
|
||||
n = 2 # some truthy number in `list`
|
||||
arrayEq [0..n], list[..n]
|
||||
arrayEq [0..n], list[..n or 0]
|
||||
arrayEq [0..n], list[..if n then n else 0]
|
||||
list[..n] = n
|
||||
arrayEq [n..9], list
|
||||
|
||||
list = [0..9]
|
||||
list[..n or 0] = n
|
||||
arrayEq [n..9], list
|
||||
|
||||
list = [0..9]
|
||||
list[..if n then n else 0] = n
|
||||
arrayEq [n..9], list
|
||||
|
|
Loading…
Add table
Reference in a new issue