mirror of https://github.com/sveltejs/svelte
chore: remove metadata.pending (#16764)
parent
2365d1b90c
commit
33453869e7
@ -1,36 +1,36 @@
|
||||
/** @import { BlockStatement } from 'estree' */
|
||||
/** @import { AST } from '#compiler' */
|
||||
/** @import { ComponentContext } from '../types' */
|
||||
import {
|
||||
BLOCK_CLOSE,
|
||||
BLOCK_OPEN,
|
||||
BLOCK_OPEN_ELSE
|
||||
} from '../../../../../internal/server/hydration.js';
|
||||
import * as b from '#compiler/builders';
|
||||
import { build_attribute_value } from './shared/utils.js';
|
||||
import { block_close, block_open, block_open_else, build_attribute_value } from './shared/utils.js';
|
||||
|
||||
/**
|
||||
* @param {AST.SvelteBoundary} node
|
||||
* @param {ComponentContext} context
|
||||
*/
|
||||
export function SvelteBoundary(node, context) {
|
||||
const pending_snippet = node.metadata.pending;
|
||||
// if this has a `pending` snippet, render it
|
||||
const pending_attribute = /** @type {AST.Attribute} */ (
|
||||
node.attributes.find((node) => node.type === 'Attribute' && node.name === 'pending')
|
||||
);
|
||||
|
||||
if (pending_snippet) {
|
||||
context.state.template.push(b.literal(BLOCK_OPEN_ELSE));
|
||||
const pending_snippet = /** @type {AST.SnippetBlock} */ (
|
||||
node.fragment.nodes.find(
|
||||
(node) => node.type === 'SnippetBlock' && node.expression.name === 'pending'
|
||||
)
|
||||
);
|
||||
|
||||
if (pending_snippet.type === 'Attribute') {
|
||||
const value = build_attribute_value(pending_snippet.value, context, false, true);
|
||||
context.state.template.push(b.call(value, b.id('$$payload')));
|
||||
} else if (pending_snippet.type === 'SnippetBlock') {
|
||||
context.state.template.push(
|
||||
/** @type {BlockStatement} */ (context.visit(pending_snippet.body))
|
||||
);
|
||||
}
|
||||
if (pending_attribute || pending_snippet) {
|
||||
const pending = pending_attribute
|
||||
? b.call(
|
||||
build_attribute_value(pending_attribute.value, context, false, true),
|
||||
b.id('$$payload')
|
||||
)
|
||||
: /** @type {BlockStatement} */ (context.visit(pending_snippet.body));
|
||||
|
||||
context.state.template.push(block_open_else, pending, block_close);
|
||||
} else {
|
||||
context.state.template.push(b.literal(BLOCK_OPEN));
|
||||
context.state.template.push(/** @type {BlockStatement} */ (context.visit(node.fragment)));
|
||||
const block = /** @type {BlockStatement} */ (context.visit(node.fragment));
|
||||
context.state.template.push(block_open, block, block_close);
|
||||
}
|
||||
|
||||
context.state.template.push(b.literal(BLOCK_CLOSE));
|
||||
}
|
||||
|
Loading…
Reference in new issue