Skip to content

Commit 7cc7dfa

Browse files
committed
WIP
1 parent a95b625 commit 7cc7dfa

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

packages/svelte/src/internal/client/dev/tracing.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ import { DERIVED, PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
66
import { effect_tracking } from '../reactivity/effects.js';
77
import { active_reaction } from '../runtime.js';
88

9-
/** @type {{ reaction: Reaction | null, entries: Map<Value, Error[]> } | null} */
9+
/**
10+
* @typedef {{
11+
* traces: Error[];
12+
* }} TraceEntry
13+
*/
14+
15+
/** @type {{ reaction: Reaction | null, entries: Map<Value, TraceEntry> } | null} */
1016
export let tracing_expressions = null;
1117

1218
/**
1319
* @param {Value} signal
14-
* @param {Error[]} [traces]
20+
* @param {TraceEntry} [entry]
1521
*/
16-
function log_entry(signal, traces = []) {
22+
function log_entry(signal, entry) {
1723
const value = signal.trace_need_increase ? signal.trace_v : signal.v;
1824

1925
if (value === UNINITIALIZED) {
@@ -54,9 +60,11 @@ function log_entry(signal, traces = []) {
5460
console.log(signal.updated);
5561
}
5662

57-
for (var trace of traces) {
58-
// eslint-disable-next-line no-console
59-
console.log(trace);
63+
if (entry) {
64+
for (var trace of entry.traces) {
65+
// eslint-disable-next-line no-console
66+
console.log(trace);
67+
}
6068
}
6169

6270
// eslint-disable-next-line no-console

packages/svelte/src/internal/client/runtime.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,18 +777,19 @@ export function get(signal) {
777777
var trace = get_stack('TracedAt');
778778

779779
if (trace) {
780-
var traces = tracing_expressions.entries.get(signal);
780+
var entry = tracing_expressions.entries.get(signal);
781781

782-
if (traces === undefined) {
783-
tracing_expressions.entries.set(signal, (traces = []));
782+
if (entry === undefined) {
783+
entry = { traces: [] };
784+
tracing_expressions.entries.set(signal, entry);
784785
}
785786

786-
var last = traces.at(-1);
787+
var last = entry.traces.at(-1);
787788

788789
// traces can be duplicated, e.g. by `snapshot` invoking both
789790
// both `getOwnPropertyDescriptor` and `get` traps at once
790791
if (trace.stack !== last?.stack) {
791-
traces.push(trace);
792+
entry.traces.push(trace);
792793
}
793794
}
794795
}

0 commit comments

Comments
 (0)