diff --git a/.changeset/four-countries-taste.md b/.changeset/four-countries-taste.md new file mode 100644 index 0000000000..6873b2ae2d --- /dev/null +++ b/.changeset/four-countries-taste.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: error on TypeScript's `readonly` modifier 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 edbb673bd5..5febef420d 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 @@ -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; diff --git a/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte b/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte index d1c4f361ba..6c9cacdeff 100644 --- a/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte +++ b/packages/svelte/tests/runtime-runes/samples/typescript/main.svelte @@ -9,7 +9,10 @@ } class Foo { - constructor(readonly name: string) {} + public name: string; + constructor(name: string) { + this.name = name; + } } declare const declared_const: number; diff --git a/packages/svelte/tests/validator/samples/ts-unsupported-modifier-readonly/errors.json b/packages/svelte/tests/validator/samples/ts-unsupported-modifier-readonly/errors.json new file mode 100644 index 0000000000..44399179c0 --- /dev/null +++ b/packages/svelte/tests/validator/samples/ts-unsupported-modifier-readonly/errors.json @@ -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 `