Ensure array is always copied during destructure
This commit is contained in:
parent
39d18679e1
commit
a749907bc2
@ -294,10 +294,7 @@ export default function ({ types: t }) {
|
|||||||
|
|
||||||
if (t.isRestElement(elem)) {
|
if (t.isRestElement(elem)) {
|
||||||
elemRef = this.toArray(arrayRef);
|
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
|
// set the element to the rest element argument since we've dealt with it
|
||||||
// being a rest already
|
// being a rest already
|
||||||
|
|||||||
@ -0,0 +1,9 @@
|
|||||||
|
const assign = ([...arr], index, value) => {
|
||||||
|
arr[index] = value;
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const arr = [1, 2, 3];
|
||||||
|
assign(arr, 1, 42);
|
||||||
|
|
||||||
|
assert.deepEqual(arr, [1, 2, 3]);
|
||||||
Loading…
x
Reference in New Issue
Block a user