Skip to content

Commit bc2af11

Browse files
committed
fix o{(p!)}q.r = s
An unlikely edge case, but nevertheless one for which there was a bug. Found while investigating unrelated issues. The fix is to consider only the last tail of a chain to be in assignment position if the entire chain is assigned to.
1 parent b1338a1 commit bc2af11

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

lib/ast.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ast.ls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,9 @@ class exports.Chain extends Node
932932
rewrite-shorthand: (o, assign) ->
933933
return that.rewrite-shorthand o, assign or that if @unfold-soak o
934934
@head = that if @head.rewrite-shorthand o
935+
last-i = @tails.length - 1
935936
for item, i in @tails
936-
@tails[i] = that if item.rewrite-shorthand o, assign
937+
@tails[i] = that if item.rewrite-shorthand(o, assign && i is last-i)
937938
@expand-slice o, assign
938939
@unwrap!
939940

test/chaining.ls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,9 @@ eq true delete! a?{x}[\x]y
291291
eq void b.x.y
292292
a = [4 3]
293293
eq '4,3,2' "#{a?[0 1] <<< {2}}"
294+
295+
# Assigning through computed properties in slices
296+
p = -> \q
297+
o = q: r: 1
298+
o{(p!)}q.r = 1
299+
eq 1 o.q.r

0 commit comments

Comments
 (0)