Skip to content

Commit 817b137

Browse files
authored
fix: Support experimental.async compiler option (#1438)
1 parent 89d030d commit 817b137

File tree

8 files changed

+48
-0
lines changed

8 files changed

+48
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { IgnoreItem } from './ignore-comment.js';
1515
import { getSvelteIgnoreItems } from './ignore-comment.js';
1616
import { extractLeadingComments } from './extract-leading-comments.js';
1717
import { findAttribute, getLangValue } from '../../utils/ast-utils.js';
18+
import { getSvelteVersion } from '../../utils/svelte-context.js';
1819
import path from 'path';
1920
import fs from 'fs';
2021

@@ -395,6 +396,8 @@ function isCustomElement(program: AST.SvelteProgram) {
395396
});
396397
}
397398

399+
const svelteVersion = getSvelteVersion();
400+
398401
/**
399402
* Get compile warnings
400403
*/
@@ -406,7 +409,16 @@ function getWarningsFromCode(
406409
kind: 'warn' | 'error';
407410
} {
408411
try {
412+
const svelteConfig = context.sourceCode.parserServices.svelteParseContext?.svelteConfig;
413+
const compilerOptions = svelteConfig?.compilerOptions ?? {};
409414
const result = compiler.compile(code, {
415+
...(svelteVersion === '5'
416+
? {
417+
experimental: {
418+
async: compilerOptions.experimental?.async
419+
}
420+
}
421+
: {}),
410422
generate: false,
411423
...(isCustomElement(context.sourceCode.ast) ? { customElement: true } : {})
412424
});
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)