aaa
Rich Harris 8 months ago
parent 364f45a08e
commit 96942400bd

@ -1,5 +1,11 @@
<!-- This file is generated by scripts/process-messages/index.js. Do not edit! --> <!-- This file is generated by scripts/process-messages/index.js. Do not edit! -->
### await_outside_boundary
```
Cannot await outside a `<svelte:boundary>` with a `pending` snippet
```
### invalid_default_snippet ### invalid_default_snippet
``` ```

@ -1,3 +1,9 @@
## await_outside_boundary
> Cannot await outside a `<svelte:boundary>` with a `pending` snippet
TODO
## invalid_default_snippet ## invalid_default_snippet
> Cannot use `{@render children(...)}` if the parent component uses `let:` directives. Consider using a named snippet instead > Cannot use `{@render children(...)}` if the parent component uses `let:` directives. Consider using a named snippet instead

@ -1,10 +1,10 @@
/** @import { AwaitExpression, Expression } from 'estree' */ /** @import { AwaitExpression, Expression } from 'estree' */
/** @import { ComponentContext } from '../types' */ /** @import { Context } from '../types' */
import * as b from '../../../../utils/builders.js'; import * as b from '../../../../utils/builders.js';
/** /**
* @param {AwaitExpression} node * @param {AwaitExpression} node
* @param {ComponentContext} context * @param {Context} context
*/ */
export function AwaitExpression(node, context) { export function AwaitExpression(node, context) {
const suspend = context.state.analysis.suspenders.has(node); const suspend = context.state.analysis.suspenders.has(node);

@ -10,6 +10,7 @@ import { dev, filename } from '../../../state.js';
import { render_stylesheet } from '../css/index.js'; import { render_stylesheet } from '../css/index.js';
import { AssignmentExpression } from './visitors/AssignmentExpression.js'; import { AssignmentExpression } from './visitors/AssignmentExpression.js';
import { AwaitBlock } from './visitors/AwaitBlock.js'; import { AwaitBlock } from './visitors/AwaitBlock.js';
import { AwaitExpression } from './visitors/AwaitExpression.js';
import { CallExpression } from './visitors/CallExpression.js'; import { CallExpression } from './visitors/CallExpression.js';
import { ClassBody } from './visitors/ClassBody.js'; import { ClassBody } from './visitors/ClassBody.js';
import { Component } from './visitors/Component.js'; import { Component } from './visitors/Component.js';
@ -44,6 +45,7 @@ import { SvelteBoundary } from './visitors/SvelteBoundary.js';
const global_visitors = { const global_visitors = {
_: set_scope, _: set_scope,
AssignmentExpression, AssignmentExpression,
AwaitExpression,
CallExpression, CallExpression,
ClassBody, ClassBody,
ExpressionStatement, ExpressionStatement,

@ -0,0 +1,17 @@
/** @import { AwaitExpression } from 'estree' */
/** @import { ComponentContext } from '../types.js' */
import * as b from '../../../../utils/builders.js';
/**
* @param {AwaitExpression} node
* @param {ComponentContext} context
*/
export function AwaitExpression(node, context) {
const suspend = context.state.analysis.suspenders.has(node);
if (!suspend) {
return context.next();
}
return b.call('$.await_outside_boundary');
}

@ -1,17 +1,38 @@
/** @import { BlockStatement } from 'estree' */ /** @import { BlockStatement, Expression } from 'estree' */
/** @import { AST } from '#compiler' */ /** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */ /** @import { ComponentContext } from '../types' */
import { BLOCK_CLOSE, BLOCK_OPEN } from '../../../../../internal/server/hydration.js'; import { BLOCK_CLOSE, BLOCK_OPEN } from '../../../../../internal/server/hydration.js';
import * as b from '../../../../utils/builders.js'; import * as b from '../../../../utils/builders.js';
import { 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) {
context.state.template.push( context.state.template.push(b.literal(BLOCK_OPEN));
b.literal(BLOCK_OPEN),
/** @type {BlockStatement} */ (context.visit(node.fragment)), // if this has a `pending` snippet, render it
b.literal(BLOCK_CLOSE) const pending_attribute = /** @type {AST.Attribute} */ (
node.attributes.find((node) => node.type === 'Attribute' && node.name === 'pending')
);
const pending_snippet = /** @type {AST.SnippetBlock} */ (
node.fragment.nodes.find(
(node) => node.type === 'SnippetBlock' && node.expression.name === 'pending'
)
); );
if (pending_attribute) {
const value = build_attribute_value(pending_attribute.value, context, false, true);
context.state.template.push(b.call(value, b.id('$$payload')));
} else if (pending_snippet) {
context.state.template.push(
/** @type {BlockStatement} */ (context.visit(pending_snippet.body))
);
} else {
context.state.template.push(/** @type {BlockStatement} */ (context.visit(node.fragment)));
}
context.state.template.push(b.literal(BLOCK_CLOSE));
} }

@ -545,3 +545,5 @@ export {
} from '../shared/validate.js'; } from '../shared/validate.js';
export { escape_html as escape }; export { escape_html as escape };
export { await_outside_boundary } from '../shared/errors.js';

@ -62,4 +62,19 @@ export function svelte_element_invalid_this_value() {
} else { } else {
throw new Error(`https://svelte.dev/e/svelte_element_invalid_this_value`); throw new Error(`https://svelte.dev/e/svelte_element_invalid_this_value`);
} }
}
/**
* Cannot await outside a `<svelte:boundary>` with a `pending` snippet
* @returns {never}
*/
export function await_outside_boundary() {
if (DEV) {
const error = new Error(`await_outside_boundary\nCannot await outside a \`<svelte:boundary>\` with a \`pending\` snippet\nhttps://svelte.dev/e/await_outside_boundary`);
error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/await_outside_boundary`);
}
} }
Loading…
Cancel
Save