diff --git a/packages/babel-plugin-transform-es2015-destructuring/src/index.js b/packages/babel-plugin-transform-es2015-destructuring/src/index.js index 3fe8c9fd3bf7..b82ac321dd12 100644 --- a/packages/babel-plugin-transform-es2015-destructuring/src/index.js +++ b/packages/babel-plugin-transform-es2015-destructuring/src/index.js @@ -294,10 +294,7 @@ export default function ({ types: t }) { if (t.isRestElement(elem)) { elemRef = this.toArray(arrayRef); - - if (i > 0) { - elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), [t.numericLiteral(i)]); - } + elemRef = t.callExpression(t.memberExpression(elemRef, t.identifier("slice")), [t.numericLiteral(i)]); // set the element to the rest element argument since we've dealt with it // being a rest already diff --git a/packages/babel-plugin-transform-es2015-destructuring/test/fixtures/destructuring/issue-5090/exec.js b/packages/babel-plugin-transform-es2015-destructuring/test/fixtures/destructuring/issue-5090/exec.js new file mode 100644 index 000000000000..b7727da60494 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-destructuring/test/fixtures/destructuring/issue-5090/exec.js @@ -0,0 +1,9 @@ +const assign = function([...arr], index, value) { + arr[index] = value; + return arr; +} + +const arr = [1, 2, 3]; +assign(arr, 1, 42); + +assert.deepEqual(arr, [1, 2, 3]);