use proper compiler error for await-in-legacy-mode

aaa
Rich Harris 8 months ago
parent d5de86803d
commit 4a9c4c6f50

@ -498,6 +498,12 @@ The arguments keyword cannot be used within the template or at the top level of
%message% %message%
``` ```
### legacy_await_invalid
```
Cannot use `await` at the top level of a component, or in the template, unless in runes mode
```
### legacy_export_invalid ### legacy_export_invalid
``` ```

@ -6,6 +6,8 @@
Cannot await outside a `<svelte:boundary>` with a `pending` snippet Cannot await outside a `<svelte:boundary>` with a `pending` snippet
``` ```
TODO
### invalid_default_snippet ### invalid_default_snippet
``` ```

@ -98,6 +98,10 @@ This turned out to be buggy and unpredictable, particularly when working with de
> The arguments keyword cannot be used within the template or at the top level of a component > The arguments keyword cannot be used within the template or at the top level of a component
## legacy_await_invalid
> Cannot use `await` at the top level of a component, or in the template, unless in runes mode
## legacy_export_invalid ## legacy_export_invalid
> Cannot use `export let` in runes mode — use `$props()` instead > Cannot use `export let` in runes mode — use `$props()` instead

@ -497,6 +497,15 @@ export function typescript_invalid_feature(node, feature) {
e(node, 'typescript_invalid_feature', `TypeScript language features like ${feature} are not natively supported, and their use is generally discouraged. Outside of \`<script>\` tags, these features are not supported. For use within \`<script>\` tags, you will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler. If you are using \`vitePreprocess\`, make sure to specifically enable preprocessing script tags (\`vitePreprocess({ script: true })\`)\nhttps://svelte.dev/e/typescript_invalid_feature`); e(node, 'typescript_invalid_feature', `TypeScript language features like ${feature} are not natively supported, and their use is generally discouraged. Outside of \`<script>\` tags, these features are not supported. For use within \`<script>\` tags, you will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler. If you are using \`vitePreprocess\`, make sure to specifically enable preprocessing script tags (\`vitePreprocess({ script: true })\`)\nhttps://svelte.dev/e/typescript_invalid_feature`);
} }
/**
* Cannot use `await` at the top level of a component, or in the template, unless in runes mode
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function legacy_await_invalid(node) {
e(node, 'legacy_await_invalid', `Cannot use \`await\` at the top level of a component, or in the template, unless in runes mode\nhttps://svelte.dev/e/legacy_await_invalid`);
}
/** /**
* Declaration cannot be empty * Declaration cannot be empty
* @param {null | number | NodeLike} node * @param {null | number | NodeLike} node

@ -1,5 +1,6 @@
/** @import { AwaitExpression } from 'estree' */ /** @import { AwaitExpression } from 'estree' */
/** @import { Context } from '../types' */ /** @import { Context } from '../types' */
import * as e from '../../../errors.js';
/** /**
* @param {AwaitExpression} node * @param {AwaitExpression} node
@ -32,7 +33,7 @@ export function AwaitExpression(node, context) {
if (suspend) { if (suspend) {
if (!context.state.analysis.runes) { if (!context.state.analysis.runes) {
throw new Error('TODO runes mode only'); e.legacy_await_invalid(node);
} }
context.state.analysis.suspenders.set(node, preserve_context); context.state.analysis.suspenders.set(node, preserve_context);

@ -2,6 +2,21 @@
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
/**
* 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`);
}
}
/** /**
* 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
* @returns {never} * @returns {never}
@ -63,18 +78,3 @@ export function svelte_element_invalid_this_value() {
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