Skip to content

Commit bc10aba

Browse files
committed
remove exposable/expose stuff
1 parent cb0bf61 commit bc10aba

File tree

4 files changed

+16
-106
lines changed

4 files changed

+16
-106
lines changed

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -795,32 +795,17 @@ function serialize_inline_component(node, component_name, context) {
795795
push_prop(
796796
b.get(attribute.name, [
797797
b.return(
798-
b.call(
799-
'$.exposable',
800-
b.thunk(
801-
/** @type {import('estree').Expression} */ (context.visit(attribute.expression))
802-
)
803-
)
798+
/** @type {import('estree').Expression} */ (context.visit(attribute.expression))
804799
)
805800
])
806801
);
807-
// If the binding is just a reference to a top level state variable
808-
// we don't need a setter as the inner component can write to the signal directly
809-
const binding =
810-
attribute.expression.type !== 'Identifier'
811-
? null
812-
: context.state.scope.get(attribute.expression.name);
813-
if (
814-
binding === null ||
815-
(binding.kind !== 'state' && binding.kind !== 'prop' && binding.kind !== 'rest_prop')
816-
) {
817-
const assignment = b.assignment('=', attribute.expression, b.id('$$value'));
818-
push_prop(
819-
b.set(attribute.name, [
820-
b.stmt(serialize_set_binding(assignment, context, () => context.visit(assignment)))
821-
])
822-
);
823-
}
802+
803+
const assignment = b.assignment('=', attribute.expression, b.id('$$value'));
804+
push_prop(
805+
b.set(attribute.name, [
806+
b.stmt(serialize_set_binding(assignment, context, () => context.visit(assignment)))
807+
])
808+
);
824809
}
825810
}
826811
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
untrack,
3535
effect,
3636
flushSync,
37-
expose,
3837
safe_not_equal,
3938
current_block,
4039
source,
@@ -1193,10 +1192,7 @@ export function bind_prop(props, prop, value) {
11931192
/** @param {V | null} value */
11941193
const update = (value) => {
11951194
const current_props = unwrap(props);
1196-
const signal = expose(() => current_props[prop]);
1197-
if (is_signal(signal)) {
1198-
set(signal, value);
1199-
} else if (Object.getOwnPropertyDescriptor(current_props, prop)?.set !== undefined) {
1195+
if (get_descriptor(current_props, prop)?.set !== undefined) {
12001196
current_props[prop] = value;
12011197
}
12021198
};

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

Lines changed: 7 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DEV } from 'esm-env';
22
import { subscribe_to_store } from '../../store/utils.js';
33
import { EMPTY_FUNC, run_all } from '../common.js';
4-
import { get_descriptors, is_array } from './utils.js';
4+
import { get_descriptor, get_descriptors, is_array } from './utils.js';
55
import { PROPS_CALL_DEFAULT_VALUE, PROPS_IS_IMMUTABLE } from '../../constants.js';
66

77
export const SOURCE = 1;
@@ -31,8 +31,7 @@ let current_scheduler_mode = FLUSH_MICROTASK;
3131
// Used for handling scheduling
3232
let is_micro_task_queued = false;
3333
let is_task_queued = false;
34-
// Used for exposing signals
35-
let is_signal_exposed = false;
34+
3635
// Handle effect queues
3736

3837
/** @type {import('./types.js').EffectSignal[]} */
@@ -64,8 +63,6 @@ export let current_untracking = false;
6463
/** Exists to opt out of the mutation validation for stores which may be set for the first time during a derivation */
6564
let ignore_mutation_validation = false;
6665

67-
/** @type {null | import('./types.js').Signal} */
68-
let current_captured_signal = null;
6966
// If we are working with a get() chain that has no active container,
7067
// to prevent memory leaks, we skip adding the consumer.
7168
let current_skip_consumer = false;
@@ -801,23 +798,6 @@ export function unsubscribe_on_destroy(stores) {
801798
});
802799
}
803800

