Skip to content

Commit e22a60f

Browse files
committed
tag svelte/reactivity, svelte/motion sources in DEV
1 parent 0901a1b commit e22a60f

File tree

11 files changed

+93
-34
lines changed

11 files changed

+93
-34
lines changed

packages/svelte/src/motion/spring.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { writable } from '../store/shared/index.js';
55
import { loop } from '../internal/client/loop.js';
66
import { raf } from '../internal/client/timing.js';
7-
import { is_date } from './utils.js';
7+
import { is_date, tag_if_necessary } from './utils.js';
88
import { set, source } from '../internal/client/reactivity/sources.js';
99
import { render_effect } from '../internal/client/reactivity/effects.js';
1010
import { get } from '../internal/client/runtime.js';
@@ -168,12 +168,12 @@ export function spring(value, opts = {}) {
168168
* @since 5.8.0
169169
*/
170170
export class Spring {
171-
#stiffness = source(0.15);
172-
#damping = source(0.8);
173-
#precision = source(0.01);
171+
#stiffness = tag_if_necessary(source(0.15), 'Spring.stiffness');
172+
#damping = tag_if_necessary(source(0.8), 'Spring.damping');
173+
#precision = tag_if_necessary(source(0.01), 'Spring.precision');
174174

175-
#current = source(/** @type {T} */ (undefined));
176-
#target = source(/** @type {T} */ (undefined));
175+
#current = tag_if_necessary(source(/** @type {T} */ (undefined)), 'Spring.current');
176+
#target = tag_if_necessary(source(/** @type {T} */ (undefined)), 'Spring.target');
177177

178178
#last_value = /** @type {T} */ (undefined);
179179
#last_time = 0;

packages/svelte/src/motion/tweened.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { writable } from '../store/shared/index.js';
55
import { raf } from '../internal/client/timing.js';
66
import { loop } from '../internal/client/loop.js';
77
import { linear } from '../easing/index.js';
8-
import { is_date } from './utils.js';
8+
import { is_date, tag_if_necessary } from './utils.js';
99
import { set, source } from '../internal/client/reactivity/sources.js';
1010
import { get, render_effect } from 'svelte/internal/client';
1111

@@ -175,8 +175,8 @@ export function tweened(value, defaults = {}) {
175175
* @since 5.8.0
176176
*/
177177
export class Tween {
178-
#current = source(/** @type {T} */ (undefined));
179-
#target = source(/** @type {T} */ (undefined));
178+
#current = tag_if_necessary(source(/** @type {T} */ (undefined)), 'Tween.current');
179+
#target = tag_if_necessary(source(/** @type {T} */ (undefined)), 'Tween.target');
180180

181181
/** @type {TweenedOptions<T>} */
182182
#defaults;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
import { DEV } from "esm-env";
2+
import { tag } from "../internal/client/dev/tracing.js";
3+
14
/**
25
* @param {any} obj
36
* @returns {obj is Date}
47
*/
58
export function is_date(obj) {
69
return Object.prototype.toString.call(obj) === '[object Date]';
710
}
11+
12+
13+
/**
14+
* @template {import("#client").Source<any>} T
15+
* @param {T} source
16+
* @param {string} name
17+
* @returns {T}
18+
*/
19+
export function tag_if_necessary(source, name) {
20+
if (DEV) {
21+
return /** @type {T} */ (tag(source, name));
22+
}
23+
return source;
24+
}

packages/svelte/src/reactivity/create-subscriber.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { get, tick, untrack } from '../internal/client/runtime.js';
22
import { effect_tracking, render_effect } from '../internal/client/reactivity/effects.js';
33
import { source } from '../internal/client/reactivity/sources.js';
4-
import { increment } from './utils.js';
4+
import { increment, tag_if_necessary } from './utils.js';
55

66
/**
77
* Returns a `subscribe` function that, if called in an effect (including expressions in the template),
@@ -47,7 +47,7 @@ import { increment } from './utils.js';
4747
*/
4848
export function createSubscriber(start) {
4949
let subscribers = 0;
50-
let version = source(0);
50+
let version = tag_if_necessary(source(0), 'createSubscriber version');
5151
/** @type {(() => void) | void} */
5252
let stop;
5353

packages/svelte/src/reactivity/date.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { derived } from '../internal/client/index.js';
33
import { source, set } from '../internal/client/reactivity/sources.js';
44
import { active_reaction, get, set_active_reaction } from '../internal/client/runtime.js';
5+
import { tag_if_necessary } from './utils.js';
56

67
var inited = false;
78

@@ -38,7 +39,7 @@ var inited = false;
3839
* ```
3940
*/
4041
export class SvelteDate extends Date {
41-
#time = source(super.getTime());
42+
#time = tag_if_necessary(source(super.getTime()), 'SvelteDate.#time');
4243

4344
/** @type {Map<keyof Date, Source<unknown>>} */
4445
#deriveds = new Map();

packages/svelte/src/reactivity/map.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { DEV } from 'esm-env';
33
import { set, source } from '../internal/client/reactivity/sources.js';
44
import { get } from '../internal/client/runtime.js';
5-
import { increment } from './utils.js';
5+
import { increment, tag_if_necessary } from './utils.js';
66

77
/**
88
* A reactive version of the built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) object.
@@ -53,8 +53,8 @@ import { increment } from './utils.js';
5353
export class SvelteMap extends Map {
5454
/** @type {Map<K, Source<number>>} */
5555
#sources = new Map();
56-
#version = source(0);
57-
#size = source(0);
56+
#version = tag_if_necessary(source(0), 'SvelteMap version');
57+
#size = tag_if_necessary(source(0), 'SvelteMap.size');
5858

5959
/**
6060
* @param {Iterable<readonly [K, V]> | null | undefined} [value]
@@ -81,7 +81,10 @@ export class SvelteMap extends Map {
8181
if (s === undefined) {
8282
var ret = super.get(key);
8383
if (ret !== undefined) {
84-
s = source(0);
84+
s = tag_if_necessary(
85+
source(0),
86+
`SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`
87+
);
8588
sources.set(key, s);
8689
} else {
8790
// We should always track the version in case
@@ -112,7 +115,10 @@ export class SvelteMap extends Map {
112115
if (s === undefined) {
113116
var ret = super.get(key);
114117
if (ret !== undefined) {
115-
s = source(0);
118+
s = tag_if_necessary(
119+
source(0),
120+
`SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`
121+
);
116122
sources.set(key, s);
117123
} else {
118124
// We should always track the version in case
@@ -138,7 +144,13 @@ export class SvelteMap extends Map {
138144
var version = this.#version;
139145

140146
if (s === undefined) {
141-
sources.set(key, source(0));
147+
sources.set(
148+
key,
149+
tag_if_necessary(
150+
source(0),
151+
`SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`
152+
)
153+
);
142154
set(this.#size, super.size);
143155
increment(version);
144156
} else if (prev_res !== value) {
@@ -197,7 +209,13 @@ export class SvelteMap extends Map {
197209
if (this.#size.v !== sources.size) {
198210
for (var key of super.keys()) {
199211
if (!sources.has(key)) {
200-
sources.set(key, source(0));
212+
sources.set(
213+
key,
214+
tag_if_necessary(
215+
source(0),
216+
`SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`
217+
)
218+
);
201219
}
202220
}
203221
}

packages/svelte/src/reactivity/set.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { DEV } from 'esm-env';
33
import { source, set } from '../internal/client/reactivity/sources.js';
44
import { get } from '../internal/client/runtime.js';
5-
import { increment } from './utils.js';
5+
import { increment, tag_if_necessary } from './utils.js';
66

77
var read_methods = ['forEach', 'isDisjointFrom', 'isSubsetOf', 'isSupersetOf'];
88
var set_like_methods = ['difference', 'intersection', 'symmetricDifference', 'union'];
@@ -47,8 +47,8 @@ var inited = false;
4747
export class SvelteSet extends Set {
4848
/** @type {Map<T, Source<boolean>>} */
4949
#sources = new Map();
50-
#version = source(0);
51-
#size = source(0);
50+
#version = tag_if_necessary(source(0), 'SvelteSet version');
51+
#size = tag_if_necessary(source(0), 'SvelteSet.size');
5252

5353
/**
5454
* @param {Iterable<T> | null | undefined} [value]
@@ -110,7 +110,10 @@ export class SvelteSet extends Set {
110110
return false;
111111
}
112112

113-
s = source(true);
113+
s = tag_if_necessary(
114+
source(true),
115+
`SvelteSet Entry [${typeof value === 'symbol' ? `Symbol(${value.description})` : value}]`
116+
);
114117
sources.set(value, s);
115118
}
116119

packages/svelte/src/reactivity/url-search-params.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { source } from '../internal/client/reactivity/sources.js';
22
import { get } from '../internal/client/runtime.js';
33
import { get_current_url } from './url.js';
4-
import { increment } from './utils.js';
4+
import { increment, tag_if_necessary } from './utils.js';
55

66
export const REPLACE = Symbol();
77

@@ -32,7 +32,7 @@ export const REPLACE = Symbol();
3232
* ```
3333
*/
3434
export class SvelteURLSearchParams extends URLSearchParams {
35-
#version = source(0);
35+
#version = tag_if_necessary(source(0), 'SvelteURLSearchParams version');
3636
#url = get_current_url();
3737

3838
#updating = false;

packages/svelte/src/reactivity/url.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { source, set } from '../internal/client/reactivity/sources.js';
22
import { get } from '../internal/client/runtime.js';
33
import { REPLACE, SvelteURLSearchParams } from './url-search-params.js';
4+
import { tag_if_necessary } from './utils.js';
45

56
/** @type {SvelteURL | null} */
67
let current_url = null;
@@ -38,14 +39,14 @@ export function get_current_url() {
3839
* ```
3940
*/
4041
export class SvelteURL extends URL {
41-
#protocol = source(super.protocol);
42-
#username = source(super.username);
43-
#password = source(super.password);
44-
#hostname = source(super.hostname);
45-
#port = source(super.port);
46-
#pathname = source(super.pathname);
47-
#hash = source(super.hash);
48-
#search = source(super.search);
42+
#protocol = tag_if_necessary(source(super.protocol), 'SvelteURL.protocol');
43+
#username = tag_if_necessary(source(super.username), 'SvelteURL.username');
44+
#password = tag_if_necessary(source(super.password), 'SvelteURL.password');
45+
#hostname = tag_if_necessary(source(super.hostname), 'SvelteURL.hostname');
46+
#port = tag_if_necessary(source(super.port), 'SvelteURL.port');
47+
#pathname = tag_if_necessary(source(super.pathname), 'SvelteURL.pathname');
48+
#hash = tag_if_necessary(source(super.hash), 'SvelteURL.hash');
49+
#search = tag_if_necessary(source(super.search), 'SvelteURL.search');
4950
#searchParams;
5051

5152
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
/** @import { Source } from '#client' */
2+
import { DEV } from 'esm-env';
23
import { set } from '../internal/client/reactivity/sources.js';
4+
import { tag } from '../internal/client/index.js';
35

46
/** @param {Source<number>} source */
57
export function increment(source) {
68
set(source, source.v + 1);
79
}
10+
11+
/**
12+
* @template {Source<any>} T
13+
* @param {T} source
14+
* @param {string} name
15+
* @returns {T}
16+
*/
17+
export function tag_if_necessary(source, name) {
18+
if (DEV) {
19+
return /** @type {T} */ (tag(source, name));
20+
}
21+
return source;
22+
}

0 commit comments

Comments
 (0)