pull/16131/head
Rich Harris 3 months ago
parent a95b625800
commit 7cc7dfa68c

@ -6,14 +6,20 @@ import { DERIVED, PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
import { effect_tracking } from '../reactivity/effects.js'; import { effect_tracking } from '../reactivity/effects.js';
import { active_reaction } from '../runtime.js'; import { active_reaction } from '../runtime.js';
/** @type {{ reaction: Reaction | null, entries: Map<Value, Error[]> } | null} */ /**
* @typedef {{
* traces: Error[];
* }} TraceEntry
*/
/** @type {{ reaction: Reaction | null, entries: Map<Value, TraceEntry> } | null} */
export let tracing_expressions = null; export let tracing_expressions = null;
/** /**
* @param {Value} signal * @param {Value} signal
* @param {Error[]} [traces] * @param {TraceEntry} [entry]
*/ */
function log_entry(signal, traces = []) { function log_entry(signal, entry) {
const value = signal.trace_need_increase ? signal.trace_v : signal.v; const value = signal.trace_need_increase ? signal.trace_v : signal.v;
if (value === UNINITIALIZED) { if (value === UNINITIALIZED) {
@ -54,9 +60,11 @@ function log_entry(signal, traces = []) {
console.log(signal.updated); console.log(signal.updated);
} }
for (var trace of traces) { if (entry) {
// eslint-disable-next-line no-console for (var trace of entry.traces) {
console.log(trace); // eslint-disable-next-line no-console
console.log(trace);
}
} }
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

@ -777,18 +777,19 @@ export function get(signal) {
var trace = get_stack('TracedAt'); var trace = get_stack('TracedAt');
if (trace) { if (trace) {
var traces = tracing_expressions.entries.get(signal); var entry = tracing_expressions.entries.get(signal);
if (traces === undefined) { if (entry === undefined) {
tracing_expressions.entries.set(signal, (traces = [])); entry = { traces: [] };
tracing_expressions.entries.set(signal, entry);
} }
var last = traces.at(-1); var last = entry.traces.at(-1);
// traces can be duplicated, e.g. by `snapshot` invoking both // traces can be duplicated, e.g. by `snapshot` invoking both
// both `getOwnPropertyDescriptor` and `get` traps at once // both `getOwnPropertyDescriptor` and `get` traps at once
if (trace.stack !== last?.stack) { if (trace.stack !== last?.stack) {
traces.push(trace); entry.traces.push(trace);
} }
} }
} }

Loading…
Cancel
Save