diff --git a/packages/svelte/messages/compile-warnings/options.md b/packages/svelte/messages/compile-warnings/options.md index 0b970fb26c..ed69b9f421 100644 --- a/packages/svelte/messages/compile-warnings/options.md +++ b/packages/svelte/messages/compile-warnings/options.md @@ -1,3 +1,23 @@ -## missing_custom_element_compile_option +## options_deprecated_immutable -The 'customElement' option is used when generating a custom element. Did you forget the 'customElement: true' compile option? +The `immutable` option has been deprecated. It will have no effect in runes mode + +## options_missing_custom_element + +The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option? + +## options_renamed_ssr_dom + +`generate: "dom"` and `generate: "ssr"` options have been renamed to "client" and "server" respectively + +## options_removed_enable_sourcemap + +The `enableSourcemap` option has been removed. Source maps are always generated now, and tooling can choose to ignore them + +## options_removed_hydratable + +The `hydratable` option has been removed. Svelte components are always hydratable now + +## options_removed_loop_guard_timeout + +The `loopGuardTimeout` option has been removed diff --git a/packages/svelte/scripts/process-messages/templates/compile-warnings.js b/packages/svelte/scripts/process-messages/templates/compile-warnings.js index e9a0ad3a7d..cac547de60 100644 --- a/packages/svelte/scripts/process-messages/templates/compile-warnings.js +++ b/packages/svelte/scripts/process-messages/templates/compile-warnings.js @@ -31,7 +31,7 @@ export function reset_warnings(options) { */ function w(node, code, message) { // @ts-expect-error - if (node.ignores?.has(code)) return; + if (node?.ignores?.has(code)) return; warnings.push({ code, diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index 848ea4ebfa..fad0061551 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -396,7 +396,7 @@ export function analyze_component(root, source, options) { }; if (!options.customElement && root.options?.customElement) { - w.missing_custom_element_compile_option(root.options); + w.options_missing_custom_element(root.options); } if (analysis.runes) { diff --git a/packages/svelte/src/compiler/validate-options.js b/packages/svelte/src/compiler/validate-options.js index d9b0e9b1c3..157ea6fd35 100644 --- a/packages/svelte/src/compiler/validate-options.js +++ b/packages/svelte/src/compiler/validate-options.js @@ -1,4 +1,5 @@ import * as e from './errors.js'; +import * as w from './warnings.js'; /** * @template [Input=any] @@ -13,9 +14,7 @@ const common = { generate: validator('client', (input, keypath) => { if (input === 'dom' || input === 'ssr') { - warn( - '`generate: "dom"` and `generate: "ssr"` options have been renamed to "client" and "server" respectively' - ); + warn_once(w.options_renamed_ssr_dom); return input === 'dom' ? 'client' : 'server'; } @@ -72,16 +71,13 @@ export const validate_component_options = discloseVersion: boolean(true), - immutable: deprecate( - 'The immutable option has been deprecated. It has no effect in runes mode.', - boolean(false) - ), + immutable: deprecate(w.options_deprecated_immutable, boolean(false)), legacy: object({ componentApi: boolean(false) }), - loopGuardTimeout: warn_removed('The loopGuardTimeout option has been removed.'), + loopGuardTimeout: warn_removed(w.options_removed_loop_guard_timeout), name: string(undefined), @@ -103,12 +99,8 @@ export const validate_component_options = return input; }), - enableSourcemap: warn_removed( - 'The enableSourcemap option has been removed. Source maps are always generated now, and tooling can choose to ignore them.' - ), - hydratable: warn_removed( - 'The hydratable option has been removed. Svelte components are always hydratable now.' - ), + enableSourcemap: warn_removed(w.options_removed_enable_sourcemap), + hydratable: warn_removed(w.options_removed_hydratable), format: removed( 'The format option has been removed in Svelte 4, the compiler only outputs ESM now. Remove "format" from your compiler options. ' + 'If you did not set this yourself, bump the version of your bundler plugin (vite-plugin-svelte/rollup-plugin-svelte/svelte-loader)' @@ -149,34 +141,33 @@ function removed(msg) { const warned = new Set(); -/** @param {string} message */ -function warn(message) { - if (!warned.has(message)) { - warned.add(message); - // eslint-disable-next-line no-console - console.warn(message); +/** @param {(node: null) => void} fn */ +function warn_once(fn) { + if (!warned.has(fn)) { + warned.add(fn); + fn(null); } } /** - * @param {string} message + * @param {(node: null) => void} fn * @returns {Validator} */ -function warn_removed(message) { +function warn_removed(fn) { return (input) => { - if (input !== undefined) warn(message); + if (input !== undefined) warn_once(fn); return /** @type {any} */ (undefined); }; } /** - * @param {string} message + * @param {(node: null) => void} fn * @param {Validator} validator * @returns {Validator} */ -function deprecate(message, validator) { +function deprecate(fn, validator) { return (input, keypath) => { - if (input !== undefined) warn(message); + if (input !== undefined) warn_once(fn); return validator(input, keypath); }; } diff --git a/packages/svelte/src/compiler/warnings.js b/packages/svelte/src/compiler/warnings.js index 1e71aa51a6..d4a41de1a1 100644 --- a/packages/svelte/src/compiler/warnings.js +++ b/packages/svelte/src/compiler/warnings.js @@ -29,7 +29,7 @@ export function reset_warnings(options) { */ function w(node, code, message) { // @ts-expect-error - if (node.ignores?.has(code)) return; + if (node?.ignores?.has(code)) return; warnings.push({ code, @@ -545,11 +545,51 @@ export function invalid_self_closing_tag(node, name) { } /** - * The 'customElement' option is used when generating a custom element. Did you forget the 'customElement: true' compile option? + * The `immutable` option has been deprecated. It will have no effect in runes mode * @param {null | NodeLike} node */ -export function missing_custom_element_compile_option(node) { - w(node, "missing_custom_element_compile_option", "The 'customElement' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?"); +export function options_deprecated_immutable(node) { + w(node, "options_deprecated_immutable", "The `immutable` option has been deprecated. It will have no effect in runes mode"); +} + +/** + * The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option? + * @param {null | NodeLike} node + */ +export function options_missing_custom_element(node) { + w(node, "options_missing_custom_element", "The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option?"); +} + +/** + * `generate: "dom"` and `generate: "ssr"` options have been renamed to "client" and "server" respectively + * @param {null | NodeLike} node + */ +export function options_renamed_ssr_dom(node) { + w(node, "options_renamed_ssr_dom", "`generate: \"dom\"` and `generate: \"ssr\"` options have been renamed to \"client\" and \"server\" respectively"); +} + +/** + * The `enableSourcemap` option has been removed. Source maps are always generated now, and tooling can choose to ignore them + * @param {null | NodeLike} node + */ +export function options_removed_enable_sourcemap(node) { + w(node, "options_removed_enable_sourcemap", "The `enableSourcemap` option has been removed. Source maps are always generated now, and tooling can choose to ignore them"); +} + +/** + * The `hydratable` option has been removed. Svelte components are always hydratable now + * @param {null | NodeLike} node + */ +export function options_removed_hydratable(node) { + w(node, "options_removed_hydratable", "The `hydratable` option has been removed. Svelte components are always hydratable now"); +} + +/** + * The `loopGuardTimeout` option has been removed + * @param {null | NodeLike} node + */ +export function options_removed_loop_guard_timeout(node) { + w(node, "options_removed_loop_guard_timeout", "The `loopGuardTimeout` option has been removed"); } /** 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 72602abb85..bdc1d737b8 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 @@ -1,7 +1,7 @@ [ { - "code": "missing_custom_element_compile_option", - "message": "The 'customElement' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?", + "code": "options_missing_custom_element", + "message": "The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option?", "start": { "line": 1, "column": 0