From 75c448cb72975b80946f9caa7c4fcb15d2845ef7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 10 Jun 2025 14:18:28 -0400 Subject: [PATCH] remove PROXY_REMOVE_PATH --- .../client/visitors/VariableDeclaration.js | 25 +++++++------------ .../svelte/src/internal/client/constants.js | 2 -- packages/svelte/src/internal/client/proxy.js | 1 - .../src/internal/client/reactivity/sources.js | 7 ++---- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js index 13869229b5..b531f0df6e 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js @@ -9,7 +9,6 @@ import { get_rune } from '../../../scope.js'; import { get_prop_source, is_prop_source, is_state_source, should_proxy } from '../utils.js'; import { is_hoisted_function } from '../../utils.js'; import { get_value } from './shared/declarations.js'; -import { PROXY_REMOVE_PATH } from '#client/constants'; /** * @param {VariableDeclaration} node @@ -90,12 +89,7 @@ export function VariableDeclaration(node, context) { binding.kind === 'bindable_prop' && should_proxy(initial, context.state.scope) ) { - initial = b.call( - '$.proxy', - initial, - dev ? b.literal(id.name) : undefined, - dev ? b.literal(PROXY_REMOVE_PATH) : undefined - ); + initial = b.call('$.proxy', initial, dev ? b.literal(id.name) : undefined); } if (is_prop_source(binding, context.state)) { @@ -136,20 +130,19 @@ export function VariableDeclaration(node, context) { ); const is_state = is_state_source(binding, context.state.analysis); const is_proxy = should_proxy(value, context.state.scope); + if (rune === '$state' && is_proxy) { - value = b.call( - '$.proxy', - value, - dev ? b.literal(id.name) : undefined, - dev ? b.literal(PROXY_REMOVE_PATH) : undefined - ); + value = b.call('$.proxy', value, dev ? b.literal(id.name) : undefined); } + if (is_state) { value = b.call('$.state', value); + + if (dev) { + value = b.call('$.tag', value, b.literal(id.name)); + } } - if (dev && is_state) { - value = b.call('$.tag', value, b.literal(id.name)); - } + return value; }; diff --git a/packages/svelte/src/internal/client/constants.js b/packages/svelte/src/internal/client/constants.js index 98695bf751..268ba29c88 100644 --- a/packages/svelte/src/internal/client/constants.js +++ b/packages/svelte/src/internal/client/constants.js @@ -27,8 +27,6 @@ export const EFFECT_IS_UPDATING = 1 << 21; export const PROXY_PRESERVE_PATH = 1 << 1; /** Change proxy path to new "owner" */ export const PROXY_CHANGE_PATH = 1 << 2; -/** "Unown" proxy, so its path becomes `[$state proxy]` */ -export const PROXY_REMOVE_PATH = 1 << 3; export const STATE_SYMBOL = Symbol('$state'); export const LEGACY_PROPS = Symbol('legacy props'); diff --git a/packages/svelte/src/internal/client/proxy.js b/packages/svelte/src/internal/client/proxy.js index 993c6f45a2..6237655e49 100644 --- a/packages/svelte/src/internal/client/proxy.js +++ b/packages/svelte/src/internal/client/proxy.js @@ -13,7 +13,6 @@ import { PROXY_CHANGE_PATH, PROXY_PATH_SYMBOL, PROXY_PRESERVE_PATH, - PROXY_REMOVE_PATH, STATE_SYMBOL } from '#client/constants'; import { UNINITIALIZED } from '../../constants.js'; diff --git a/packages/svelte/src/internal/client/reactivity/sources.js b/packages/svelte/src/internal/client/reactivity/sources.js index 847f14d2ec..ad5ad3383d 100644 --- a/packages/svelte/src/internal/client/reactivity/sources.js +++ b/packages/svelte/src/internal/client/reactivity/sources.js @@ -27,8 +27,7 @@ import { UNOWNED, MAYBE_DIRTY, BLOCK_EFFECT, - ROOT_EFFECT, - PROXY_REMOVE_PATH + ROOT_EFFECT } from '#client/constants'; import * as e from '../errors.js'; import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js'; @@ -140,9 +139,7 @@ export function set(source, value, should_proxy = false) { e.state_unsafe_mutation(); } - let new_value = should_proxy - ? proxy(value, DEV ? source.trace_name : undefined, DEV ? PROXY_REMOVE_PATH : undefined) - : value; + let new_value = should_proxy ? proxy(value, DEV ? source.trace_name : undefined) : value; return internal_set(source, new_value); }