Skip to content

Commit 46a004e

Browse files
committed
add experimental.async option
1 parent b78fed8 commit 46a004e

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

documentation/docs/98-reference/.generated/compile-errors.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ Expected token %token%
444444
Expected whitespace
445445
```
446446

447+
### experimental_async
448+
449+
```
450+
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
451+
```
452+
447453
### export_undefined
448454

449455
```
@@ -501,7 +507,7 @@ The arguments keyword cannot be used within the template or at the top level of
501507
### legacy_await_invalid
502508

503509
```
504-
Cannot use `await` at the top level of a component, or in the template, unless in runes mode
510+
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless in runes mode
505511
```
506512

507513
### legacy_export_invalid

packages/svelte/messages/compile-errors/script.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ This turned out to be buggy and unpredictable, particularly when working with de
7070

7171
> `$effect()` can only be used as an expression statement
7272
73+
## experimental_async
74+
75+
> Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
76+
7377
## export_undefined
7478

7579
> `%name%` is not defined
@@ -100,7 +104,7 @@ This turned out to be buggy and unpredictable, particularly when working with de
100104
101105
## legacy_await_invalid
102106

103-
> Cannot use `await` at the top level of a component, or in the template, unless in runes mode
107+
> Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless in runes mode
104108
105109
## legacy_export_invalid
106110

packages/svelte/src/compiler/errors.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ export function effect_invalid_placement(node) {
168168
e(node, 'effect_invalid_placement', `\`$effect()\` can only be used as an expression statement\nhttps://svelte.dev/e/effect_invalid_placement`);
169169
}
170170

171+
/**
172+
* Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
173+
* @param {null | number | NodeLike} node
174+
* @returns {never}
175+
*/
176+
export function experimental_async(node) {
177+
e(node, 'experimental_async', `Cannot use \`await\` in deriveds and template expressions, or at the top level of a component, unless the \`experimental.async\` compiler option is \`true\`\nhttps://svelte.dev/e/experimental_async`);
178+
}
179+
171180
/**
172181
* `%name%` is not defined
173182
* @param {null | number | NodeLike} node
@@ -234,12 +243,12 @@ export function invalid_arguments_usage(node) {
234243
}
235244

236245
/**
237-
* Cannot use `await` at the top level of a component, or in the template, unless in runes mode
246+
* Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless in runes mode
238247
* @param {null | number | NodeLike} node
239248
* @returns {never}
240249
*/
241250
export function legacy_await_invalid(node) {
242-
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`);
251+
e(node, 'legacy_await_invalid', `Cannot use \`await\` in deriveds and template expressions, or at the top level of a component, unless in runes mode\nhttps://svelte.dev/e/legacy_await_invalid`);
243252
}
244253

245254
/**

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ export interface ModuleCompileOptions {
212212
* Use this to filter out warnings. Return `true` to keep the warning, `false` to discard it.
213213
*/
214214
warningFilter?: (warning: Warning) => boolean;
215+
/** Experimental options */
216+
experimental?: {
217+
/** Allow `await` keyword in deriveds, template expressions, and the top level of components */
218+
async?: boolean;
219+
};
215220
}
216221

217222
// The following two somewhat scary looking types ensure that certain types are required but can be undefined still

packages/svelte/src/compiler/validate-options.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ const common = {
4141
return input;
4242
}),
4343

44-
warningFilter: fun(() => true)
44+
warningFilter: fun(() => true),
45+
46+
experimental: object({
47+
async: boolean(false)
48+
})
4549
};
4650

4751
export const validate_module_options =

packages/svelte/types/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,11 @@ declare module 'svelte/compiler' {
933933
* Use this to filter out warnings. Return `true` to keep the warning, `false` to discard it.
934934
*/
935935
warningFilter?: (warning: Warning) => boolean;
936+
/** Experimental options */
937+
experimental?: {
938+
/** Allow `await` keyword in deriveds, template expressions, and the top level of components */
939+
async?: boolean;
940+
};
936941
}
937942
/**
938943
* - `html` — the default, for e.g. `<div>` or `<span>`
@@ -2635,6 +2640,11 @@ declare module 'svelte/types/compiler/interfaces' {
26352640
* Use this to filter out warnings. Return `true` to keep the warning, `false` to discard it.
26362641
*/
26372642
warningFilter?: (warning: Warning_1) => boolean;
2643+
/** Experimental options */
2644+
experimental?: {
2645+
/** Allow `await` keyword in deriveds, template expressions, and the top level of components */
2646+
async?: boolean;
2647+
};
26382648
}
26392649
/**
26402650
* - `html` — the default, for e.g. `<div>` or `<span>`

0 commit comments

Comments
 (0)