804-
/**
805-
* Wraps a function and marks execution context so that the last signal read from can be captured
806-
* using the `expose` function.
807-
* @template V
808-
* @param {() => V} fn
809-
* @returns {V}
810-
*/
811-
export function exposable(fn) {
812-
const previous_is_signal_exposed = is_signal_exposed;
813-
try {
814-
is_signal_exposed = true;
815-
return fn();
816-
} finally {
817-
is_signal_exposed = previous_is_signal_exposed;
818-
}
819-
}
820-
821801
/**
822802
* @template V
823803
* @param {import('./types.js').Signal<V>} signal
@@ -837,10 +817,6 @@ export function get(signal) {
837817
return signal.v;
838818
}
839819

840-
if (is_signal_exposed && current_should_capture_signal) {
841-
current_captured_signal = signal;
842-
}
843-
844820
if (is_signals_recorded) {
845821
captured_signals.add(signal);
846822
}
@@ -907,31 +883,6 @@ export function set_sync(signal, value) {
907883
flushSync(() => set(signal, value));
908884
}
909885

910-
/**
911-
* Invokes a function and captures the last signal that is read during the invocation
912-
* if that signal is read within the `exposable` function context.
913-
* If a signal is captured, it returns the signal instead of the read value.
914-
* @template V
915-
* @param {() => V} possible_signal_fn
916-
* @returns {any}
917-
*/
918-
export function expose(possible_signal_fn) {
919-
const previous_captured_signal = current_captured_signal;
920-
const previous_should_capture_signal = current_should_capture_signal;
921-
current_captured_signal = null;
922-
current_should_capture_signal = true;
923-
try {
924-
const value = possible_signal_fn();
925-
if (current_captured_signal === null) {
926-
return value;
927-
}
928-
return current_captured_signal;
929-
} finally {
930-
current_captured_signal = previous_captured_signal;
931-
current_should_capture_signal = previous_should_capture_signal;
932-
}
933-
}
934-
935886
/**
936887
* Invokes a function and captures all signals that are read during the invocation,
937888
* then invalidates them.
@@ -1473,28 +1424,10 @@ export function prop_source(props_obj, key, flags, default_value) {
14731424
const immutable = (flags & PROPS_IS_IMMUTABLE) !== 0;
14741425

14751426
const props = is_signal(props_obj) ? get(props_obj) : props_obj;
1476-
const possible_signal = /** @type {import('./types.js').MaybeSignal<V>} */ (
1477-
expose(() => props[key])
1478-
);
1479-
const update_bound_prop = Object.getOwnPropertyDescriptor(props, key)?.set;
1427+
const update_bound_prop = get_descriptor(props, key)?.set;
14801428
let value = props[key];
14811429
const should_set_default_value = value === undefined && default_value !== undefined;
14821430

1483-
if (
1484-
is_signal(possible_signal) &&
1485-
possible_signal.v === value &&
1486-
update_bound_prop === undefined
1487-
) {
1488-
if (should_set_default_value) {
1489-
set(
1490-
possible_signal,
1491-
// @ts-expect-error would need a cumbersome method overload to type this
1492-
call_default_value ? default_value() : default_value
1493-
);
1494-
}
1495-
return possible_signal;
1496-
}
1497-
14981431
if (should_set_default_value) {
14991432
value =
15001433
// @ts-expect-error would need a cumbersome method overload to type this
@@ -1537,7 +1470,7 @@ export function prop_source(props_obj, key, flags, default_value) {
15371470
}
15381471
});
15391472

1540-
if (is_signal(possible_signal) && update_bound_prop !== undefined) {
1473+
if (update_bound_prop !== undefined) {
15411474
let ignore_first = !should_set_default_value;
15421475
sync_effect(() => {
15431476
// Before if to ensure signal dependency is registered
@@ -1551,11 +1484,9 @@ export function prop_source(props_obj, key, flags, default_value) {
15511484
return;
15521485
}
15531486

1554-
if (not_equal(immutable, propagating_value, possible_signal.v)) {
1555-
ignore_next1 = true;
1556-
did_update_to_defined = true;
1557-
untrack(() => update_bound_prop(propagating_value));
1558-
}
1487+
ignore_next1 = true;
1488+
did_update_to_defined = true;
1489+
untrack(() => update_bound_prop(propagating_value));
15591490
});
15601491
}
15611492

packages/svelte/src/internal/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export {
44
set,
55
set_sync,
66
invalidate_inner_signals,
7-
expose,
8-
exposable,
97
source,
108
mutable_source,
119
derived,

0 commit comments

Comments
 (0)