Skip to content

Commit 197cfbe

Browse files
authored
remove PROXY_REMOVE_PATH (#16126)
* remove PROXY_REMOVE_PATH * simplify a bit * simplify * tweak * tweak implementation * tweak implementation * tweak implementation * hoist * tweak * fix * WIP (reduce number of with_parent calls, move towards possibility of combining tag and tag_proxy) * DRY out
1 parent 3d161ee commit 197cfbe

File tree

7 files changed

+135
-116
lines changed

7 files changed

+135
-116
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { get_rune } from '../../../scope.js';
99
import { get_prop_source, is_prop_source, is_state_source, should_proxy } from '../utils.js';
1010
import { is_hoisted_function } from '../../utils.js';
1111
import { get_value } from './shared/declarations.js';
12-
import { PROXY_REMOVE_PATH } from '#client/constants';
1312

1413
/**
1514
* @param {VariableDeclaration} node
@@ -90,12 +89,11 @@ export function VariableDeclaration(node, context) {
9089
binding.kind === 'bindable_prop' &&
9190
should_proxy(initial, context.state.scope)
9291
) {
93-
initial = b.call(
94-
'$.proxy',
95-
initial,
96-
dev ? b.literal(id.name) : undefined,
97-
dev ? b.literal(PROXY_REMOVE_PATH) : undefined
98-
);
92+
initial = b.call('$.proxy', initial);
93+
94+
if (dev) {
95+
initial = b.call('$.tag_proxy', initial, b.literal(id.name));
96+
}
9997
}
10098

10199
if (is_prop_source(binding, context.state)) {
@@ -136,20 +134,23 @@ export function VariableDeclaration(node, context) {
136134
);
137135
const is_state = is_state_source(binding, context.state.analysis);
138136
const is_proxy = should_proxy(value, context.state.scope);
137+
139138
if (rune === '$state' && is_proxy) {
140-
value = b.call(
141-
'$.proxy',
142-
value,
143-
dev ? b.literal(id.name) : undefined,
144-
dev ? b.literal(PROXY_REMOVE_PATH) : undefined
145-
);
139+
value = b.call('$.proxy', value);
140+
141+
if (dev && !is_state) {
142+
value = b.call('$.tag_proxy', value, b.literal(id.name));
143+
}
146144
}
145+
147146
if (is_state) {
148147
value = b.call('$.state', value);
148+
149+
if (dev) {
150+
value = b.call('$.tag', value, b.literal(id.name));
151+
}
149152
}
150-
if (dev && is_state) {
151-
value = b.call('$.tag', value, b.literal(id.name));
152-
}
153+
153154
return value;
154155
};
155156

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ export const HEAD_EFFECT = 1 << 19;
2222
export const EFFECT_HAS_DERIVED = 1 << 20;
2323
export const EFFECT_IS_UPDATING = 1 << 21;
2424

25-
// `$inspect.trace` proxy path flags
26-
/** Keep path the same */
27-
export const PROXY_PRESERVE_PATH = 1 << 1;
28-
/** Change proxy path to new "owner" */
29-
export const PROXY_CHANGE_PATH = 1 << 2;
30-
/** "Unown" proxy, so its path becomes `[$state proxy]` */
31-
export const PROXY_REMOVE_PATH = 1 << 3;
32-
3325
export const STATE_SYMBOL = Symbol('$state');
3426
export const LEGACY_PROPS = Symbol('legacy props');
3527
export const LOADING_ATTR_SYMBOL = Symbol('');

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { UNINITIALIZED } from '../../../constants.js';
33
import { snapshot } from '../../shared/clone.js';
44
import { define_property } from '../../shared/utils.js';
5-
import { DERIVED, STATE_SYMBOL } from '#client/constants';
5+
import { DERIVED, PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
66
import { effect_tracking } from '../reactivity/effects.js';
77
import { active_reaction, captured_signals, set_captured_signals, untrack } from '../runtime.js';
88

@@ -43,7 +43,7 @@ function log_entry(signal, entry) {
4343
const type = (signal.f & DERIVED) !== 0 ? '$derived' : '$state';
4444
const current_reaction = /** @type {Reaction} */ (active_reaction);
4545
const dirty = signal.wv > current_reaction.wv || current_reaction.wv === 0;
46-
const { trace_name: name } = signal;
46+
const { label: name } = signal;
4747
const style = dirty
4848
? 'color: CornflowerBlue; font-weight: bold'
4949
: 'color: grey; font-weight: normal';
@@ -183,13 +183,25 @@ export function get_stack(label) {
183183

184184
/**
185185
* @param {Value} source
186-
* @param {string} name
186+
* @param {string} label
187187
*/
188-
export function tag(source, name) {
189-
source.trace_name = name;
188+
export function tag(source, label) {
189+
source.label = label;
190+
tag_proxy(source.v, label);
191+
190192
return source;
191193
}
192194

195+
/**
196+
* @param {unknown} value
197+
* @param {string} label
198+
*/
199+
export function tag_proxy(value, label) {
200+
// @ts-expect-error
201+
value?.[PROXY_PATH_SYMBOL]?.(label);
202+
return value;
203+
}
204+
193205
/**
194206
* @param {unknown} value
195207
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export { add_locations } from './dev/elements.js';
77
export { hmr } from './dev/hmr.js';
88
export { create_ownership_validator } from './dev/ownership.js';
99
export { check_target, legacy_api } from './dev/legacy.js';
10-
export { trace, tag } from './dev/tracing.js';
10+
export { trace, tag, tag_proxy } from './dev/tracing.js';
1111
export { inspect } from './dev/inspect.js';
1212
export { validate_snippet_args } from './dev/validation.js';
1313
export { await_block as await } from './dom/blocks/await.js';

0 commit comments

Comments
 (0)