|
|
|
|
@ -51,24 +51,28 @@ const common_options = {
|
|
|
|
|
const component_options = {
|
|
|
|
|
accessors: deprecate(w.options_deprecated_accessors, boolean(false)),
|
|
|
|
|
|
|
|
|
|
css: validator('external', (input) => {
|
|
|
|
|
if (input === true || input === false) {
|
|
|
|
|
throw_error(
|
|
|
|
|
'The boolean options have been removed from the css option. Use "external" instead of false and "injected" instead of true'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (input === 'none') {
|
|
|
|
|
throw_error(
|
|
|
|
|
'css: "none" is no longer a valid option. If this was crucial for you, please open an issue on GitHub with your use case.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
/** @type {Validator<'injected' | 'external' | ((options: { filename: string }) => 'injected' | 'external'), (options: { filename: string }) => 'injected' | 'external'>} */
|
|
|
|
|
css: parametric(
|
|
|
|
|
/** @type {(options: { filename: string }) => 'injected' | 'external'} */ (() => 'external'),
|
|
|
|
|
(input) => {
|
|
|
|
|
if (input === true || input === false) {
|
|
|
|
|
throw_error(
|
|
|
|
|
'The boolean options have been removed from the css option. Use "external" instead of false and "injected" instead of true'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (input === 'none') {
|
|
|
|
|
throw_error(
|
|
|
|
|
'css: "none" is no longer a valid option. If this was crucial for you, please open an issue on GitHub with your use case.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input !== 'external' && input !== 'injected') {
|
|
|
|
|
throw_error(`css should be either "external" (default, recommended) or "injected"`);
|
|
|
|
|
}
|
|
|
|
|
if (input !== 'external' && input !== 'injected') {
|
|
|
|
|
throw_error(`css should be either "external" (default, recommended) or "injected"`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return input;
|
|
|
|
|
}),
|
|
|
|
|
return /** @type {'external' | 'injected'} */ (input);
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
cssHash: fun(({ css, filename, hash }) => {
|
|
|
|
|
return `svelte-${hash(filename === '(unknown)' ? css : filename ?? css)}`;
|
|
|
|
|
@ -77,7 +81,17 @@ const component_options = {
|
|
|
|
|
// TODO this is a sourcemap option, would be good to put under a sourcemap namespace
|
|
|
|
|
cssOutputFilename: string(undefined),
|
|
|
|
|
|
|
|
|
|
customElement: boolean(false),
|
|
|
|
|
/** @type {Validator<boolean | ((options: { filename: string }) => boolean), (options: { filename: string }) => boolean>} */
|
|
|
|
|
customElement: parametric(
|
|
|
|
|
/** @type {(options: { filename: string }) => boolean} */ (() => false),
|
|
|
|
|
(input, keypath) => {
|
|
|
|
|
if (typeof input !== 'boolean') {
|
|
|
|
|
throw_error(`${keypath} should be true or false`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return /** @type {boolean} */ (input);
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
discloseVersion: boolean(true),
|
|
|
|
|
|
|
|
|
|
@ -107,7 +121,8 @@ const component_options = {
|
|
|
|
|
|
|
|
|
|
preserveWhitespace: boolean(false),
|
|
|
|
|
|
|
|
|
|
runes: boolean(undefined),
|
|
|
|
|
/** @type {Validator<boolean | undefined | (() => boolean | undefined), () => boolean | undefined>} */
|
|
|
|
|
runes: parametric(() => /** @type {boolean | undefined} */ (undefined)),
|
|
|
|
|
|
|
|
|
|
hmr: boolean(false),
|
|
|
|
|
|
|
|
|
|
@ -318,6 +333,28 @@ function fun(fallback) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @template {(...args: any[]) => any} F
|
|
|
|
|
* @param {F} fallback
|
|
|
|
|
* @param {(value: unknown, keypath: string) => ReturnType<F>} [normalize]
|
|
|
|
|
* @returns {Validator}
|
|
|
|
|
*/
|
|
|
|
|
function parametric(fallback, normalize = (value) => /** @type {ReturnType<F>} */ (value)) {
|
|
|
|
|
return validator(fallback, (input, keypath) => {
|
|
|
|
|
if (typeof input === 'function') {
|
|
|
|
|
/** @type {(...args: Parameters<F>) => ReturnType<F>} */
|
|
|
|
|
const normalized = (...args) => normalize(input(...args), keypath);
|
|
|
|
|
|
|
|
|
|
return /** @type {F} */ (/** @type {unknown} */ (normalized));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @type {(...args: Parameters<F>) => ReturnType<F>} */
|
|
|
|
|
const normalized = (..._args) => normalize(input, keypath);
|
|
|
|
|
|
|
|
|
|
return /** @type {F} */ (/** @type {unknown} */ (normalized));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @param {string} msg */
|
|
|
|
|
function throw_error(msg) {
|
|
|
|
|
e.options_invalid_value(null, msg);
|
|
|
|
|
|