Skip to content

Commit eba64f7

Browse files
authored
chore: improve runtime variable naming (#13275)
1 parent ed7611b commit eba64f7

File tree

14 files changed

+166
-172
lines changed

14 files changed

+166
-172
lines changed

packages/svelte/src/index-client.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @import { ComponentContext, ComponentContextLegacy } from '#client' */
22
/** @import { EventDispatcher } from './index.js' */
33
/** @import { NotFunction } from './internal/types.js' */
4-
import { current_component_context, flush_sync, untrack } from './internal/client/runtime.js';
4+
import { component_context, flush_sync, untrack } from './internal/client/runtime.js';
55
import { is_array } from './internal/shared/utils.js';
66
import { user_effect } from './internal/client/index.js';
77
import * as e from './internal/client/errors.js';
@@ -22,12 +22,12 @@ import { lifecycle_outside_component } from './internal/shared/errors.js';
2222
* @returns {void}
2323
*/
2424
export function onMount(fn) {
25-
if (current_component_context === null) {
25+
if (component_context === null) {
2626
lifecycle_outside_component('onMount');
2727
}
2828

29-
if (current_component_context.l !== null) {
30-
init_update_callbacks(current_component_context).m.push(fn);
29+
if (component_context.l !== null) {
30+
init_update_callbacks(component_context).m.push(fn);
3131
} else {
3232
user_effect(() => {
3333
const cleanup = untrack(fn);
@@ -47,7 +47,7 @@ export function onMount(fn) {
4747
* @returns {void}
4848
*/
4949
export function onDestroy(fn) {
50-
if (current_component_context === null) {
50+
if (component_context === null) {
5151
lifecycle_outside_component('onDestroy');
5252
}
5353

@@ -90,14 +90,14 @@ function create_custom_event(type, detail, { bubbles = false, cancelable = false
9090
* @returns {EventDispatcher<EventMap>}
9191
*/
9292
export function createEventDispatcher() {
93-
const component_context = current_component_context;
94-
if (component_context === null) {
93+
const active_component_context = component_context;
94+
if (active_component_context === null) {
9595
lifecycle_outside_component('createEventDispatcher');
9696
}
9797

9898
return (type, detail, options) => {
9999
const events = /** @type {Record<string, Function | Function[]>} */ (
100-
component_context.s.$$events
100+
active_component_context.s.$$events
101101
)?.[/** @type {any} */ (type)];
102102

103103
if (events) {
@@ -106,7 +106,7 @@ export function createEventDispatcher() {
106106
// in a server (non-DOM) environment?
107107
const event = create_custom_event(/** @type {string} */ (type), detail, options);
108108
for (const fn of callbacks) {
109-
fn.call(component_context.x, event);
109+
fn.call(active_component_context.x, event);
110110
}
111111
return !event.defaultPrevented;
112112
}
@@ -130,15 +130,15 @@ export function createEventDispatcher() {
130130
* @returns {void}
131131
*/
132132
export function beforeUpdate(fn) {
133-
if (current_component_context === null) {
133+
if (component_context === null) {
134134
lifecycle_outside_component('beforeUpdate');
135135
}
136136

137-
if (current_component_context.l === null) {
137+
if (component_context.l === null) {
138138
e.lifecycle_legacy_only('beforeUpdate');
139139
}
140140

141-
init_update_callbacks(current_component_context).b.push(fn);
141+
init_update_callbacks(component_context).b.push(fn);
142142
}
143143

144144
/**
@@ -154,15 +154,15 @@ export function beforeUpdate(fn) {
154154
* @returns {void}
155155
*/
156156
export function afterUpdate(fn) {
157-
if (current_component_context === null) {
157+
if (component_context === null) {
158158
lifecycle_outside_component('afterUpdate');
159159
}
160160

161-
if (current_component_context.l === null) {
161+
if (component_context.l === null) {
162162
e.lifecycle_legacy_only('afterUpdate');
163163
}
164164

165-
init_update_callbacks(current_component_context).a.push(fn);
165+
init_update_callbacks(component_context).a.push(fn);
166166
}
167167

168168
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as e from '../errors.js';
2-
import { current_component_context } from '../runtime.js';
2+
import { component_context } from '../runtime.js';
33
import { FILENAME } from '../../../constants.js';
44
import { get_component } from './ownership.js';
55

@@ -11,7 +11,7 @@ export function check_target(target) {
1111
}
1212

1313
export function legacy_api() {
14-
const component = current_component_context?.function;
14+
const component = component_context?.function;
1515

1616
/** @param {string} method */
1717
function error(method) {

packages/svelte/src/internal/client/dom/blocks/await.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/** @import { Effect, Source, TemplateNode } from '#client' */
22
import { is_promise, noop } from '../../../shared/utils.js';
33
import {
4-
current_component_context,
4+
component_context,
55
flush_sync,
66
is_runes,
7-
set_current_component_context,
8-
set_current_effect,
9-
set_current_reaction,
7+
set_component_context,
8+
set_active_effect,
9+
set_active_reaction,
1010
set_dev_current_component_function
1111
} from '../../runtime.js';
1212
import { block, branch, pause_effect, resume_effect } from '../../reactivity/effects.js';
@@ -35,7 +35,7 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
3535

3636
var anchor = node;
3737
var runes = is_runes();
38-
var component_context = current_component_context;
38+
var active_component_context = component_context;
3939

4040
/** @type {any} */
4141
var component_function = DEV ? component_context?.function : null;
@@ -64,9 +64,9 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
6464
resolved = true;
6565

6666
if (restore) {
67-
set_current_effect(effect);
68-
set_current_reaction(effect); // TODO do we need both?
69-
set_current_component_context(component_context);
67+
set_active_effect(effect);
68+
set_active_reaction(effect); // TODO do we need both?
69+
set_component_context(active_component_context);
7070
if (DEV) set_dev_current_component_function(component_function);
7171
}
7272

@@ -99,9 +99,9 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
9999

100100
if (restore) {
101101
if (DEV) set_dev_current_component_function(null);
102-
set_current_component_context(null);
103-
set_current_reaction(null);
104-
set_current_effect(null);
102+
set_component_context(null);
103+
set_active_reaction(null);
104+
set_active_effect(null);
105105

106106
// without this, the DOM does not update until two ticks after the promise
107107
// resolves, which is unexpected behaviour (and somewhat irksome to test)

packages/svelte/src/internal/client/dom/blocks/each.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { source, mutable_source, set } from '../../reactivity/sources.js';
3535
import { array_from, is_array } from '../../../shared/utils.js';
3636
import { INERT } from '../../constants.js';
3737
import { queue_micro_task } from '../task.js';
38-
import { current_effect } from '../../runtime.js';
38+
import { active_effect } from '../../runtime.js';
3939

4040
/**
4141
* The row of a keyed each block that is currently updating. We track this
@@ -426,8 +426,8 @@ function reconcile(array, state, anchor, render_fn, flags, get_key) {
426426
});
427427
}
428428

429-
/** @type {Effect} */ (current_effect).first = state.first && state.first.e;
430-
/** @type {Effect} */ (current_effect).last = prev && prev.e;
429+
/** @type {Effect} */ (active_effect).first = state.first && state.first.e;
430+
/** @type {Effect} */ (active_effect).last = prev && prev.e;
431431
}
432432

433433
/**

packages/svelte/src/internal/client/dom/blocks/svelte-element.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../../reactivity/effects.js';
1818
import { set_should_intro } from '../../render.js';
1919
import { current_each_item, set_current_each_item } from './each.js';
20-
import { current_component_context, current_effect } from '../../runtime.js';
20+
import { component_context, active_effect } from '../../runtime.js';
2121
import { DEV } from 'esm-env';
2222
import { EFFECT_TRANSPARENT } from '../../constants.js';
2323
import { assign_nodes } from '../template.js';
@@ -38,7 +38,7 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
3838
hydrate_next();
3939
}
4040

41-
var filename = DEV && location && current_component_context?.function[FILENAME];
41+
var filename = DEV && location && component_context?.function[FILENAME];
4242

4343
/** @type {string | null} */
4444
var tag;
@@ -138,7 +138,7 @@ export function element(node, get_tag, is_svg, render_fn, get_namespace, locatio
138138
}
139139

140140
// we do this after calling `render_fn` so that child effects don't override `nodes.end`
141-
/** @type {Effect} */ (current_effect).nodes_end = element;
141+
/** @type {Effect} */ (active_effect).nodes_end = element;
142142

143143
anchor.before(element);
144144
});

packages/svelte/src/internal/client/dom/elements/transitions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @import { AnimateFn, Animation, AnimationConfig, EachItem, Effect, TransitionFn, TransitionManager } from '#client' */
22
import { noop, is_function } from '../../../shared/utils.js';
33
import { effect } from '../../reactivity/effects.js';
4-
import { current_effect, untrack } from '../../runtime.js';
4+
import { active_effect, untrack } from '../../runtime.js';
55
import { loop } from '../../loop.js';
66
import { should_intro } from '../../render.js';
77
import { current_each_item } from '../blocks/each.js';
@@ -243,7 +243,7 @@ export function transition(flags, element, get_fn, get_params) {
243243
}
244244
};
245245

246-
var e = /** @type {Effect} */ (current_effect);
246+
var e = /** @type {Effect} */ (active_effect);
247247

248248
(e.transitions ??= []).push(transition);
249249

packages/svelte/src/internal/client/dom/legacy/lifecycle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/** @import { ComponentContextLegacy } from '#client' */
22
import { run, run_all } from '../../../shared/utils.js';
33
import { user_pre_effect, user_effect } from '../../reactivity/effects.js';
4-
import { current_component_context, deep_read_state, get, untrack } from '../../runtime.js';
4+
import { component_context, deep_read_state, get, untrack } from '../../runtime.js';
55

66
/**
77
* Legacy-mode only: Call `onMount` callbacks and set up `beforeUpdate`/`afterUpdate` effects
88
*/
99
export function init() {
10-
const context = /** @type {ComponentContextLegacy} */ (current_component_context);
10+
const context = /** @type {ComponentContextLegacy} */ (component_context);
1111

1212
const callbacks = context.l.u;
1313
if (!callbacks) return;

packages/svelte/src/internal/client/dom/template.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { hydrate_next, hydrate_node, hydrating, set_hydrate_node } from './hydration.js';
33
import { create_text, get_first_child } from './operations.js';
44
import { create_fragment_from_html } from './reconciler.js';
5-
import { current_effect } from '../runtime.js';
5+
import { active_effect } from '../runtime.js';
66
import { TEMPLATE_FRAGMENT, TEMPLATE_USE_IMPORT_NODE } from '../../../constants.js';
77
import { queue_micro_task } from './task.js';
88

@@ -11,7 +11,7 @@ import { queue_micro_task } from './task.js';
1111
* @param {TemplateNode | null} end
1212
*/
1313
export function assign_nodes(start, end) {
14-
var effect = /** @type {Effect} */ (current_effect);
14+
var effect = /** @type {Effect} */ (active_effect);
1515
if (effect.nodes_start === null) {
1616
effect.nodes_start = start;
1717
effect.nodes_end = end;
@@ -192,7 +192,7 @@ function run_scripts(node) {
192192
/** @type {HTMLElement} */ (node).tagName === 'SCRIPT'
193193
? [/** @type {HTMLScriptElement} */ (node)]
194194
: node.querySelectorAll('script');
195-
const effect = /** @type {Effect} */ (current_effect);
195+
const effect = /** @type {Effect} */ (active_effect);
196196

197197
for (const script of scripts) {
198198
const clone = document.createElement('script');
@@ -274,7 +274,7 @@ export function comment() {
274274
*/
275275
export function append(anchor, dom) {
276276
if (hydrating) {
277-
/** @type {Effect} */ (current_effect).nodes_end = hydrate_node;
277+
/** @type {Effect} */ (active_effect).nodes_end = hydrate_node;
278278
hydrate_next();
279279
return;
280280
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @import { ProxyMetadata, ProxyStateObject, Source } from '#client' */
22
import { DEV } from 'esm-env';
3-
import { get, current_component_context, untrack, current_effect } from './runtime.js';
3+
import { get, component_context, active_effect } from './runtime.js';
44
import {
55
array_prototype,
66
get_descriptor,
@@ -62,8 +62,8 @@ export function proxy(value, parent = null, prev) {
6262
} else {
6363
metadata.owners =
6464
parent === null
65-
? current_component_context !== null
66-
? new Set([current_component_context.function])
65+
? component_context !== null
66+
? new Set([component_context.function])
6767
: null
6868
: new Set();
6969
}
@@ -190,7 +190,7 @@ export function proxy(value, parent = null, prev) {
190190

191191
if (
192192
s !== undefined ||
193-
(current_effect !== null && (!has || get_descriptor(target, prop)?.writable))
193+
(active_effect !== null && (!has || get_descriptor(target, prop)?.writable))
194194
) {
195195
if (s === undefined) {
196196
s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED);

packages/svelte/src/internal/client/reactivity/deriveds.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { DEV } from 'esm-env';
33
import { CLEAN, DERIVED, DESTROYED, DIRTY, MAYBE_DIRTY, UNOWNED } from '../constants.js';
44
import {
5-
current_reaction,
6-
current_effect,
5+
active_reaction,
6+
active_effect,
77
remove_reactions,
88
set_signal_status,
9-
current_skip_reaction,
9+
skip_reaction,
1010
update_reaction,
1111
increment_version
1212
} from '../runtime.js';
@@ -23,7 +23,7 @@ import { inspect_effects, set_inspect_effects } from './sources.js';
2323
/*#__NO_SIDE_EFFECTS__*/
2424
export function derived(fn) {
2525
let flags = DERIVED | DIRTY;
26-
if (current_effect === null) flags |= UNOWNED;
26+
if (active_effect === null) flags |= UNOWNED;
2727

2828
/** @type {Derived<V>} */
2929
const signal = {
@@ -37,8 +37,8 @@ export function derived(fn) {
3737
version: 0
3838
};
3939

40-
if (current_reaction !== null && (current_reaction.f & DERIVED) !== 0) {
41-
var derived = /** @type {Derived} */ (current_reaction);
40+
if (active_reaction !== null && (active_reaction.f & DERIVED) !== 0) {
41+
var derived = /** @type {Derived} */ (active_reaction);
4242
(derived.children ??= []).push(signal);
4343
}
4444

@@ -114,9 +114,7 @@ export function update_derived(derived) {
114114
}
115115

116116
var status =
117-
(current_skip_reaction || (derived.f & UNOWNED) !== 0) && derived.deps !== null
118-
? MAYBE_DIRTY
119-
: CLEAN;
117+
(skip_reaction || (derived.f & UNOWNED) !== 0) && derived.deps !== null ? MAYBE_DIRTY : CLEAN;
120118

121119
set_signal_status(derived, status);
122120

0 commit comments

Comments
 (0)