Skip to content

Commit 9486c88

Browse files
committed
fix: Support experimental.async compiler option
1 parent f26aa0b commit 9486c88

File tree

8 files changed

+41
-0
lines changed

8 files changed

+41
-0
lines changed

.changeset/wild-steaks-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
fix: Support `experimental.async` compiler option

packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,12 @@ function getWarningsFromCode(
406406
kind: 'warn' | 'error';
407407
} {
408408
try {
409+
const svelteConfig = context.sourceCode.parserServices.svelteParseContext?.svelteConfig;
410+
const compilerOptions = svelteConfig?.compilerOptions ?? {};
409411
const result = compiler.compile(code, {
412+
experimental: {
413+
async: compilerOptions.experimental?.async
414+
},
410415
generate: false,
411416
...(isCustomElement(context.sourceCode.ast) ? { customElement: true } : {})
412417
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- message: |-
2+
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
3+
https://svelte.dev/e/experimental_async(experimental_async)
4+
line: 2
5+
column: 2
6+
suggestions: null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
await new Promise(() => {});
3+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"svelte": ">=5.0.0-0"
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
languageOptions: {
3+
parserOptions: {
4+
svelteConfig: {
5+
compilerOptions: {
6+
experimental: {
7+
async: true
8+
}
9+
}
10+
}
11+
}
12+
}
13+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script>
2+
await new Promise(() => {});
3+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"svelte": ">=5.0.0-0"
3+
}

0 commit comments

Comments
 (0)