Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn on boolean compilerOptions.css #8710

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stale-cougars-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

warn on boolean compilerOptions.css
29 changes: 15 additions & 14 deletions packages/svelte/src/compiler/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down