Skip to content

Commit edf468a

Browse files
committed
fix: ensure $state.snapshot clones holey arrays correctly
1 parent 2ac038c commit edf468a

File tree

1 file changed

+7
-6
lines changed
  • packages/svelte/src/internal/shared

1 file changed

+7
-6
lines changed

packages/svelte/src/internal/shared/clone.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,24 @@ export function snapshot(value, skip_warning = false) {
5454
*/
5555
function clone(value, cloned, path, paths, original = null) {
5656
if (typeof value === 'object' && value !== null) {
57-
const unwrapped = cloned.get(value);
57+
var unwrapped = cloned.get(value);
5858
if (unwrapped !== undefined) return unwrapped;
5959

6060
if (value instanceof Map) return /** @type {Snapshot<T>} */ (new Map(value));
6161
if (value instanceof Set) return /** @type {Snapshot<T>} */ (new Set(value));
6262

6363
if (is_array(value)) {
64-
const copy = /** @type {Snapshot<any>} */ (Array(value.length));
64+
var copy = /** @type {Snapshot<any>} */ (Array(value.length));
6565
cloned.set(value, copy);
6666

6767
if (original !== null) {
6868
cloned.set(original, copy);
6969
}
7070

71-
for (let i = 0; i < value.length; i += 1) {
72-
if (value[i] !== undefined) {
73-
copy[i] = clone(value[i], cloned, DEV ? `${path}[${i}]` : path, paths);
71+
for (var i = 0; i < value.length; i += 1) {
72+
var element = value[i];
73+
if (element !== undefined) {
74+
copy[i] = clone(element, cloned, DEV ? `${path}[${i}]` : path, paths);
7475
}
7576
}
7677

@@ -79,7 +80,7 @@ function clone(value, cloned, path, paths, original = null) {
7980

8081
if (get_prototype_of(value) === object_prototype) {
8182
/** @type {Snapshot<any>} */
82-
const copy = {};
83+
copy = {};
8384
cloned.set(value, copy);
8485

8586
if (original !== null) {

0 commit comments

Comments
 (0)