File tree Expand file tree Collapse file tree 1 file changed +21
-10
lines changed
packages/svelte/src/internal/client Expand file tree Collapse file tree 1 file changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -16,20 +16,29 @@ import * as w from './warnings.js';
1616import { get_stack } from './dev/tracing.js' ;
1717import { tracing_mode_flag } from '../flags/index.js' ;
1818
19+ /**
20+ * @param {unknown } value
21+ * @returns {boolean }
22+ */
23+ function should_proxy ( value ) {
24+ if ( typeof value !== 'object' || value === null || STATE_SYMBOL in value ) {
25+ return false ;
26+ }
27+ const prototype = get_prototype_of ( value ) ;
28+ if ( prototype !== object_prototype && prototype !== array_prototype ) {
29+ return false ;
30+ }
31+ return true ;
32+ }
33+
1934/**
2035 * @template T
2136 * @param {T } value
2237 * @returns {T }
2338 */
2439export function proxy ( value ) {
2540 // if non-proxyable, or is already a proxy, return `value`
26- if ( typeof value !== 'object' || value === null || STATE_SYMBOL in value ) {
27- return value ;
28- }
29-
30- const prototype = get_prototype_of ( value ) ;
31-
32- if ( prototype !== object_prototype && prototype !== array_prototype ) {
41+ if ( ! should_proxy ( value ) ) {
3342 return value ;
3443 }
3544
@@ -289,10 +298,12 @@ export function proxy(value) {
289298 * @returns {T | void }
290299 */
291300export function return_proxy ( value ) {
292- const res = proxy ( value ) ;
293- if ( res !== value || ( typeof value === 'object' && value !== null && STATE_SYMBOL in value ) ) {
301+ if (
302+ ! should_proxy ( value ) &&
303+ ! ( typeof value === 'object' && value !== null && STATE_SYMBOL in value )
304+ ) {
294305 // if the argument passed was already a proxy, we don't warn
295- return res ;
306+ return proxy ( value ) ;
296307 }
297308 w . state_return_not_proxyable ( ) ;
298309}
You can’t perform that action at this time.
0 commit comments