From b45d27274791069df1b46b26606480868d9df660 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 21 Apr 2024 17:28:36 -0400 Subject: [PATCH] add warnings for deprecated attributes --- .../src/compiler/phases/2-analyze/index.js | 16 ++++++++++++++-- packages/svelte/src/compiler/warnings.js | 6 +++++- .../warnings.json | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index 37eb3a3c92..c5fdb6c58d 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -406,8 +406,20 @@ export function analyze_component(root, source, options) { source }; - if (!options.customElement && root.options?.customElement) { - warn(analysis.warnings, root.options, [], 'missing-custom-element-compile-option'); + if (root.options) { + for (const attribute of root.options.attributes) { + if (attribute.name === 'accessors') { + warn(analysis.warnings, attribute, [], 'deprecated-accessors'); + } + + if (attribute.name === 'customElement' && !options.customElement) { + warn(analysis.warnings, attribute, [], 'missing-custom-element-compile-option'); + } + + if (attribute.name === 'immutable') { + warn(analysis.warnings, attribute, [], 'deprecated-immutable'); + } + } } if (analysis.runes) { diff --git a/packages/svelte/src/compiler/warnings.js b/packages/svelte/src/compiler/warnings.js index fc5897aa93..66c923ae19 100644 --- a/packages/svelte/src/compiler/warnings.js +++ b/packages/svelte/src/compiler/warnings.js @@ -238,7 +238,11 @@ const legacy = { `Using to render parent content is deprecated. Use {@render ...} tags instead.`, /** @param {string} name */ 'deprecated-event-handler': (name) => - `Using on:${name} to listen to the ${name} event is is deprecated. Use the event attribute on${name} instead.` + `Using on:${name} to listen to the ${name} event is is deprecated. Use the event attribute on${name} instead.`, + 'deprecated-accessors': () => + `The accessors option has been deprecated. It will have no effect in runes mode.`, + 'deprecated-immutable': () => + `The immutable option has been deprecated. It will have no effect in runes mode.` }; const block = { diff --git a/packages/svelte/tests/validator/samples/tag-custom-element-options-missing/warnings.json b/packages/svelte/tests/validator/samples/tag-custom-element-options-missing/warnings.json index 5ddce88a53..3c8b16bd7a 100644 --- a/packages/svelte/tests/validator/samples/tag-custom-element-options-missing/warnings.json +++ b/packages/svelte/tests/validator/samples/tag-custom-element-options-missing/warnings.json @@ -4,11 +4,11 @@ "message": "The 'customElement' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?", "start": { "line": 1, - "column": 0 + "column": 16 }, "end": { "line": 1, - "column": 49 + "column": 46 } } ]