Skip to content

Commit a531999

Browse files
committed
feat: define inspect on dev mode only
1 parent d38f89e commit a531999

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

packages/svelte/src/reactivity/date.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DEV } from 'esm-env';
12
import { INSPECT_SYMBOL } from '../internal/client/constants.js';
23
import { source, set } from '../internal/client/reactivity/sources.js';
34
import { get } from '../internal/client/runtime.js';
@@ -89,6 +90,12 @@ export class ReactiveDate extends Date {
8990
return v;
9091
};
9192
}
93+
94+
if (DEV) {
95+
proto[INSPECT_SYMBOL] = function () {
96+
get(this.#raw_time);
97+
};
98+
}
9299
}
93100
}
94101

@@ -100,8 +107,4 @@ export class ReactiveDate extends Date {
100107
super(...values);
101108
this.#init();
102109
}
103-
104-
[INSPECT_SYMBOL]() {
105-
get(this.#raw_time);
106-
}
107110
}

packages/svelte/src/reactivity/map.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { UNINITIALIZED } from '../constants.js';
55
import { map } from './utils.js';
66
import { INSPECT_SYMBOL } from '../internal/client/constants.js';
77

8+
var inited = false;
9+
810
/**
911
* @template K
1012
* @template V
@@ -21,6 +23,21 @@ export class ReactiveMap extends Map {
2123
constructor(value) {
2224
super();
2325

26+
if (DEV) {
27+
if (!inited) {
28+
inited = true;
29+
ReactiveMap.prototype[INSPECT_SYMBOL] = function () {
30+
// changes could either introduced by
31+
// - modifying the value, or
32+
// - add / remove entries to the map
33+
for (const [, source] of this.#sources) {
34+
get(source);
35+
}
36+
get(this.#size);
37+
};
38+
}
39+
}
40+
2441
// If the value is invalid then the native exception will fire here
2542
if (DEV) new Map(value);
2643

@@ -156,14 +173,4 @@ export class ReactiveMap extends Map {
156173
get size() {
157174
return get(this.#size);
158175
}
159-
160-
[INSPECT_SYMBOL]() {
161-
// changes could either introduced by
162-
// - modifying the value, or
163-
// - add / remove entries to the map
164-
for (const [, source] of this.#sources) {
165-
get(source);
166-
}
167-
get(this.#size);
168-
}
169176
}

packages/svelte/src/reactivity/set.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export class ReactiveSet extends Set {
6767
return new ReactiveSet(set);
6868
};
6969
}
70+
71+
if (DEV) {
72+
proto[INSPECT_SYMBOL] = function () {
73+
get(this.#version);
74+
};
75+
}
7076
}
7177

7278
#increment_version() {
@@ -151,7 +157,4 @@ export class ReactiveSet extends Set {
151157
get size() {
152158
return get(this.#size);
153159
}
154-
[INSPECT_SYMBOL]() {
155-
get(this.#version);
156-
}
157160
}

0 commit comments

Comments
 (0)