Skip to content

Commit 98508df

Browse files
committed
only export things that should be available on $
1 parent eaca526 commit 98508df

File tree

4 files changed

+71
-69
lines changed

4 files changed

+71
-69
lines changed

packages/svelte/src/internal/server/dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../../html-tree-validation.js';
77
import { current_component } from './context.js';
88
import { invalid_snippet_arguments } from '../shared/errors.js';
9-
import { Payload } from './index.js';
9+
import { Payload } from './payload.js';
1010

1111
/**
1212
* @typedef {{

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

+4-66
Original file line numberDiff line numberDiff line change
@@ -17,67 +17,13 @@ import { EMPTY_COMMENT, BLOCK_CLOSE, BLOCK_OPEN } from './hydration.js';
1717
import { validate_store } from '../shared/validate.js';
1818
import { is_boolean_attribute, is_raw_text_element, is_void } from '../../utils.js';
1919
import { reset_elements } from './dev.js';
20+
import { Payload } from './payload.js';
2021

2122
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
2223
// https://infra.spec.whatwg.org/#noncharacter
2324
const INVALID_ATTR_NAME_CHAR_REGEX =
2425
/[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u;
2526

26-
class Payload {
27-
/** @type {Set<{ hash: string; code: string }>} */
28-
css = new Set();
29-
out = '';
30-
uid = () => '';
31-
32-
head = {
33-
/** @type {Set<{ hash: string; code: string }>} */
34-
css: new Set(),
35-
title: '',
36-
out: '',
37-
uid: () => ''
38-
};
39-
40-
constructor(id_prefix = '') {
41-
this.uid = props_id_generator(id_prefix);
42-
this.head.uid = this.uid;
43-
}
44-
}
45-
46-
/**
47-
* Used in legacy mode to handle bindings
48-
* @param {Payload} to_copy
49-
* @returns {Payload}
50-
*/
51-
export function copy_payload({ out, css, head, uid }) {
52-
const payload = new Payload();
53-
54-
payload.out = out;
55-
payload.css = new Set(css);
56-
payload.uid = uid;
57-
58-
payload.head = {
59-
title: head.title,
60-
out: head.out,
61-
css: new Set(head.css),
62-
uid: head.uid
63-
};
64-
65-
return payload;
66-
}
67-
68-
/**
69-
* Assigns second payload to first
70-
* @param {Payload} p1
71-
* @param {Payload} p2
72-
* @returns {void}
73-
*/
74-
export function assign_payload(p1, p2) {
75-
p1.out = p2.out;
76-
p1.css = p2.css;
77-
p1.head = p2.head;
78-
p1.uid = p2.uid;
79-
}
80-
8127
/**
8228
* @param {Payload} payload
8329
* @param {string} tag
@@ -111,16 +57,6 @@ export function element(payload, tag, attributes_fn = noop, children_fn = noop)
11157
*/
11258
export let on_destroy = [];
11359

114-
/**
115-
* Creates an ID generator
116-
* @param {string} prefix
117-
* @returns {() => string}
118-
*/
119-
function props_id_generator(prefix) {
120-
let uid = 1;
121-
return () => `${prefix}s${uid++}`;
122-
}
123-
12460
/**
12561
* Only available on the server and when compiling with the `server` option.
12662
* Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
@@ -553,14 +489,16 @@ export function props_id(payload) {
553489
return uid;
554490
}
555491

556-
export { attr, clsx, Payload };
492+
export { attr, clsx };
557493

558494
export { html } from './blocks/html.js';
559495

560496
export { push, pop } from './context.js';
561497

562498
export { push_element, pop_element, validate_snippet_args } from './dev.js';
563499

500+
export { assign_payload, copy_payload } from './payload.js';
501+
564502
export { snapshot } from '../shared/clone.js';
565503

566504
export { fallback } from '../shared/utils.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
export class Payload {
2+
/** @type {Set<{ hash: string; code: string }>} */
3+
css = new Set();
4+
out = '';
5+
uid = () => '';
6+
7+
head = {
8+
/** @type {Set<{ hash: string; code: string }>} */
9+
css: new Set(),
10+
title: '',
11+
out: '',
12+
uid: () => ''
13+
};
14+
15+
constructor(id_prefix = '') {
16+
this.uid = props_id_generator(id_prefix);
17+
this.head.uid = this.uid;
18+
}
19+
}
20+
21+
/**
22+
* Used in legacy mode to handle bindings
23+
* @param {Payload} to_copy
24+
* @returns {Payload}
25+
*/
26+
export function copy_payload({ out, css, head, uid }) {
27+
const payload = new Payload();
28+
29+
payload.out = out;
30+
payload.css = new Set(css);
31+
payload.uid = uid;
32+
33+
payload.head = {
34+
title: head.title,
35+
out: head.out,
36+
css: new Set(head.css),
37+
uid: head.uid
38+
};
39+
40+
return payload;
41+
}
42+
43+
/**
44+
* Assigns second payload to first
45+
* @param {Payload} p1
46+
* @param {Payload} p2
47+
* @returns {void}
48+
*/
49+
export function assign_payload(p1, p2) {
50+
p1.out = p2.out;
51+
p1.css = p2.css;
52+
p1.head = p2.head;
53+
p1.uid = p2.uid;
54+
}
55+
56+
/**
57+
* Creates an ID generator
58+
* @param {string} prefix
59+
* @returns {() => string}
60+
*/
61+
function props_id_generator(prefix) {
62+
let uid = 1;
63+
return () => `${prefix}s${uid++}`;
64+
}

packages/svelte/src/internal/shared/errors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export function invalid_default_snippet() {
1818
}
1919

2020
/**
21-
* A snippet function was passed invalid arguments. A snippet function should only be called via `{@render ...}`
21+
* A snippet function was passed invalid arguments. Snippets should only be instantiated via `{@render ...}`
2222
* @returns {never}
2323
*/
2424
export function invalid_snippet_arguments() {
2525
if (DEV) {
26-
const error = new Error(`invalid_snippet_arguments\nA snippet function was passed invalid arguments. A snippet function should only be called via \`{@render ...}\`\nhttps://svelte.dev/e/invalid_snippet_arguments`);
26+
const error = new Error(`invalid_snippet_arguments\nA snippet function was passed invalid arguments. Snippets should only be instantiated via \`{@render ...}\`\nhttps://svelte.dev/e/invalid_snippet_arguments`);
2727

2828
error.name = 'Svelte error';
2929
throw error;

0 commit comments

Comments
 (0)