Skip to content

Commit eea5c8f

Browse files
authored
chore: handle option warnings the same as others (#11303)
1 parent f6dfac9 commit eea5c8f

File tree

6 files changed

+87
-36
lines changed

6 files changed

+87
-36
lines changed
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
## missing_custom_element_compile_option
1+
## options_deprecated_immutable
22

3-
The 'customElement' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?
3+
The `immutable` option has been deprecated. It will have no effect in runes mode
4+
5+
## options_missing_custom_element
6+
7+
The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option?
8+
9+
## options_renamed_ssr_dom
10+
11+
`generate: "dom"` and `generate: "ssr"` options have been renamed to "client" and "server" respectively
12+
13+
## options_removed_enable_sourcemap
14+
15+
The `enableSourcemap` option has been removed. Source maps are always generated now, and tooling can choose to ignore them
16+
17+
## options_removed_hydratable
18+
19+
The `hydratable` option has been removed. Svelte components are always hydratable now
20+
21+
## options_removed_loop_guard_timeout
22+
23+
The `loopGuardTimeout` option has been removed

packages/svelte/scripts/process-messages/templates/compile-warnings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function reset_warnings(options) {
3131
*/
3232
function w(node, code, message) {
3333
// @ts-expect-error
34-
if (node.ignores?.has(code)) return;
34+
if (node?.ignores?.has(code)) return;
3535

3636
warnings.push({
3737
code,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export function analyze_component(root, source, options) {
396396
};
397397

398398
if (!options.customElement && root.options?.customElement) {
399-
w.missing_custom_element_compile_option(root.options);
399+
w.options_missing_custom_element(root.options);
400400
}
401401

402402
if (analysis.runes) {

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as e from './errors.js';
2+
import * as w from './warnings.js';
23

34
/**
45
* @template [Input=any]
@@ -13,9 +14,7 @@ const common = {
1314

1415
generate: validator('client', (input, keypath) => {
1516
if (input === 'dom' || input === 'ssr') {
16-
warn(
17-
'`generate: "dom"` and `generate: "ssr"` options have been renamed to "client" and "server" respectively'
18-
);
17+
warn_once(w.options_renamed_ssr_dom);
1918
return input === 'dom' ? 'client' : 'server';
2019
}
2120

@@ -72,16 +71,13 @@ export const validate_component_options =
7271

7372
discloseVersion: boolean(true),
7473

75-
immutable: deprecate(
76-
'The immutable option has been deprecated. It has no effect in runes mode.',
77-
boolean(false)
78-
),
74+
immutable: deprecate(w.options_deprecated_immutable, boolean(false)),
7975

8076
legacy: object({
8177
componentApi: boolean(false)
8278
}),
8379

84-
loopGuardTimeout: warn_removed('The loopGuardTimeout option has been removed.'),
80+
loopGuardTimeout: warn_removed(w.options_removed_loop_guard_timeout),
8581

8682
name: string(undefined),
8783

@@ -103,12 +99,8 @@ export const validate_component_options =
10399
return input;
104100
}),
105101

106-
enableSourcemap: warn_removed(
107-
'The enableSourcemap option has been removed. Source maps are always generated now, and tooling can choose to ignore them.'
108-
),
109-
hydratable: warn_removed(
110-
'The hydratable option has been removed. Svelte components are always hydratable now.'
111-
),
102+
enableSourcemap: warn_removed(w.options_removed_enable_sourcemap),
103+
hydratable: warn_removed(w.options_removed_hydratable),
112104
format: removed(
113105
'The format option has been removed in Svelte 4, the compiler only outputs ESM now. Remove "format" from your compiler options. ' +
114106
'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) {
149141

150142
const warned = new Set();
151143

152-
/** @param {string} message */
153-
function warn(message) {
154-
if (!warned.has(message)) {
155-
warned.add(message);
156-
// eslint-disable-next-line no-console
157-
console.warn(message);
144+
/** @param {(node: null) => void} fn */
145+
function warn_once(fn) {
146+
if (!warned.has(fn)) {
147+
warned.add(fn);
148+
fn(null);
158149
}
159150
}
160151

161152
/**
162-
* @param {string} message
153+
* @param {(node: null) => void} fn
163154
* @returns {Validator}
164155
*/
165-
function warn_removed(message) {
156+
function warn_removed(fn) {
166157
return (input) => {
167-
if (input !== undefined) warn(message);
158+
if (input !== undefined) warn_once(fn);
168159
return /** @type {any} */ (undefined);
169160
};
170161
}
171162

172163
/**
173-
* @param {string} message
164+
* @param {(node: null) => void} fn
174165
* @param {Validator} validator
175166
* @returns {Validator}
176167
*/
177-
function deprecate(message, validator) {
168+
function deprecate(fn, validator) {
178169
return (input, keypath) => {
179-
if (input !== undefined) warn(message);
170+
if (input !== undefined) warn_once(fn);
180171
return validator(input, keypath);
181172
};
182173
}

packages/svelte/src/compiler/warnings.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function reset_warnings(options) {
2929
*/
3030
function w(node, code, message) {
3131
// @ts-expect-error
32-
if (node.ignores?.has(code)) return;
32+
if (node?.ignores?.has(code)) return;
3333

3434
warnings.push({
3535
code,
@@ -545,11 +545,51 @@ export function invalid_self_closing_tag(node, name) {
545545
}
546546

547547
/**
548-
* The 'customElement' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?
548+
* The `immutable` option has been deprecated. It will have no effect in runes mode
549549
* @param {null | NodeLike} node
550550
*/
551-
export function missing_custom_element_compile_option(node) {
552-
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?");
551+
export function options_deprecated_immutable(node) {
552+
w(node, "options_deprecated_immutable", "The `immutable` option has been deprecated. It will have no effect in runes mode");
553+
}
554+
555+
/**
556+
* The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option?
557+
* @param {null | NodeLike} node
558+
*/
559+
export function options_missing_custom_element(node) {
560+
w(node, "options_missing_custom_element", "The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option?");
561+
}
562+
563+
/**
564+
* `generate: "dom"` and `generate: "ssr"` options have been renamed to "client" and "server" respectively
565+
* @param {null | NodeLike} node
566+
*/
567+
export function options_renamed_ssr_dom(node) {
568+
w(node, "options_renamed_ssr_dom", "`generate: \"dom\"` and `generate: \"ssr\"` options have been renamed to \"client\" and \"server\" respectively");
569+
}
570+
571+
/**
572+
* The `enableSourcemap` option has been removed. Source maps are always generated now, and tooling can choose to ignore them
573+
* @param {null | NodeLike} node
574+
*/
575+
export function options_removed_enable_sourcemap(node) {
576+
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");
577+
}
578+
579+
/**
580+
* The `hydratable` option has been removed. Svelte components are always hydratable now
581+
* @param {null | NodeLike} node
582+
*/
583+
export function options_removed_hydratable(node) {
584+
w(node, "options_removed_hydratable", "The `hydratable` option has been removed. Svelte components are always hydratable now");
585+
}
586+
587+
/**
588+
* The `loopGuardTimeout` option has been removed
589+
* @param {null | NodeLike} node
590+
*/
591+
export function options_removed_loop_guard_timeout(node) {
592+
w(node, "options_removed_loop_guard_timeout", "The `loopGuardTimeout` option has been removed");
553593
}
554594

555595
/**

packages/svelte/tests/validator/samples/tag-custom-element-options-missing/warnings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"code": "missing_custom_element_compile_option",
4-
"message": "The 'customElement' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?",
3+
"code": "options_missing_custom_element",
4+
"message": "The `customElement` option is used when generating a custom element. Did you forget the `customElement: true` compile option?",
55
"start": {
66
"line": 1,
77
"column": 0

0 commit comments

Comments
 (0)