From f580e2e0c8cb5d319cbc461d0e81e7d9ab716fbf Mon Sep 17 00:00:00 2001 From: gtmnayan <50981692+gtm-nayan@users.noreply.github.com> Date: Thu, 15 Jun 2023 01:16:44 +0545 Subject: [PATCH] fix: warn on boolean compilerOptions.css (#8710) * warn on boolean compilerOptions.css * changeset --- .changeset/stale-cougars-wink.md | 5 ++++ packages/svelte/src/compiler/compile/index.js | 29 ++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .changeset/stale-cougars-wink.md diff --git a/.changeset/stale-cougars-wink.md b/.changeset/stale-cougars-wink.md new file mode 100644 index 000000000000..67ffa3b04715 --- /dev/null +++ b/.changeset/stale-cougars-wink.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +warn on boolean compilerOptions.css diff --git a/packages/svelte/src/compiler/compile/index.js b/packages/svelte/src/compiler/compile/index.js index 39f14b702a84..d2ac8eba63fd 100644 --- a/packages/svelte/src/compiler/compile/index.js +++ b/packages/svelte/src/compiler/compile/index.js @@ -37,6 +37,7 @@ const regex_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; const regex_starts_with_lowercase_character = /^[a-z]/; let warned_of_format = false; +let warned_boolean_css = false; /** * @param {import('../interfaces.js').CompileOptions} options @@ -86,23 +87,23 @@ function validate_options(options, warnings) { toString: () => message }); } - if (valid_css_values.indexOf(css) === -1) { - throw new Error( - `options.css must be true, false, 'injected', 'external', or 'none' (got '${css}')` - ); - } + if (css === true || css === false) { options.css = css === true ? 'injected' : 'external'; - // possibly show this warning once we decided how Svelte 4 looks like - // const message = `options.css as a boolean is deprecated. Use '${options.css}' instead of ${css}.`; - // warnings.push({ - // code: 'options-css-boolean-deprecated', - // message, - // filename, - // toString: () => message - // }); - // } + if (!warned_boolean_css) { + console.warn( + `compilerOptions.css as a boolean is deprecated. Use '${options.css}' instead of ${css}.` + ); + warned_boolean_css = true; + } + } + + if (!valid_css_values.includes(options.css)) { + throw new Error( + `compilerOptions.css must be 'injected', 'external' or 'none' (got '${options.css}').` + ); } + if (namespace && valid_namespaces.indexOf(namespace) === -1) { const match = fuzzymatch(namespace, valid_namespaces); if (match) {