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

closes #14152
pull/14167/head
Caique Torres 2 months ago committed by GitHub
parent ecc9b97a5b
commit 5077061695
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: error on TypeScript's `readonly` modifier

@ -94,7 +94,7 @@ const visitors = {
e.typescript_invalid_feature(node, 'enums'); e.typescript_invalid_feature(node, 'enums');
}, },
TSParameterProperty(node, context) { 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'); e.typescript_invalid_feature(node, 'accessibility modifiers on constructor parameters');
} }
return node.parameter; return node.parameter;

@ -9,7 +9,10 @@
} }
class Foo { class Foo {
constructor(readonly name: string) {} public name: string;
constructor(name: string) {
this.name = name;
}
} }
declare const declared_const: number; declare const declared_const: number;

@ -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
}
}
]

@ -0,0 +1,5 @@
<script lang="ts">
class Foo {
constructor(readonly x: number) {}
}
</script>
Loading…
Cancel
Save