Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wild-steaks-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': patch
---

fix: Support `experimental.async` compiler option
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { IgnoreItem } from './ignore-comment.js';
import { getSvelteIgnoreItems } from './ignore-comment.js';
import { extractLeadingComments } from './extract-leading-comments.js';
import { findAttribute, getLangValue } from '../../utils/ast-utils.js';
import { getSvelteVersion } from '../../utils/svelte-context.js';
import path from 'path';
import fs from 'fs';

Expand Down Expand Up @@ -395,6 +396,8 @@ function isCustomElement(program: AST.SvelteProgram) {
});
}

const svelteVersion = getSvelteVersion();

/**
* Get compile warnings
*/
Expand All @@ -406,7 +409,16 @@ function getWarningsFromCode(
kind: 'warn' | 'error';
} {
try {
const svelteConfig = context.sourceCode.parserServices.svelteParseContext?.svelteConfig;
const compilerOptions = svelteConfig?.compilerOptions ?? {};
const result = compiler.compile(code, {
...(svelteVersion === '5'
? {
experimental: {
async: compilerOptions.experimental?.async
}
}
: {}),
generate: false,
...(isCustomElement(context.sourceCode.ast) ? { customElement: true } : {})
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- message: |-
Cannot use `await` in deriveds and template expressions, or at the top level of a component, unless the `experimental.async` compiler option is `true`
https://svelte.dev/e/experimental_async(experimental_async)
line: 2
column: 2
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
await new Promise(() => {});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": ">=5.0.0-0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
languageOptions: {
parserOptions: {
svelteConfig: {
compilerOptions: {
experimental: {
async: true
}
}
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
await new Promise(() => {});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": ">=5.0.0-0"
}
Loading