Skip to content

Commit 476f217

Browse files
fix: mark accessors and immutable as deprecated (#11277)
* fix: mark `accessors` and `immutable` as deprecated * add warnings for deprecated <svelte:options> attributes * disable accessors in runes mode * update tests * tidy up * the hell? * regenerate types * if I would get a dollar for every windows bug I fix I would be a millionaire by now * return instance _and_ props in runes mode, move flushSync into shared code, don't set accessors in runes mode * goddammit * note breaking change * fix * regenerate messages * Revert "return instance _and_ props in runes mode, move flushSync into shared code, don't set accessors in runes mode" This reverts commit a47827e. * pass instance to tests --------- Co-authored-by: Simon Holthausen <[email protected]>
1 parent 22b2c15 commit 476f217

File tree

29 files changed

+154
-56
lines changed

29 files changed

+154
-56
lines changed

.changeset/tiny-meals-deliver.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: mark `accessors` and `immutable` as deprecated

packages/svelte/messages/compile-warnings/legacy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
1717
## deprecated_event_handler
1818

19-
> Using on:%name% to listen to the %name% event is is deprecated. Use the event attribute on%name% instead.
19+
> Using on:%name% to listen to the %name% event is is deprecated. Use the event attribute on%name% instead.

packages/svelte/messages/compile-warnings/options.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## options_deprecated_accessors
2+
3+
The `accessors` option has been deprecated. It will have no effect in runes mode
4+
15
## options_deprecated_immutable
26

37
> The `immutable` option has been deprecated. It will have no effect in runes mode

packages/svelte/scripts/process-messages/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ for (const category of fs.readdirSync('messages')) {
1313
for (const file of fs.readdirSync(`messages/${category}`)) {
1414
if (!file.endsWith('.md')) continue;
1515

16-
const markdown = fs.readFileSync(`messages/${category}/${file}`, 'utf-8');
16+
const markdown = fs
17+
.readFileSync(`messages/${category}/${file}`, 'utf-8')
18+
.replace(/\r\n/g, '\n');
1719

1820
for (const match of markdown.matchAll(/## ([\w]+)\n\n([^]+?)(?=$|\n\n## )/g)) {
1921
const [_, code, text] = match;
@@ -33,7 +35,9 @@ for (const category of fs.readdirSync('messages')) {
3335
}
3436

3537
function transform(name, dest) {
36-
const source = fs.readFileSync(new URL(`./templates/${name}.js`, import.meta.url), 'utf-8');
38+
const source = fs
39+
.readFileSync(new URL(`./templates/${name}.js`, import.meta.url), 'utf-8')
40+
.replace(/\r\n/g, '\n');
3741

3842
const comments = [];
3943

@@ -217,7 +221,8 @@ function transform(name, dest) {
217221

218222
fs.writeFileSync(
219223
dest,
220-
`/* This file is generated by scripts/process-messages.js. Do not edit! */\n\n` + module.code,
224+
`/* This file is generated by scripts/process-messages/index.js. Do not edit! */\n\n` +
225+
module.code,
221226
'utf-8'
222227
);
223228
}

packages/svelte/src/compiler/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is generated by scripts/process-messages.js. Do not edit! */
1+
/* This file is generated by scripts/process-messages/index.js. Do not edit! */
22

33
/** @typedef {{ start?: number, end?: number }} NodeLike */
44
// interface is duplicated between here (used internally) and ./interfaces.js

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export function analyze_component(root, source, options) {
374374
inject_styles: options.css === 'injected' || options.customElement,
375375
accessors: options.customElement
376376
? true
377-
: !!options.accessors ||
377+
: (runes ? false : !!options.accessors) ||
378378
// because $set method needs accessors
379379
!!options.legacy?.componentApi,
380380
reactive_statements: new Map(),
@@ -395,8 +395,20 @@ export function analyze_component(root, source, options) {
395395
source
396396
};
397397

398-
if (!options.customElement && root.options?.customElement) {
399-
w.options_missing_custom_element(root.options);
398+
if (root.options) {
399+
for (const attribute of root.options.attributes) {
400+
if (attribute.name === 'accessors') {
401+
w.options_deprecated_accessors(attribute);
402+
}
403+
404+
if (attribute.name === 'customElement' && !options.customElement) {
405+
w.options_missing_custom_element(attribute);
406+
}
407+
408+
if (attribute.name === 'immutable') {
409+
w.options_deprecated_immutable(attribute);
410+
}
411+
}
400412
}
401413

402414
if (analysis.runes) {

packages/svelte/src/compiler/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface CompileOptions extends ModuleCompileOptions {
9494
* If `true`, getters and setters will be created for the component's props. If `false`, they will only be created for readonly exported values (i.e. those declared with `const`, `class` and `function`). If compiling with `customElement: true` this option defaults to `true`.
9595
*
9696
* @default false
97+
* @deprecated This will have no effect in runes mode
9798
*/
9899
accessors?: boolean;
99100
/**
@@ -107,6 +108,7 @@ export interface CompileOptions extends ModuleCompileOptions {
107108
* This allows it to be less conservative about checking whether values have changed.
108109
*
109110
* @default false
111+
* @deprecated This will have no effect in runes mode
110112
*/
111113
immutable?: boolean;
112114
/**

packages/svelte/src/compiler/validate-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const validate_component_options =
3939
object({
4040
...common,
4141

42-
accessors: boolean(false),
42+
accessors: deprecate(w.options_deprecated_accessors, boolean(false)),
4343

4444
css: validator('external', (input) => {
4545
if (input === true || input === false) {

packages/svelte/src/compiler/warnings.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is generated by scripts/process-messages.js. Do not edit! */
1+
/* This file is generated by scripts/process-messages/index.js. Do not edit! */
22

33
import { getLocator } from 'locate-character';
44

@@ -544,6 +544,14 @@ export function invalid_self_closing_tag(node, name) {
544544
w(node, "invalid_self_closing_tag", `Self-closing HTML tags for non-void elements are ambiguous — use <${name} ...></${name}> rather than <${name} ... />`);
545545
}
546546

547+
/**
548+
* e `accessors` option has been deprecated. It will have no effect in runes mode
549+
* @param {null | NodeLike} node
550+
*/
551+
export function options_deprecated_accessors(node) {
552+
w(node, "options_deprecated_accessors", "e `accessors` option has been deprecated. It will have no effect in runes mode");
553+
}
554+
547555
/**
548556
* The `immutable` option has been deprecated. It will have no effect in runes mode
549557
* @param {null | NodeLike} node

packages/svelte/src/internal/client/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* This file is generated by scripts/process-messages.js. Do not edit! */
1+
/* This file is generated by scripts/process-messages/index.js. Do not edit! */
22

33
import { DEV } from 'esm-env';
44

0 commit comments

Comments
 (0)