11/** @import { Source } from '#client' */
22import { DEV } from 'esm-env' ;
33import { set , source } from '../internal/client/reactivity/sources.js' ;
4+ import { tag } from '../internal/client/dev/tracing.js' ;
45import { get } from '../internal/client/runtime.js' ;
5- import { increment , tag_if_necessary } from './utils.js' ;
6+ import { increment } from './utils.js' ;
67
78/**
89 * A reactive version of the built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) object.
@@ -53,17 +54,22 @@ import { increment, tag_if_necessary } from './utils.js';
5354export class SvelteMap extends Map {
5455 /** @type {Map<K, Source<number>> } */
5556 #sources = new Map ( ) ;
56- #version = tag_if_necessary ( source ( 0 ) , 'SvelteMap version' ) ;
57- #size = tag_if_necessary ( source ( 0 ) , 'SvelteMap.size' ) ;
57+ #version = source ( 0 ) ;
58+ #size = source ( 0 ) ;
5859
5960 /**
6061 * @param {Iterable<readonly [K, V]> | null | undefined } [value]
6162 */
6263 constructor ( value ) {
6364 super ( ) ;
6465
65- // If the value is invalid then the native exception will fire here
66- if ( DEV ) value = new Map ( value ) ;
66+ if ( DEV ) {
67+ // If the value is invalid then the native exception will fire here
68+ value = new Map ( value ) ;
69+
70+ tag ( this . #version, 'SvelteMap version' ) ;
71+ tag ( this . #size, 'SvelteMap.size' ) ;
72+ }
6773
6874 if ( value ) {
6975 for ( var [ key , v ] of value ) {
@@ -81,10 +87,13 @@ export class SvelteMap extends Map {
8187 if ( s === undefined ) {
8288 var ret = super . get ( key ) ;
8389 if ( ret !== undefined ) {
84- s = tag_if_necessary (
85- source ( 0 ) ,
86- `SvelteMap Entry [${ typeof key === 'symbol' ? `Symbol(${ key . description } )` : key } ]`
87- ) ;
90+ s = source ( 0 ) ;
91+
92+ if ( DEV ) {
93+ var label = `SvelteMap Entry [${ typeof key === 'symbol' ? `Symbol(${ key . description } )` : key } ]` ;
94+ tag ( s , label ) ;
95+ }
96+
8897 sources . set ( key , s ) ;
8998 } else {
9099 // We should always track the version in case
@@ -115,10 +124,13 @@ export class SvelteMap extends Map {
115124 if ( s === undefined ) {
116125 var ret = super . get ( key ) ;
117126 if ( ret !== undefined ) {
118- s = tag_if_necessary (
119- source ( 0 ) ,
120- `SvelteMap Entry [${ typeof key === 'symbol' ? `Symbol(${ key . description } )` : key } ]`
121- ) ;
127+ s = source ( 0 ) ;
128+
129+ if ( DEV ) {
130+ var label = `SvelteMap Entry [${ typeof key === 'symbol' ? `Symbol(${ key . description } )` : key } ]` ;
131+ tag ( s , label ) ;
132+ }
133+
122134 sources . set ( key , s ) ;
123135 } else {
124136 // We should always track the version in case
@@ -144,13 +156,14 @@ export class SvelteMap extends Map {
144156 var version = this . #version;
145157
146158 if ( s === undefined ) {
147- sources . set (
148- key ,
149- tag_if_necessary (
150- source ( 0 ) ,
151- `SvelteMap Entry [${ typeof key === 'symbol' ? `Symbol(${ key . description } )` : key } ]`
152- )
153- ) ;
159+ s = source ( 0 ) ;
160+
161+ if ( DEV ) {
162+ var label = `SvelteMap Entry [${ typeof key === 'symbol' ? `Symbol(${ key . description } )` : key } ]` ;
163+ tag ( s , label ) ;
164+ }
165+
166+ sources . set ( key , s ) ;
154167 set ( this . #size, super . size ) ;
155168 increment ( version ) ;
156169 } else if ( prev_res !== value ) {
@@ -209,18 +222,19 @@ export class SvelteMap extends Map {
209222 if ( this . #size. v !== sources . size ) {
210223 for ( var key of super . keys ( ) ) {
211224 if ( ! sources . has ( key ) ) {
212- sources . set (
213- key ,
214- tag_if_necessary (
215- source ( 0 ) ,
216- `SvelteMap Entry [${ typeof key === 'symbol' ? `Symbol(${ key . description } )` : key } ]`
217- )
218- ) ;
225+ var s = source ( 0 ) ;
226+
227+ if ( DEV ) {
228+ var label = `SvelteMap Entry [${ typeof key === 'symbol' ? `Symbol(${ key . description } )` : key } ]` ;
229+ tag ( s , label ) ;
230+ }
231+
232+ sources . set ( key , s ) ;
219233 }
220234 }
221235 }
222236
223- for ( var [ , s ] of this . #sources) {
237+ for ( [ , s ] of this . #sources) {
224238 get ( s ) ;
225239 }
226240 }
0 commit comments