Skip to content

Commit 7383059

Browse files
authored
chore: clarify usage of accessors (#10522)
1 parent fbb8839 commit 7383059

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

packages/svelte/src/internal/client/custom-element.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,15 @@ function get_custom_elements_slots(element) {
276276
* @param {any} Component A Svelte component function
277277
* @param {Record<string, CustomElementPropDefinition>} props_definition The props to observe
278278
* @param {string[]} slots The slots to create
279-
* @param {string[]} accessors Other accessors besides the ones for props the component has
279+
* @param {string[]} exports Explicitly exported values, other than props
280280
* @param {boolean} use_shadow_dom Whether to use shadow DOM
281281
* @param {(ce: new () => HTMLElement) => new () => HTMLElement} [extend]
282282
*/
283283
export function create_custom_element(
284284
Component,
285285
props_definition,
286286
slots,
287-
accessors,
287+
exports,
288288
use_shadow_dom,
289289
extend
290290
) {
@@ -311,10 +311,10 @@ export function create_custom_element(
311311
}
312312
});
313313
});
314-
accessors.forEach((accessor) => {
315-
define_property(Class.prototype, accessor, {
314+
exports.forEach((property) => {
315+
define_property(Class.prototype, property, {
316316
get() {
317-
return this.$$c?.[accessor];
317+
return this.$$c?.[property];
318318
}
319319
});
320320
});

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,7 +2836,7 @@ export function createRoot() {
28362836
}
28372837

28382838
/**
2839-
* Mounts a component to the given target and returns the exports and potentially the accessors (if compiled with `accessors: true`) of the component
2839+
* Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component
28402840
*
28412841
* @template {Record<string, any>} Props
28422842
* @template {Record<string, any>} Exports
@@ -2860,7 +2860,7 @@ export function mount(component, options) {
28602860
}
28612861

28622862
/**
2863-
* Hydrates a component on the given target and returns the exports and potentially the accessors (if compiled with `accessors: true`) of the component
2863+
* Hydrates a component on the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component
28642864
*
28652865
* @template {Record<string, any>} Props
28662866
* @template {Record<string, any>} Exports
@@ -2932,7 +2932,7 @@ export function hydrate(component, options) {
29322932
* @template {Record<string, any>} Props
29332933
* @template {Record<string, any>} Exports
29342934
* @template {Record<string, any>} Events
2935-
* @param {import('../../main/public.js').ComponentType<import('../../main/public.js').SvelteComponent<Props, Events>>} component
2935+
* @param {import('../../main/public.js').ComponentType<import('../../main/public.js').SvelteComponent<Props, Events>>} Component
29362936
* @param {{
29372937
* target: Node;
29382938
* anchor: null | Text;
@@ -2944,14 +2944,14 @@ export function hydrate(component, options) {
29442944
* }} options
29452945
* @returns {Exports}
29462946
*/
2947-
function _mount(component, options) {
2947+
function _mount(Component, options) {
29482948
const registered_events = new Set();
29492949
const container = options.target;
29502950
const block = create_root_block(options.intro || false);
29512951

29522952
/** @type {Exports} */
29532953
// @ts-expect-error will be defined because the render effect runs synchronously
2954-
let accessors = undefined;
2954+
let component = undefined;
29552955

29562956
const effect = render_effect(
29572957
() => {
@@ -2961,7 +2961,7 @@ function _mount(component, options) {
29612961
options.context;
29622962
}
29632963
// @ts-expect-error the public typings are not what the actual function looks like
2964-
accessors = component(options.anchor, options.props || {}) || {};
2964+
component = Component(options.anchor, options.props || {}) || {};
29652965
if (options.context) {
29662966
pop();
29672967
}
@@ -3008,7 +3008,7 @@ function _mount(component, options) {
30083008
event_handle(array_from(all_registerd_events));
30093009
root_event_handles.add(event_handle);
30103010

3011-
mounted_components.set(accessors, () => {
3011+
mounted_components.set(component, () => {
30123012
for (const event_name of registered_events) {
30133013
container.removeEventListener(event_name, bound_event_listener);
30143014
}
@@ -3020,11 +3020,11 @@ function _mount(component, options) {
30203020
destroy_signal(/** @type {import('./types.js').EffectSignal} */ (block.e));
30213021
});
30223022

3023-
return accessors;
3023+
return component;
30243024
}
30253025

30263026
/**
3027-
* References of the accessors of all components that were `mount`ed or `hydrate`d.
3027+
* References of the components that were mounted or hydrated.
30283028
* Uses a `WeakMap` to avoid memory leaks.
30293029
*/
30303030
let mounted_components = new WeakMap();
@@ -3034,12 +3034,12 @@ let mounted_components = new WeakMap();
30343034
* @param {Record<string, any>} component
30353035
*/
30363036
export function unmount(component) {
3037-
const destroy = mounted_components.get(component);
3038-
if (DEV && !destroy) {
3037+
const fn = mounted_components.get(component);
3038+
if (DEV && !fn) {
30393039
// eslint-disable-next-line no-console
30403040
console.warn('Tried to unmount a component that was not mounted.');
30413041
}
3042-
destroy?.();
3042+
fn?.();
30433043
}
30443044

30453045
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,8 +1884,8 @@ function on_destroy(fn) {
18841884
*/
18851885
export function push(props, runes = false) {
18861886
current_component_context = {
1887-
// accessors
1888-
a: null,
1887+
// exports (and props, if `accessors: true`)
1888+
x: null,
18891889
// context
18901890
c: null,
18911891
// effects
@@ -1914,7 +1914,7 @@ export function pop(component) {
19141914
const context_stack_item = current_component_context;
19151915
if (context_stack_item !== null) {
19161916
if (component !== undefined) {
1917-
context_stack_item.a = component;
1917+
context_stack_item.x = component;
19181918
}
19191919
const effects = context_stack_item.e;
19201920
if (effects !== null) {

packages/svelte/src/internal/client/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export type ComponentContext = {
4040
d: null | Signal<any>[];
4141
/** props */
4242
s: Record<string, unknown>;
43-
/** accessors */
44-
a: Record<string, any> | null;
43+
/** exports (and props, if `accessors: true`) */
44+
x: Record<string, any> | null;
4545
/** effects */
4646
e: null | Array<EffectSignal>;
4747
/** mounted */

packages/svelte/src/main/main-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export function createEventDispatcher() {
164164
// in a server (non-DOM) environment?
165165
const event = create_custom_event(/** @type {string} */ (type), detail, options);
166166
for (const fn of callbacks) {
167-
fn.call(component_context.a, event);
167+
fn.call(component_context.x, event);
168168
}
169169
return !event.defaultPrevented;
170170
}

packages/svelte/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ declare module 'svelte' {
328328
*/
329329
export function createRoot(): void;
330330
/**
331-
* Mounts a component to the given target and returns the exports and potentially the accessors (if compiled with `accessors: true`) of the component
331+
* Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component
332332
*
333333
* */
334334
export function mount<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>>(component: ComponentType<SvelteComponent<Props, Events, any>>, options: {
@@ -339,7 +339,7 @@ declare module 'svelte' {
339339
intro?: boolean | undefined;
340340
}): Exports;
341341
/**
342-
* Hydrates a component on the given target and returns the exports and potentially the accessors (if compiled with `accessors: true`) of the component
342+
* Hydrates a component on the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component
343343
*
344344
* */
345345
export function hydrate<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>>(component: ComponentType<SvelteComponent<Props, Events, any>>, options: {

0 commit comments

Comments
 (0)