Skip to content

Commit 178a5a6

Browse files
committed
avoid magic strings
1 parent abff84e commit 178a5a6

File tree

8 files changed

+23
-27
lines changed

8 files changed

+23
-27
lines changed

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import { create_attribute, is_custom_element_node, is_element_node } from '../..
2424
import { error } from '../../../errors.js';
2525
import { binding_properties } from '../../bindings.js';
2626
import { regex_starts_with_newline, regex_whitespaces_strict } from '../../patterns.js';
27-
import { DOMBooleanAttributes } from '../../../../constants.js';
27+
import { DOMBooleanAttributes, HYDRATION_END, HYDRATION_START } from '../../../../constants.js';
2828
import { sanitize_template_string } from '../../../utils/sanitize_template_string.js';
2929

30-
const block_open = t_string('<!--[-->');
31-
const block_close = t_string('<!--]-->');
30+
export const block_open = t_string(`<!--${HYDRATION_START}-->`);
31+
export const block_close = t_string(`<!--${HYDRATION_END}-->`);
3232

3333
/**
3434
* @param {string} value

packages/svelte/src/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ 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 HYDRATION_START = '[';
23+
export const HYDRATION_END = ']';
24+
2225
export const UNINITIALIZED = Symbol();
2326

2427
/** List of Element events that will be delegated */

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ import {
44
EACH_IS_CONTROLLED,
55
EACH_IS_STRICT_EQUALS,
66
EACH_ITEM_REACTIVE,
7-
EACH_KEYED
7+
EACH_KEYED,
8+
HYDRATION_START
89
} from '../../../../constants.js';
9-
import {
10-
HYDRATION_START,
11-
hydrate_anchor,
12-
hydrate_nodes,
13-
hydrating,
14-
set_hydrating
15-
} from '../hydration.js';
10+
import { hydrate_anchor, hydrate_nodes, hydrating, set_hydrating } from '../hydration.js';
1611
import { empty } from '../operations.js';
1712
import { remove } from '../reconciler.js';
1813
import { untrack } from '../../runtime.js';

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import {
2-
HYDRATION_START,
3-
hydrate_anchor,
4-
hydrate_nodes,
5-
hydrating,
6-
set_hydrate_nodes
7-
} from '../hydration.js';
1+
import { hydrate_anchor, hydrate_nodes, hydrating, set_hydrate_nodes } from '../hydration.js';
82
import { empty } from '../operations.js';
93
import { block } from '../../reactivity/effects.js';
4+
import { HYDRATION_START } from '../../../../constants.js';
105

116
/**
127
* @param {(anchor: Node) => import('#client').Dom | void} render_fn

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export const HYDRATION_START = '[';
2-
export const HYDRATION_END = ']';
1+
import { HYDRATION_END, HYDRATION_START } from '../../../constants.js';
32

43
/**
54
* Use this variable to guard everything related to hydration code so it can be treeshaken out

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import {
66
empty,
77
init_operations
88
} from './dom/operations.js';
9-
import { PassiveDelegatedEvents } from '../../constants.js';
9+
import { HYDRATION_START, PassiveDelegatedEvents } from '../../constants.js';
1010
import { flush_sync, push, pop, current_component_context, untrack } from './runtime.js';
1111
import { effect_root, branch } from './reactivity/effects.js';
1212
import {
13-
HYDRATION_START,
1413
hydrate_anchor,
1514
hydrate_nodes,
1615
hydrating,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { HYDRATION_END, HYDRATION_START } from '../../constants.js';
2+
3+
export const BLOCK_OPEN = `<!--${HYDRATION_START}-->`;
4+
export const BLOCK_CLOSE = `<!--${HYDRATION_END}-->`;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '../../constants.js';
1010
import { DEV } from 'esm-env';
1111
import { current_component, pop, push } from './context.js';
12+
import { BLOCK_CLOSE, BLOCK_OPEN } from './hydration.js';
1213

1314
/**
1415
* @typedef {{
@@ -161,11 +162,11 @@ export function element(payload, tag, attributes_fn, children_fn) {
161162

162163
if (!VoidElements.has(tag)) {
163164
if (tag !== 'textarea') {
164-
payload.out += '<!--[-->';
165+
payload.out += BLOCK_OPEN;
165166
}
166167
children_fn();
167168
if (tag !== 'textarea') {
168-
payload.out += '<!--]-->';
169+
payload.out += BLOCK_CLOSE;
169170
}
170171
payload.out += `</${tag}>`;
171172
}
@@ -187,7 +188,7 @@ export function render(component, options) {
187188

188189
const prev_on_destroy = on_destroy;
189190
on_destroy = [];
190-
payload.out += '<!--[-->';
191+
payload.out += BLOCK_OPEN;
191192

192193
if (options.context) {
193194
push();
@@ -200,14 +201,14 @@ export function render(component, options) {
200201
pop();
201202
}
202203

203-
payload.out += '<!--]-->';
204+
payload.out += BLOCK_CLOSE;
204205
for (const cleanup of on_destroy) cleanup();
205206
on_destroy = prev_on_destroy;
206207

207208
return {
208209
head:
209210
payload.head.out || payload.head.title
210-
? payload.head.title + '<!--[-->' + payload.head.out + '<!--]-->'
211+
? payload.head.title + BLOCK_OPEN + payload.head.out + BLOCK_CLOSE
211212
: '',
212213
html: payload.out
213214
};

0 commit comments

Comments
 (0)