Skip to content

Commit dad19ec

Browse files
committed
Fix issue with implicit public modifier causing undefined properties in classes
1 parent e6dd871 commit dad19ec

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const visitors = {
9494
e.typescript_invalid_feature(node, 'enums');
9595
},
9696
TSParameterProperty(node, context) {
97-
if (node.accessibility && context.path.at(-2)?.kind === 'constructor') {
97+
if ((node.readonly || node.accessibility) && context.path.at(-2)?.kind === 'constructor') {
9898
e.typescript_invalid_feature(node, 'accessibility modifiers on constructor parameters');
9999
}
100100
return node.parameter;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
}
1010
1111
class Foo {
12-
constructor(readonly name: string) {}
12+
public name: string;
13+
constructor(name: string) {
14+
this.name = name;
15+
}
1316
}
1417
1518
declare const declared_const: number;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "typescript_invalid_feature",
4+
"message": "TypeScript language features like accessibility modifiers on constructor parameters are not natively supported, and their use is generally discouraged. Outside of `<script>` tags, these features are not supported. For use within `<script>` tags, you will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler. If you are using `vitePreprocess`, make sure to specifically enable preprocessing script tags (`vitePreprocess({ script: true })`)",
5+
"start": {
6+
"line": 3,
7+
"column": 14
8+
},
9+
"end": {
10+
"line": 3,
11+
"column": 32
12+
}
13+
}
14+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts">
2+
class Foo {
3+
constructor(readonly x: number) {}
4+
}
5+
</script>

0 commit comments

Comments
 (0)