pull/16126/head
Rich Harris 3 months ago
parent 7f4debebcf
commit 1d6451223a

@ -67,13 +67,6 @@ export function proxy(value) {
/** Used in dev for $inspect.trace() */ /** Used in dev for $inspect.trace() */
var path = ''; var path = '';
/** @param {string | symbol} prop */
function to_trace_name(prop) {
if (typeof prop === 'symbol') return `${path}[Symbol(${prop.description ?? ''})]`;
if (regex_is_valid_identifier.test(prop)) return `${path}.${prop}`;
return /^\d+$/.test(prop) ? `${path}[${prop}]` : `${path}['${prop}']`;
}
/** @param {string} new_path */ /** @param {string} new_path */
function update_path(new_path) { function update_path(new_path) {
path = new_path; path = new_path;
@ -82,7 +75,7 @@ export function proxy(value) {
// rename all child sources and child proxies // rename all child sources and child proxies
for (const [prop, source] of sources) { for (const [prop, source] of sources) {
var label = to_trace_name(prop); var label = get_label(path, prop);
tag(source, label); tag(source, label);
tag_proxy(source.v, label); tag_proxy(source.v, label);
@ -111,14 +104,14 @@ export function proxy(value) {
sources.set(prop, s); sources.set(prop, s);
if (DEV && typeof prop === 'string') { if (DEV && typeof prop === 'string') {
tag(s, to_trace_name(prop)); tag(s, get_label(path, prop));
} }
} else { } else {
var p = with_parent(() => proxy(descriptor.value)); var p = with_parent(() => proxy(descriptor.value));
set(s, p); set(s, p);
if (DEV) { if (DEV) {
tag_proxy(p, to_trace_name(prop)); tag_proxy(p, get_label(path, prop));
} }
} }
@ -135,7 +128,7 @@ export function proxy(value) {
update_version(version); update_version(version);
if (DEV) { if (DEV) {
tag(s, to_trace_name(prop)); tag(s, get_label(path, prop));
} }
} }
} else { } else {
@ -175,7 +168,7 @@ export function proxy(value) {
var s = source(p, stack); var s = source(p, stack);
if (DEV) { if (DEV) {
var label = to_trace_name(prop); var label = get_label(path, prop);
tag(s, label); tag(s, label);
tag_proxy(p, label); tag_proxy(p, label);
} }
@ -235,7 +228,7 @@ export function proxy(value) {
var s = source(p, stack); var s = source(p, stack);
if (DEV) { if (DEV) {
var label = to_trace_name(prop); var label = get_label(path, prop);
tag(s, label); tag(s, label);
tag_proxy(p, label); tag_proxy(p, label);
} }
@ -270,8 +263,11 @@ export function proxy(value) {
// else a later read of the property would result in a source being created with // else a later read of the property would result in a source being created with
// the value of the original item at that index. // the value of the original item at that index.
other_s = with_parent(() => source(UNINITIALIZED, stack)); other_s = with_parent(() => source(UNINITIALIZED, stack));
other_s = DEV ? tag(other_s, to_trace_name(i)) : other_s;
sources.set(i + '', other_s); sources.set(i + '', other_s);
if (DEV) {
tag(other_s, get_label(path, i));
}
} }
} }
} }
@ -286,7 +282,7 @@ export function proxy(value) {
var p = with_parent(() => proxy(value)); var p = with_parent(() => proxy(value));
if (DEV) { if (DEV) {
var label = to_trace_name(prop); var label = get_label(path, prop);
tag(s, label); tag(s, label);
tag_proxy(p, label); tag_proxy(p, label);
} }
@ -300,7 +296,7 @@ export function proxy(value) {
p = with_parent(() => proxy(value)); p = with_parent(() => proxy(value));
if (DEV) { if (DEV) {
tag_proxy(p, to_trace_name(prop)); tag_proxy(p, get_label(path, prop));
} }
set(s, p); set(s, p);
@ -356,6 +352,16 @@ export function proxy(value) {
}); });
} }
/**
* @param {string} path
* @param {string | symbol} prop
*/
function get_label(path, prop) {
if (typeof prop === 'symbol') return `${path}[Symbol(${prop.description ?? ''})]`;
if (regex_is_valid_identifier.test(prop)) return `${path}.${prop}`;
return /^\d+$/.test(prop) ? `${path}[${prop}]` : `${path}['${prop}']`;
}
/** /**
* @param {Source<number>} signal * @param {Source<number>} signal
* @param {1 | -1} [d] * @param {1 | -1} [d]

Loading…
Cancel
Save