chore: remove metadata.pending (#16764)

pull/16769/head
Rich Harris 2 days ago committed by GitHub
parent 2365d1b90c
commit 33453869e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -14,10 +14,6 @@ export function SvelteBoundary(node, context) {
e.svelte_boundary_invalid_attribute(attribute); e.svelte_boundary_invalid_attribute(attribute);
} }
if (attribute.name === 'pending') {
node.metadata.pending = attribute;
}
if ( if (
attribute.value === true || attribute.value === true ||
(Array.isArray(attribute.value) && (Array.isArray(attribute.value) &&
@ -27,12 +23,5 @@ export function SvelteBoundary(node, context) {
} }
} }
node.metadata.pending ??=
/** @type {AST.SnippetBlock | undefined} */ (
node.fragment.nodes.find(
(node) => node.type === 'SnippetBlock' && node.expression.name === 'pending'
)
) ?? null;
context.next(); context.next();
} }

@ -1,9 +1,8 @@
/** @import { BlockStatement, Expression, Statement } from 'estree' */ /** @import { BlockStatement, Expression, Statement } from 'estree' */
/** @import { AST } from '#compiler' */ /** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */ /** @import { ComponentContext } from '../types.js' */
import { BLOCK_OPEN_ELSE } from '../../../../../internal/server/hydration.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { block_close, block_open } from './shared/utils.js'; import { block_close, block_open, block_open_else } from './shared/utils.js';
/** /**
* @param {AST.EachBlock} node * @param {AST.EachBlock} node
@ -49,7 +48,7 @@ export function EachBlock(node, context) {
const fallback = /** @type {BlockStatement} */ (context.visit(node.fallback)); const fallback = /** @type {BlockStatement} */ (context.visit(node.fallback));
fallback.body.unshift( fallback.body.unshift(
b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), b.literal(BLOCK_OPEN_ELSE))) b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open_else))
); );
state.template.push( state.template.push(

@ -1,9 +1,8 @@
/** @import { BlockStatement, Expression } from 'estree' */ /** @import { BlockStatement, Expression } from 'estree' */
/** @import { AST } from '#compiler' */ /** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */ /** @import { ComponentContext } from '../types.js' */
import { BLOCK_OPEN_ELSE } from '../../../../../internal/server/hydration.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { block_close, block_open } from './shared/utils.js'; import { block_close, block_open, block_open_else } from './shared/utils.js';
/** /**
* @param {AST.IfBlock} node * @param {AST.IfBlock} node
@ -20,7 +19,7 @@ export function IfBlock(node, context) {
consequent.body.unshift(b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open))); consequent.body.unshift(b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open)));
alternate.body.unshift( alternate.body.unshift(
b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), b.literal(BLOCK_OPEN_ELSE))) b.stmt(b.call(b.member(b.id('$$payload'), b.id('push')), block_open_else))
); );
context.state.template.push(b.if(test, consequent, alternate), block_close); context.state.template.push(b.if(test, consequent, alternate), block_close);

@ -1,36 +1,36 @@
/** @import { BlockStatement } from 'estree' */ /** @import { BlockStatement } from 'estree' */
/** @import { AST } from '#compiler' */ /** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */ /** @import { ComponentContext } from '../types' */
import {
BLOCK_CLOSE,
BLOCK_OPEN,
BLOCK_OPEN_ELSE
} from '../../../../../internal/server/hydration.js';
import * as b from '#compiler/builders'; 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 {AST.SvelteBoundary} node
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function SvelteBoundary(node, 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} */ (
if (pending_snippet) { node.attributes.find((node) => node.type === 'Attribute' && node.name === 'pending')
context.state.template.push(b.literal(BLOCK_OPEN_ELSE)); );
if (pending_snippet.type === 'Attribute') { const pending_snippet = /** @type {AST.SnippetBlock} */ (
const value = build_attribute_value(pending_snippet.value, context, false, true); node.fragment.nodes.find(
context.state.template.push(b.call(value, b.id('$$payload'))); (node) => node.type === 'SnippetBlock' && node.expression.name === 'pending'
} 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 { } else {
context.state.template.push(b.literal(BLOCK_OPEN)); const block = /** @type {BlockStatement} */ (context.visit(node.fragment));
context.state.template.push(/** @type {BlockStatement} */ (context.visit(node.fragment))); context.state.template.push(block_open, block, block_close);
} }
context.state.template.push(b.literal(BLOCK_CLOSE));
} }

@ -6,6 +6,7 @@ import { escape_html } from '../../../../../../escaping.js';
import { import {
BLOCK_CLOSE, BLOCK_CLOSE,
BLOCK_OPEN, BLOCK_OPEN,
BLOCK_OPEN_ELSE,
EMPTY_COMMENT EMPTY_COMMENT
} from '../../../../../../internal/server/hydration.js'; } from '../../../../../../internal/server/hydration.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
@ -16,6 +17,9 @@ import { has_await } from '../../../../../utils/ast.js';
/** Opens an if/each block, so that we can remove nodes in the case of a mismatch */ /** Opens an if/each block, so that we can remove nodes in the case of a mismatch */
export const block_open = b.literal(BLOCK_OPEN); export const block_open = b.literal(BLOCK_OPEN);
/** Opens an if/each block, so that we can remove nodes in the case of a mismatch */
export const block_open_else = b.literal(BLOCK_OPEN_ELSE);
/** 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 */ /** 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 */
export const block_close = b.literal(BLOCK_CLOSE); export const block_close = b.literal(BLOCK_CLOSE);

@ -409,10 +409,6 @@ export namespace AST {
export interface SvelteBoundary extends BaseElement { export interface SvelteBoundary extends BaseElement {
type: 'SvelteBoundary'; type: 'SvelteBoundary';
name: 'svelte:boundary'; name: 'svelte:boundary';
/** @internal */
metadata: {
pending: SnippetBlock | Attribute | null;
};
} }
export interface SvelteHead extends BaseElement { export interface SvelteHead extends BaseElement {

Loading…
Cancel
Save