From f18a91cf644a00a3a798535b18f1bcb8fb5db7c9 Mon Sep 17 00:00:00 2001 From: summivox Date: Sun, 21 Feb 2016 02:39:36 -0500 Subject: [PATCH] Fix #858 Inconsistent empty splat assignment See #858 TL;DR: `[a, ..., b, c, d] = [1 2 3]` should behave the same as `[a, ...m, b, c, d]` --- src/ast.ls | 12 ++++++++---- test/splat.ls | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ast.ls b/src/ast.ls index ea3d690b8..f7c5c32ea 100644 --- a/src/ast.ls +++ b/src/ast.ls @@ -1660,10 +1660,14 @@ class exports.Assign extends Node continue if skip and i+2 is len start = i+1 @temps = [ivar = o.scope.temporary \i] - val = if skip then node = Var ivar; Var val else - Arr.wrap JS "#i < (#ivar = #val) - \ ? #{ util \slice }.call(#rite, #i, #ivar) - \ : (#ivar = #i, [])" + val = switch + | skip + Arr.wrap JS "#i < (#ivar = #val) ? #i : (#ivar = #i)" + | _ + Arr.wrap JS do + "#i < (#ivar = #val) + \ ? #{ util \slice }.call(#rite, #i, #ivar) + \ : (#ivar = #i, [])" else (inc = ivar) and start < i and inc += " + #{ i - start }" val = Chain rcache||=Literal(rite), [Index JS inc || i] diff --git a/test/splat.ls b/test/splat.ls index 896eb7e62..723dc1440 100644 --- a/test/splat.ls +++ b/test/splat.ls @@ -102,6 +102,12 @@ eq b, 2 eq a, 1 eq b, 5 +# [LiveScript#858](https://github.com/gkz/LiveScript/issues/858) +[a, ..., b, c, d] = [1 2 3] +eq a, 1 +eq b, 2 +eq c, 3 + eq ''' (function(){ var a;