@@ -12,15 +12,16 @@ import { state as source, set } from './reactivity/sources.js';
1212import { STATE_SYMBOL } from '#client/constants' ;
1313import { UNINITIALIZED } from '../../constants.js' ;
1414import * as e from './errors.js' ;
15- import { get_stack } from './dev/tracing.js' ;
15+ import { get_stack , tag_source } from './dev/tracing.js' ;
1616import { tracing_mode_flag } from '../flags/index.js' ;
1717
1818/**
1919 * @template T
2020 * @param {T } value
21+ * @param {string } [path]
2122 * @returns {T }
2223 */
23- export function proxy ( value ) {
24+ export function proxy ( value , path ) {
2425 // if non-proxyable, or is already a proxy, return `value`
2526 if ( typeof value !== 'object' || value === null || STATE_SYMBOL in value ) {
2627 return value ;
@@ -39,6 +40,16 @@ export function proxy(value) {
3940
4041 var stack = DEV && tracing_mode_flag ? get_stack ( 'CreatedAt' ) : null ;
4142 var reaction = active_reaction ;
43+ /** @type {(prop: any) => any } */
44+ var to_trace_name = DEV
45+ ? ( prop ) => {
46+ return typeof prop === 'symbol'
47+ ? `${ path } [unique symbol]`
48+ : typeof prop === 'number' || Number ( prop ) === Number ( prop )
49+ ? `${ path } [${ prop } ]`
50+ : `${ path } .${ prop } ` ;
51+ }
52+ : ( prop ) => undefined ;
4253
4354 /**
4455 * @template T
@@ -58,7 +69,8 @@ export function proxy(value) {
5869 if ( is_proxied_array ) {
5970 // We need to create the length source eagerly to ensure that
6071 // mutations to the array are properly synced with our proxy
61- sources . set ( 'length' , source ( /** @type {any[] } */ ( value ) . length , stack ) ) ;
72+ const length_source = source ( /** @type {any[] } */ ( value ) . length , stack ) ;
73+ sources . set ( 'length' , DEV ? tag_source ( length_source , to_trace_name ( 'length' ) ) : length_source ) ;
6274 }
6375
6476 return new Proxy ( /** @type {any } */ ( value ) , {
@@ -80,11 +92,12 @@ export function proxy(value) {
8092
8193 if ( s === undefined ) {
8294 s = with_parent ( ( ) => source ( descriptor . value , stack ) ) ;
95+ s = DEV && typeof prop === 'string' ? tag_source ( s , to_trace_name ( prop ) ) : s ;
8396 sources . set ( prop , s ) ;
8497 } else {
8598 set (
8699 s ,
87- with_parent ( ( ) => proxy ( descriptor . value ) )
100+ with_parent ( ( ) => proxy ( descriptor . value , to_trace_name ( prop ) ) )
88101 ) ;
89102 }
90103
@@ -96,9 +109,10 @@ export function proxy(value) {
96109
97110 if ( s === undefined ) {
98111 if ( prop in target ) {
112+ const s = with_parent ( ( ) => source ( UNINITIALIZED , stack ) ) ;
99113 sources . set (
100114 prop ,
101- with_parent ( ( ) => source ( UNINITIALIZED , stack ) )
115+ DEV && typeof prop === 'string' ? tag_source ( s , to_trace_name ( prop ) ) : s
102116 ) ;
103117 update_version ( version ) ;
104118 }
@@ -130,7 +144,10 @@ export function proxy(value) {
130144
131145 // create a source, but only if it's an own property and not a prototype property
132146 if ( s === undefined && ( ! exists || get_descriptor ( target , prop ) ?. writable ) ) {
133- s = with_parent ( ( ) => source ( proxy ( exists ? target [ prop ] : UNINITIALIZED ) , stack ) ) ;
147+ s = with_parent ( ( ) =>
148+ source ( proxy ( exists ? target [ prop ] : UNINITIALIZED , to_trace_name ( prop ) ) , stack )
149+ ) ;
150+ s = DEV && typeof prop === 'string' ? tag_source ( s , to_trace_name ( prop ) ) : s ;
134151 sources . set ( prop , s ) ;
135152 }
136153
@@ -178,7 +195,10 @@ export function proxy(value) {
178195 ( active_effect !== null && ( ! has || get_descriptor ( target , prop ) ?. writable ) )
179196 ) {
180197 if ( s === undefined ) {
181- s = with_parent ( ( ) => source ( has ? proxy ( target [ prop ] ) : UNINITIALIZED , stack ) ) ;
198+ s = with_parent ( ( ) =>
199+ source ( has ? proxy ( target [ prop ] , to_trace_name ( prop ) ) : UNINITIALIZED , stack )
200+ ) ;
201+ s = DEV && typeof prop === 'string' ? tag_source ( s , to_trace_name ( prop ) ) : s ;
182202 sources . set ( prop , s ) ;
183203 }
184204
@@ -206,6 +226,7 @@ export function proxy(value) {
206226 // else a later read of the property would result in a source being created with
207227 // the value of the original item at that index.
208228 other_s = with_parent ( ( ) => source ( UNINITIALIZED , stack ) ) ;
229+ other_s = DEV ? tag_source ( other_s , to_trace_name ( i ) ) : other_s ;
209230 sources . set ( i + '' , other_s ) ;
210231 }
211232 }
@@ -218,17 +239,18 @@ export function proxy(value) {
218239 if ( s === undefined ) {
219240 if ( ! has || get_descriptor ( target , prop ) ?. writable ) {
220241 s = with_parent ( ( ) => source ( undefined , stack ) ) ;
242+ s = DEV && typeof prop === 'string' ? tag_source ( s , to_trace_name ( prop ) ) : s ;
221243 set (
222244 s ,
223- with_parent ( ( ) => proxy ( value ) )
245+ with_parent ( ( ) => proxy ( value , to_trace_name ( prop ) ) )
224246 ) ;
225247 sources . set ( prop , s ) ;
226248 }
227249 } else {
228250 has = s . v !== UNINITIALIZED ;
229251 set (
230252 s ,
231- with_parent ( ( ) => proxy ( value ) )
253+ with_parent ( ( ) => proxy ( value , to_trace_name ( prop ) ) )
232254 ) ;
233255 }
234256
0 commit comments