diff --git a/.changeset/light-humans-hang.md b/.changeset/light-humans-hang.md new file mode 100644 index 0000000000..de1f6ed8ff --- /dev/null +++ b/.changeset/light-humans-hang.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: support TypeScript's `satisfies` operator diff --git a/packages/svelte/package.json b/packages/svelte/package.json index d464f21558..a8616f0a17 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -117,7 +117,7 @@ "@ampproject/remapping": "^2.2.1", "@jridgewell/sourcemap-codec": "^1.4.15", "acorn": "^8.10.0", - "acorn-typescript": "^1.4.11", + "acorn-typescript": "^1.4.13", "aria-query": "^5.3.0", "axobject-query": "^4.0.0", "esm-env": "^1.0.0", diff --git a/packages/svelte/src/compiler/phases/1-parse/acorn.js b/packages/svelte/src/compiler/phases/1-parse/acorn.js index ad23d47d6b..23fa756a9b 100644 --- a/packages/svelte/src/compiler/phases/1-parse/acorn.js +++ b/packages/svelte/src/compiler/phases/1-parse/acorn.js @@ -2,7 +2,7 @@ import * as acorn from 'acorn'; import { walk } from 'zimmerframe'; import { tsPlugin } from 'acorn-typescript'; -const ParserWithTS = acorn.Parser.extend(tsPlugin()); +const ParserWithTS = acorn.Parser.extend(tsPlugin({ allowSatisfies: true })); /** * @param {string} source diff --git a/packages/svelte/src/compiler/phases/3-transform/typescript.js b/packages/svelte/src/compiler/phases/3-transform/typescript.js index 9449ced6a0..e34d75691e 100644 --- a/packages/svelte/src/compiler/phases/3-transform/typescript.js +++ b/packages/svelte/src/compiler/phases/3-transform/typescript.js @@ -41,13 +41,16 @@ export const remove_types = { TSAsExpression(node, context) { return context.visit(node.expression); }, + TSSatisfiesExpression(node, context) { + return context.visit(node.expression); + }, TSNonNullExpression(node, context) { return context.visit(node.expression); }, - TSInterfaceDeclaration(node, context) { + TSInterfaceDeclaration() { return b.empty; }, - TSTypeAliasDeclaration(node, context) { + TSTypeAliasDeclaration() { return b.empty; } }; diff --git a/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte b/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte index 724988b55a..e991aa7533 100644 --- a/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte +++ b/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte @@ -10,6 +10,9 @@ import { type Bar, type Baz } from './types'; let count = $state(0); + const person = { + message: 'goodbye' + } satisfies Goodbye;