Skip to content

Commit 9700ee5

Browse files
committed
tidy up
1 parent 732b145 commit 9700ee5

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ 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, HYDRATION_END, HYDRATION_START } from '../../../../constants.js';
27+
import {
28+
DOMBooleanAttributes,
29+
HYDRATION_END,
30+
HYDRATION_END_ELSE,
31+
HYDRATION_START
32+
} from '../../../../constants.js';
2833
import { sanitize_template_string } from '../../../utils/sanitize_template_string.js';
29-
import { BLOCK_CLOSE } from '../../../../internal/server/hydration.js';
34+
import { BLOCK_CLOSE, BLOCK_CLOSE_ELSE } from '../../../../internal/server/hydration.js';
3035

3136
export const block_open = t_string(`<!--${HYDRATION_START}-->`);
3237
export const block_close = t_string(`<!--${HYDRATION_END}-->`);
@@ -1506,9 +1511,7 @@ const template_visitors = {
15061511
if (node.fallback) {
15071512
const fallback = create_block(node, node.fallback.nodes, context);
15081513

1509-
fallback.push(
1510-
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(`<!--${HYDRATION_END}!-->`)))
1511-
);
1514+
fallback.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_CLOSE_ELSE))));
15121515

15131516
state.template.push(
15141517
t_statement(
@@ -1531,9 +1534,7 @@ const template_visitors = {
15311534
const alternate = node.alternate ? create_block(node, node.alternate.nodes, context) : [];
15321535

15331536
consequent.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_CLOSE))));
1534-
alternate.push(
1535-
b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(`<!--${HYDRATION_END}!-->`)))
1536-
);
1537+
alternate.push(b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_CLOSE_ELSE))));
15371538

15381539
state.template.push(
15391540
t_statement(

packages/svelte/src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const TEMPLATE_USE_IMPORT_NODE = 1 << 1;
2121

2222
export const HYDRATION_START = '[';
2323
export const HYDRATION_END = ']';
24+
export const HYDRATION_END_ELSE = `${HYDRATION_END}!`; // used to indicate that an `{:else}...` block was rendered
2425

2526
export const UNINITIALIZED = Symbol();
2627

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
EACH_IS_STRICT_EQUALS,
66
EACH_ITEM_REACTIVE,
77
EACH_KEYED,
8-
HYDRATION_END,
8+
HYDRATION_END_ELSE,
99
HYDRATION_START
1010
} from '../../../../constants.js';
1111
import { hydrate_anchor, hydrate_nodes, hydrating, set_hydrating } from '../hydration.js';
@@ -98,7 +98,7 @@ function each(anchor, flags, get_collection, get_key, render_fn, fallback_fn, re
9898
let mismatch = false;
9999

100100
if (hydrating) {
101-
var is_else = /** @type {Comment} */ (anchor).data === `${HYDRATION_END}!`;
101+
var is_else = /** @type {Comment} */ (anchor).data === HYDRATION_END_ELSE;
102102

103103
if (is_else !== (length === 0)) {
104104
// hydration mismatch — remove the server-rendered DOM and start over

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IS_ELSEIF } from '../../constants.js';
22
import { hydrate_nodes, hydrating, set_hydrating } from '../hydration.js';
33
import { remove } from '../reconciler.js';
44
import { block, branch, pause_effect, resume_effect } from '../../reactivity/effects.js';
5-
import { HYDRATION_END } from '../../../../constants.js';
5+
import { HYDRATION_END_ELSE } from '../../../../constants.js';
66

77
/**
88
* @param {Comment} anchor
@@ -35,7 +35,7 @@ export function if_block(
3535
let mismatch = false;
3636

3737
if (hydrating) {
38-
const is_else = anchor.data === `${HYDRATION_END}!`;
38+
const is_else = anchor.data === HYDRATION_END_ELSE;
3939

4040
if (condition === is_else) {
4141
// Hydration mismatch: remove everything inside the anchor and start fresh.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { HYDRATION_END, HYDRATION_START } from '../../constants.js';
1+
import { HYDRATION_END, HYDRATION_END_ELSE, HYDRATION_START } from '../../constants.js';
22

33
export const BLOCK_OPEN = `<!--${HYDRATION_START}-->`;
44
export const BLOCK_CLOSE = `<!--${HYDRATION_END}-->`;
5+
export const BLOCK_CLOSE_ELSE = `<!--${HYDRATION_END_ELSE}-->`;

0 commit comments

Comments
 (0)