Skip to content

Commit f303d82

Browse files
authored
chore: tidy up server exports (#10972)
* tidy up server exports * tidy up server exports * docs are unnecessary here * eliminate client dependencies from server code * lint
1 parent d49e2ae commit f303d82

File tree

27 files changed

+251
-157
lines changed

27 files changed

+251
-157
lines changed

packages/svelte/src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export const TRANSITION_GLOBAL = 1 << 2;
1919
export const TEMPLATE_FRAGMENT = 1;
2020
export const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
2121

22+
export const UNINITIALIZED = Symbol();
23+
2224
/** List of Element events that will be delegated */
2325
export const DelegatedEvents = [
2426
'beforeinput',

packages/svelte/src/index-server.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
import { current_component_context } from './internal/client/runtime.js';
2-
3-
export {
4-
createEventDispatcher,
5-
flushSync,
6-
getAllContexts,
7-
getContext,
8-
hasContext,
9-
mount,
10-
hydrate,
11-
setContext,
12-
tick,
13-
unmount,
14-
untrack
15-
} from './index-client.js';
16-
17-
/** @returns {void} */
18-
export function onMount() {}
1+
import { current_component } from './internal/server/context.js';
2+
import { noop } from './internal/shared/utils.js';
193

204
/** @param {() => void} fn */
215
export function onDestroy(fn) {
22-
const context = /** @type {import('#client').ComponentContext} */ (current_component_context);
23-
(context.ondestroy ??= []).push(fn);
6+
var context = /** @type {import('#server').Component} */ (current_component);
7+
(context.d ??= []).push(fn);
8+
}
9+
10+
export {
11+
noop as beforeUpdate,
12+
noop as afterUpdate,
13+
noop as onMount,
14+
noop as flushSync,
15+
run as untrack
16+
} from './internal/shared/utils.js';
17+
18+
export function createEventDispatcher() {
19+
return noop;
2420
}
2521

26-
/** @returns {void} */
27-
export function beforeUpdate() {}
22+
export function mount() {
23+
throw new Error('mount(...) is not available on the server');
24+
}
25+
26+
export function hydrate() {
27+
throw new Error('hydrate(...) is not available on the server');
28+
}
2829

29-
/** @returns {void} */
30-
export function afterUpdate() {}
30+
export function unmount() {
31+
throw new Error('unmount(...) is not available on the server');
32+
}
33+
34+
export async function tick() {}
3135

3236
/**
3337
* @template T
@@ -38,3 +42,5 @@ export function unstate(value) {
3842
// There's no signals/proxies on the server, so just return the value
3943
return value;
4044
}
45+
46+
export { getAllContexts, getContext, hasContext, setContext } from './internal/server/context.js';

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ export const DESTROYED = 1 << 12;
1313
export const IS_ELSEIF = 1 << 13;
1414
export const EFFECT_RAN = 1 << 14;
1515

16-
export const UNINITIALIZED = Symbol();
1716
export const STATE_SYMBOL = Symbol('$state');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { is_promise } from '../../../common.js';
1+
import { is_promise } from '../../../shared/utils.js';
22
import {
33
current_component_context,
44
flush_sync,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UNINITIALIZED } from '../../constants.js';
1+
import { UNINITIALIZED } from '../../../../constants.js';
22
import { block, branch, pause_effect } from '../../reactivity/effects.js';
33
import { safe_not_equal } from '../../reactivity/equality.js';
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { noop } from '../../../common.js';
1+
import { noop } from '../../../shared/utils.js';
22
import { effect } from '../../reactivity/effects.js';
33
import { current_effect, untrack } from '../../runtime.js';
44
import { raf } from '../../timing.js';

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { run_all } from '../../../common.js';
1+
import { run, run_all } from '../../../shared/utils.js';
22
import { user_pre_effect, user_effect } from '../../reactivity/effects.js';
33
import {
44
current_component_context,
@@ -9,11 +9,6 @@ import {
99
untrack
1010
} from '../../runtime.js';
1111

12-
/** @param {Function} fn */
13-
function run(fn) {
14-
return fn();
15-
}
16-
1712
/**
1813
* Legacy-mode only: Call `onMount` callbacks and set up `beforeUpdate`/`afterUpdate` effects
1914
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { run_all } from '../../common.js';
1+
import { run_all } from '../../shared/utils.js';
22

33
let is_task_queued = false;
44
let is_raf_queued = false;

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,10 @@ export {
120120
hasContext
121121
} from './runtime.js';
122122
export {
123-
add_snippet_symbol,
124-
validate_component,
125123
validate_dynamic_component,
126-
validate_dynamic_element_tag,
127124
validate_each_keys,
128125
validate_prop_bindings,
129-
validate_snippet,
130-
validate_store,
131-
validate_void_dynamic_element
126+
validate_store
132127
} from './validate.js';
133128
export { raf } from './timing.js';
134129
export { proxy, unstate } from './proxy.js';
@@ -140,4 +135,11 @@ export {
140135
$window as window,
141136
$document as document
142137
} from './dom/operations.js';
143-
export { noop } from '../common.js';
138+
export { noop } from '../shared/utils.js';
139+
export {
140+
add_snippet_symbol,
141+
validate_component,
142+
validate_dynamic_element_tag,
143+
validate_snippet,
144+
validate_void_dynamic_element
145+
} from '../shared/validate.js';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import {
1313
} from './utils.js';
1414
import { add_owner, check_ownership, strip_owner } from './dev/ownership.js';
1515
import { mutable_source, source, set } from './reactivity/sources.js';
16-
import { STATE_SYMBOL, UNINITIALIZED } from './constants.js';
16+
import { STATE_SYMBOL } from './constants.js';
1717
import { updating_derived } from './reactivity/deriveds.js';
18+
import { UNINITIALIZED } from '../../constants.js';
1819

1920
/**
2021
* @template T

0 commit comments

Comments
 (0)