From 36315fece462cf1a2afc4f1d44f9f527df3ae7db Mon Sep 17 00:00:00 2001 From: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com> Date: Sat, 14 Jun 2025 04:18:52 -0700 Subject: [PATCH] fix: prune typescript class field declarations (#16154) * fix: prune typescript class field declarations * add test --- .changeset/neat-lemons-occur.md | 5 +++++ .../phases/1-parse/remove_typescript_nodes.js | 13 +++++++++++++ .../runtime-runes/samples/typescript/main.svelte | 1 + 3 files changed, 19 insertions(+) create mode 100644 .changeset/neat-lemons-occur.md diff --git a/.changeset/neat-lemons-occur.md b/.changeset/neat-lemons-occur.md new file mode 100644 index 0000000000..53d77ed764 --- /dev/null +++ b/.changeset/neat-lemons-occur.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: prune typescript class field declarations diff --git a/packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js b/packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js index aba94ee20d..cb498c3c13 100644 --- a/packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js +++ b/packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js @@ -115,6 +115,19 @@ const visitors = { TSDeclareFunction() { return b.empty; }, + ClassBody(node, context) { + const body = []; + for (const _child of node.body) { + const child = context.visit(_child); + if (child.type !== 'PropertyDefinition' || !child.declare) { + body.push(child); + } + } + return { + ...node, + body + }; + }, ClassDeclaration(node, context) { if (node.declare) { 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 d1b6452df4..4fc7c4ec38 100644 --- a/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte +++ b/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte @@ -14,6 +14,7 @@ class Foo { public name: string; + declare bar: string; x = 'x' as const; constructor(name: string) { this.name = name;