Skip to content

Commit 3345386

Browse files
authored
chore: remove metadata.pending (#16764)
1 parent 2365d1b commit 3345386

File tree

6 files changed

+29
-42
lines changed

6 files changed

+29
-42
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/SvelteBoundary.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ export function SvelteBoundary(node, context) {
1414
e.svelte_boundary_invalid_attribute(attribute);
1515
}
1616

17-
if (attribute.name === 'pending') {
18-
node.metadata.pending = attribute;
19-
}
20-
2117
if (
2218
attribute.value === true ||
2319
(Array.isArray(attribute.value) &&
@@ -27,12 +23,5 @@ export function SvelteBoundary(node, context) {
2723
}
2824
}
2925

30-
node.metadata.pending ??=
31-
/** @type {AST.SnippetBlock | undefined} */ (
32-
node.fragment.nodes.find(
33-
(node) => node.type === 'SnippetBlock' && node.expression.name === 'pending'
34-
)
35-
) ?? null;
36-
3726
context.next();
3827
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/** @import { BlockStatement, Expression, Statement } from 'estree' */
22
/** @import { AST } from '#compiler' */
33
/** @import { ComponentContext } from '../types.js' */
4-
import { BLOCK_OPEN_ELSE } from '../../../../../internal/server/hydration.js';
54
import * as b from '#compiler/builders';
6-
import { block_close, block_open } from './shared/utils.js';
5+
import { block_close, block_open, block_open_else } from './shared/utils.js';
76

87
/**
98
* @param {AST.EachBlock} node
@@ -49,7 +48,7 @@ export function EachBlock(node, context) {
4948
const fallback = /** @type {BlockStatement} */ (context.visit(node.fallback));
5049

5150
fallback.body.unshift(
52-
b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), b.literal(BLOCK_OPEN_ELSE)))
51+
b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open_else))
5352
);
5453

5554
state.template.push(

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/** @import { BlockStatement, Expression } from 'estree' */
22
/** @import { AST } from '#compiler' */
33
/** @import { ComponentContext } from '../types.js' */
4-
import { BLOCK_OPEN_ELSE } from '../../../../../internal/server/hydration.js';
54
import * as b from '#compiler/builders';
6-
import { block_close, block_open } from './shared/utils.js';
5+
import { block_close, block_open, block_open_else } from './shared/utils.js';
76

87
/**
98
* @param {AST.IfBlock} node
@@ -20,7 +19,7 @@ export function IfBlock(node, context) {
2019
consequent.body.unshift(b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open)));
2120

2221
alternate.body.unshift(
23-
b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), b.literal(BLOCK_OPEN_ELSE)))
22+
b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open_else))
2423
);
2524

2625
context.state.template.push(b.if(test, consequent, alternate), block_close);
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
/** @import { BlockStatement } from 'estree' */
22
/** @import { AST } from '#compiler' */
33
/** @import { ComponentContext } from '../types' */
4-
import {
5-
BLOCK_CLOSE,
6-
BLOCK_OPEN,
7-
BLOCK_OPEN_ELSE
8-
} from '../../../../../internal/server/hydration.js';
94
import * as b from '#compiler/builders';
10-
import { build_attribute_value } from './shared/utils.js';
5+
import { block_close, block_open, block_open_else, build_attribute_value } from './shared/utils.js';
116

127
/**
138
* @param {AST.SvelteBoundary} node
149
* @param {ComponentContext} context
1510
*/
1611
export function SvelteBoundary(node, context) {
17-
const pending_snippet = node.metadata.pending;
12+
// if this has a `pending` snippet, render it
13+
const pending_attribute = /** @type {AST.Attribute} */ (
14+
node.attributes.find((node) => node.type === 'Attribute' && node.name === 'pending')
15+
);
1816

19-
if (pending_snippet) {
20-
context.state.template.push(b.literal(BLOCK_OPEN_ELSE));
17+
const pending_snippet = /** @type {AST.SnippetBlock} */ (
18+
node.fragment.nodes.find(
19+
(node) => node.type === 'SnippetBlock' && node.expression.name === 'pending'
20+
)
21+
);
2122

22-
if (pending_snippet.type === 'Attribute') {
23-
const value = build_attribute_value(pending_snippet.value, context, false, true);
24-
context.state.template.push(b.call(value, b.id('$$payload')));
25-
} else if (pending_snippet.type === 'SnippetBlock') {
26-
context.state.template.push(
27-
/** @type {BlockStatement} */ (context.visit(pending_snippet.body))
28-
);
29-
}
23+
if (pending_attribute || pending_snippet) {
24+
const pending = pending_attribute
25+
? b.call(
26+
build_attribute_value(pending_attribute.value, context, false, true),
27+
b.id('$$payload')
28+
)
29+
: /** @type {BlockStatement} */ (context.visit(pending_snippet.body));
30+
31+
context.state.template.push(block_open_else, pending, block_close);
3032
} else {
31-
context.state.template.push(b.literal(BLOCK_OPEN));
32-
context.state.template.push(/** @type {BlockStatement} */ (context.visit(node.fragment)));
33+
const block = /** @type {BlockStatement} */ (context.visit(node.fragment));
34+
context.state.template.push(block_open, block, block_close);
3335
}
34-
35-
context.state.template.push(b.literal(BLOCK_CLOSE));
3636
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { escape_html } from '../../../../../../escaping.js';
66
import {
77
BLOCK_CLOSE,
88
BLOCK_OPEN,
9+
BLOCK_OPEN_ELSE,
910
EMPTY_COMMENT
1011
} from '../../../../../../internal/server/hydration.js';
1112
import * as b from '#compiler/builders';
@@ -16,6 +17,9 @@ import { has_await } from '../../../../../utils/ast.js';
1617
/** Opens an if/each block, so that we can remove nodes in the case of a mismatch */
1718
export const block_open = b.literal(BLOCK_OPEN);
1819

20+
/** Opens an if/each block, so that we can remove nodes in the case of a mismatch */
21+
export const block_open_else = b.literal(BLOCK_OPEN_ELSE);
22+
1923
/** Closes an if/each block, so that we can remove nodes in the case of a mismatch. Also serves as an anchor for these blocks */
2024
export const block_close = b.literal(BLOCK_CLOSE);
2125

packages/svelte/src/compiler/types/template.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,6 @@ export namespace AST {
409409
export interface SvelteBoundary extends BaseElement {
410410
type: 'SvelteBoundary';
411411
name: 'svelte:boundary';
412-
/** @internal */
413-
metadata: {
414-
pending: SnippetBlock | Attribute | null;
415-
};
416412
}
417413

418414
export interface SvelteHead extends BaseElement {

0 commit comments

Comments
 (0)