chore: dedupe stack stuff

dedupe-stack-stuff
Rich Harris 8 months ago
parent 3c36c7e4e8
commit 77077da9a3

@ -1,8 +1,8 @@
import { UNINITIALIZED } from '../../../constants.js';
import { snapshot } from '../../shared/clone.js';
import { get_stack } from '../../shared/dev.js';
import { eager_effect, render_effect, validate_effect } from '../reactivity/effects.js';
import { untrack } from '../runtime.js';
import { get_stack } from './tracing.js';
/**
* @param {() => any[]} get_value

@ -130,44 +130,6 @@ export function trace(label, fn) {
}
}
/**
* @param {string} label
* @returns {Error & { stack: string } | null}
*/
export function get_stack(label) {
return get_infinite_stack(label, (stack) => {
if (!stack) return;
const lines = stack.split('\n');
const new_lines = ['\n'];
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const posixified = line.replaceAll('\\', '/');
if (line === 'Error') {
continue;
}
if (line.includes('validate_each_keys')) {
return undefined;
}
if (posixified.includes('svelte/src/internal') || posixified.includes('node_modules/.vite')) {
continue;
}
new_lines.push(line);
}
if (new_lines.length === 1) {
return undefined;
}
return new_lines.join('\n');
});
}
/**
* @param {Value} source
* @param {string} label

@ -25,8 +25,9 @@ import {
import { PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
import { UNINITIALIZED } from '../../constants.js';
import * as e from './errors.js';
import { get_stack, tag } from './dev/tracing.js';
import { tag } from './dev/tracing.js';
import { tracing_mode_flag } from '../flags/index.js';
import { get_stack } from '../shared/dev.js';
// TODO move all regexes into shared module?
const regex_is_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;

@ -28,7 +28,6 @@ import * as e from '../errors.js';
import * as w from '../warnings.js';
import { async_effect, destroy_effect, effect_tracking, teardown } from './effects.js';
import { eager_effects, internal_set, set_eager_effects, source } from './sources.js';
import { get_stack } from '../dev/tracing.js';
import { async_mode_flag, tracing_mode_flag } from '../../flags/index.js';
import { Boundary } from '../dom/blocks/boundary.js';
import { component_context } from '../context.js';
@ -36,6 +35,7 @@ import { UNINITIALIZED } from '../../../constants.js';
import { batch_values, current_batch } from './batch.js';
import { unset_context } from './async.js';
import { deferred } from '../../shared/utils.js';
import { get_stack } from '../../shared/dev.js';
/** @type {Effect | null} */
export let current_async_effect = null;

@ -32,11 +32,12 @@ import {
} from '#client/constants';
import * as e from '../errors.js';
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
import { get_stack, tag_proxy } from '../dev/tracing.js';
import { tag_proxy } from '../dev/tracing.js';
import { component_context, is_runes } from '../context.js';
import { Batch, batch_values, eager_block_effects, schedule_effect } from './batch.js';
import { proxy } from '../proxy.js';
import { execute_derived } from './deriveds.js';
import { get_stack } from '../../shared/dev.js';
/** @type {Set<any>} */
export let eager_effects = new Set();

@ -32,7 +32,7 @@ import {
update_derived
} from './reactivity/deriveds.js';
import { async_mode_flag, tracing_mode_flag } from '../flags/index.js';
import { tracing_expressions, get_stack } from './dev/tracing.js';
import { tracing_expressions } from './dev/tracing.js';
import {
component_context,
dev_current_component_function,
@ -48,6 +48,7 @@ import { handle_error } from './error-handling.js';
import { UNINITIALIZED } from '../../constants.js';
import { captured_signals } from './legacy.js';
import { without_reactive_context } from './dom/elements/bindings/shared.js';
import { get_stack } from '../shared/dev.js';
export let is_updating_effect = false;

@ -2,23 +2,51 @@ import { define_property } from './utils.js';
/**
* @param {string} label
* @param {(stack: string | undefined) => string | undefined} fn
* @returns {Error & { stack: string } | null}
*/
export function get_infinite_stack(label, fn) {
// @ts-ignore - doesn't exist everywhere
export function get_stack(label) {
// @ts-ignore stackTraceLimit doesn't exist everywhere
const limit = Error.stackTraceLimit;
// @ts-ignore - doesn't exist everywhere
// @ts-ignore
Error.stackTraceLimit = Infinity;
let error = Error();
// @ts-ignore - doesn't exist everywhere
// @ts-ignore
Error.stackTraceLimit = limit;
const stack = fn(error.stack);
const stack = error.stack;
if (!stack) return null;
const lines = stack.split('\n');
const new_lines = ['\n'];
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const posixified = line.replaceAll('\\', '/');
if (line === 'Error') {
continue;
}
if (line.includes('validate_each_keys')) {
return null;
}
if (posixified.includes('svelte/src/internal') || posixified.includes('node_modules/.vite')) {
continue;
}
new_lines.push(line);
}
if (new_lines.length === 1) {
return null;
}
define_property(error, 'stack', {
value: stack
value: new_lines.join('\n')
});
define_property(error, 'name', {

Loading…
Cancel
Save