Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue with implicit public modifier causing undefined properties #14153

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/four-countries-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: issue with implicit public modifier causing undefined properties in classes
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const visitors = {
e.typescript_invalid_feature(node, 'enums');
},
TSParameterProperty(node, context) {
if (node.accessibility && context.path.at(-2)?.kind === 'constructor') {
if ((node.readonly || node.accessibility) && context.path.at(-2)?.kind === 'constructor') {
e.typescript_invalid_feature(node, 'accessibility modifiers on constructor parameters');
}
return node.parameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
}

class Foo {
constructor(readonly name: string) {}
public name: string;
constructor(name: string) {
this.name = name;
}
}

declare const declared_const: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "typescript_invalid_feature",
"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 })`)",
"start": {
"line": 3,
"column": 14
},
"end": {
"line": 3,
"column": 32
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
class Foo {
constructor(readonly x: number) {}
}
</script>