Skip to content

Commit 36315fe

Browse files
authored
fix: prune typescript class field declarations (#16154)
* fix: prune typescript class field declarations * add test
1 parent 6a7df1c commit 36315fe

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

.changeset/neat-lemons-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: prune typescript class field declarations

packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ const visitors = {
115115
TSDeclareFunction() {
116116
return b.empty;
117117
},
118+
ClassBody(node, context) {
119+
const body = [];
120+
for (const _child of node.body) {
121+
const child = context.visit(_child);
122+
if (child.type !== 'PropertyDefinition' || !child.declare) {
123+
body.push(child);
124+
}
125+
}
126+
return {
127+
...node,
128+
body
129+
};
130+
},
118131
ClassDeclaration(node, context) {
119132
if (node.declare) {
120133
return b.empty;

packages/svelte/tests/runtime-runes/samples/typescript/main.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
class Foo<T> {
1616
public name: string;
17+
declare bar: string;
1718
x = 'x' as const;
1819
constructor(name: string) {
1920
this.name = name;

0 commit comments

Comments
 (0)