avoid [[object Object]] in labels

pull/16060/head
Rich Harris 3 months ago
parent 8a416a8bbe
commit 3d161ee89d

@ -189,3 +189,13 @@ export function tag(source, name) {
source.trace_name = name;
return source;
}
/**
* @param {unknown} value
*/
export function label(value) {
if (typeof value === 'symbol') return `Symbol(${value.description})`;
if (typeof value === 'function') return '<function>';
if (typeof value === 'object' && value) return '<object>';
return String(value);
}

@ -1,7 +1,7 @@
/** @import { Source } from '#client' */
import { DEV } from 'esm-env';
import { set, source } from '../internal/client/reactivity/sources.js';
import { tag } from '../internal/client/dev/tracing.js';
import { label, tag } from '../internal/client/dev/tracing.js';
import { get } from '../internal/client/runtime.js';
import { increment } from './utils.js';
@ -90,8 +90,7 @@ export class SvelteMap extends Map {
s = source(0);
if (DEV) {
var label = `SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`;
tag(s, label);
tag(s, `SvelteMap get(${label(key)})`);
}
sources.set(key, s);
@ -127,8 +126,7 @@ export class SvelteMap extends Map {
s = source(0);
if (DEV) {
var label = `SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`;
tag(s, label);
tag(s, `SvelteMap get(${label(key)})`);
}
sources.set(key, s);
@ -159,8 +157,7 @@ export class SvelteMap extends Map {
s = source(0);
if (DEV) {
var label = `SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`;
tag(s, label);
tag(s, `SvelteMap get(${label(key)})`);
}
sources.set(key, s);
@ -225,8 +222,7 @@ export class SvelteMap extends Map {
var s = source(0);
if (DEV) {
var label = `SvelteMap Entry [${typeof key === 'symbol' ? `Symbol(${key.description})` : key}]`;
tag(s, label);
tag(s, `SvelteMap get(${label(key)})`);
}
sources.set(key, s);

@ -1,7 +1,7 @@
/** @import { Source } from '#client' */
import { DEV } from 'esm-env';
import { source, set } from '../internal/client/reactivity/sources.js';
import { tag } from '../internal/client/dev/tracing.js';
import { label, tag } from '../internal/client/dev/tracing.js';
import { get } from '../internal/client/runtime.js';
import { increment } from './utils.js';
@ -119,8 +119,7 @@ export class SvelteSet extends Set {
s = source(true);
if (DEV) {
var label = `SvelteSet Entry [${typeof value === 'symbol' ? `Symbol(${value.description})` : value}]`;
tag(s, label);
tag(s, `SvelteSet has(${label(value)})`);
}
sources.set(value, s);

Loading…
Cancel
Save