1
1
import { is_promise , noop } from '../shared/utils.js' ;
2
2
import { subscribe_to_store } from '../../store/utils.js' ;
3
- import {
4
- UNINITIALIZED ,
5
- DOMBooleanAttributes ,
6
- RawTextElements ,
7
- disallowed_paragraph_contents ,
8
- interactive_elements ,
9
- is_tag_valid_with_parent
10
- } from '../../constants.js' ;
3
+ import { UNINITIALIZED , DOMBooleanAttributes , RawTextElements } from '../../constants.js' ;
11
4
import { escape_html } from '../../escaping.js' ;
12
5
import { DEV } from 'esm-env' ;
13
6
import { current_component , pop , push } from './context.js' ;
14
7
import { BLOCK_CLOSE , BLOCK_OPEN } from './hydration.js' ;
15
8
import { validate_store } from '../shared/validate.js' ;
16
9
17
- /**
18
- * @typedef {{
19
- * tag: string;
20
- * parent: null | Element;
21
- * file: string;
22
- * }} Element
23
- */
24
-
25
10
/**
26
11
* @typedef {{
27
12
* head: string;
28
13
* html: string;
29
14
* }} RenderOutput
30
15
*/
31
16
32
- /**
33
- * @typedef {{
34
- * out: string;
35
- * anchor: number;
36
- * head: {
37
- * title: string;
38
- * out: string;
39
- * anchor: number;
40
- * };
41
- * }} Payload
42
- */
43
-
44
17
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
45
18
// https://infra.spec.whatwg.org/#noncharacter
46
19
const INVALID_ATTR_NAME_CHAR_REGEX =
@@ -65,19 +38,14 @@ export const VoidElements = new Set([
65
38
'wbr'
66
39
] ) ;
67
40
68
- /**
69
- * @type {Element | null }
70
- */
71
- let current_element = null ;
72
-
73
- /** @returns {Payload } */
41
+ /** @returns {import('#server').Payload } */
74
42
function create_payload ( ) {
75
43
return { out : '' , head : { title : '' , out : '' , anchor : 0 } , anchor : 0 } ;
76
44
}
77
45
78
46
/**
79
- * @param {Payload } to_copy
80
- * @returns {Payload }
47
+ * @param {import('#server'). Payload } to_copy
48
+ * @returns {import('#server'). Payload }
81
49
*/
82
50
export function copy_payload ( to_copy ) {
83
51
return {
@@ -88,8 +56,8 @@ export function copy_payload(to_copy) {
88
56
89
57
/**
90
58
* Assigns second payload to first
91
- * @param {Payload } p1
92
- * @param {Payload } p2
59
+ * @param {import('#server'). Payload } p1
60
+ * @param {import('#server'). Payload } p2
93
61
* @returns {void }
94
62
*/
95
63
export function assign_payload ( p1 , p2 ) {
@@ -99,85 +67,7 @@ export function assign_payload(p1, p2) {
99
67
}
100
68
101
69
/**
102
- * @param {Payload } payload
103
- * @param {string } message
104
- */
105
- function error_on_client ( payload , message ) {
106
- message =
107
- `Svelte SSR validation error:\n\n${ message } \n\n` +
108
- 'Ensure your components render valid HTML as the browser will try to repair invalid HTML, ' +
109
- 'which may result in content being shifted around and will likely result in a hydration mismatch.' ;
110
- // eslint-disable-next-line no-console
111
- console . error ( message ) ;
112
- payload . head . out += `<script>console.error(\`${ message } \`)</script>` ;
113
- }
114
-
115
- /**
116
- * @param {string } file
117
- */
118
- function print_file ( file ) {
119
- return file ? `(${ file } )` : '' ;
120
- }
121
-
122
- /**
123
- * @param {string } tag
124
- * @param {Payload } payload
125
- */
126
- export function push_element ( tag , payload ) {
127
- var file ;
128
- if ( DEV ) {
129
- if ( current_component !== null ) {
130
- const filename = current_component . function . filename ;
131
- if ( filename ) {
132
- file = filename . split ( '/' ) . at ( - 1 ) ;
133
- }
134
- }
135
- if ( current_element !== null && ! is_tag_valid_with_parent ( tag , current_element . tag ) ) {
136
- error_on_client (
137
- payload ,
138
- `<${ tag } > ${ print_file ( file ) } is not a valid child element of <${ current_element . tag } > ${ print_file ( current_element . file ) } `
139
- ) ;
140
- }
141
- if ( interactive_elements . has ( tag ) ) {
142
- let element = current_element ;
143
- while ( element !== null ) {
144
- if ( interactive_elements . has ( element . tag ) ) {
145
- error_on_client (
146
- payload ,
147
- `<${ tag } > ${ print_file ( file ) } is not a valid child element of <${ element . tag } > ${ print_file ( element . file ) } `
148
- ) ;
149
- }
150
- element = element . parent ;
151
- }
152
- }
153
- if ( disallowed_paragraph_contents . includes ( tag ) ) {
154
- let element = current_element ;
155
- while ( element !== null ) {
156
- if ( element . tag === 'p' ) {
157
- error_on_client (
158
- payload ,
159
- `<${ tag } > ${ print_file ( file ) } is not a valid child element of <p> ${ print_file ( element . file ) } `
160
- ) ;
161
- }
162
- element = element . parent ;
163
- }
164
- }
165
- }
166
- current_element = {
167
- tag,
168
- parent : current_element ,
169
- file
170
- } ;
171
- }
172
-
173
- export function pop_element ( ) {
174
- if ( current_element !== null ) {
175
- current_element = current_element . parent ;
176
- }
177
- }
178
-
179
- /**
180
- * @param {Payload } payload
70
+ * @param {import('#server').Payload } payload
181
71
* @param {string } tag
182
72
* @param {() => void } attributes_fn
183
73
* @param {() => void } children_fn
@@ -241,8 +131,8 @@ export function render(component, options) {
241
131
}
242
132
243
133
/**
244
- * @param {Payload } payload
245
- * @param {(head_payload: Payload['head']) => void } fn
134
+ * @param {import('#server'). Payload } payload
135
+ * @param {(head_payload: import('#server'). Payload['head']) => void } fn
246
136
* @returns {void }
247
137
*/
248
138
export function head ( payload , fn ) {
@@ -266,7 +156,7 @@ export function attr(name, value, boolean) {
266
156
}
267
157
268
158
/**
269
- * @param {Payload } payload
159
+ * @param {import('#server'). Payload } payload
270
160
* @param {boolean } is_html
271
161
* @param {Record<string, string> } props
272
162
* @param {() => void } component
@@ -524,8 +414,8 @@ export async function value_or_fallback_async(value, fallback) {
524
414
}
525
415
526
416
/**
527
- * @param {Payload } payload
528
- * @param {void | ((payload: Payload, props: Record<string, unknown>) => void) } slot_fn
417
+ * @param {import('#server'). Payload } payload
418
+ * @param {void | ((payload: import('#server'). Payload, props: Record<string, unknown>) => void) } slot_fn
529
419
* @param {Record<string, unknown> } slot_props
530
420
* @param {null | (() => void) } fallback_fn
531
421
* @returns {void }
@@ -648,6 +538,8 @@ export function once(get_value) {
648
538
649
539
export { push , pop } from './context.js' ;
650
540
541
+ export { push_element , pop_element } from './dev.js' ;
542
+
651
543
export {
652
544
add_snippet_symbol ,
653
545
validate_component ,
0 commit comments