Skip to content

Commit d98bc00

Browse files
committed
feat: ignore component options in compileModule
1 parent 3f3cf9f commit d98bc00

File tree

2 files changed

+96
-81
lines changed

2 files changed

+96
-81
lines changed

.changeset/violet-ways-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': minor
3+
---
4+
5+
feat: ignore component options in `compileModule`

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

Lines changed: 91 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as w from './warnings.js';
88
* @typedef {(input: Input, keypath: string) => Required<Output>} Validator
99
*/
1010

11-
const common = {
11+
const common_options = {
1212
filename: string('(unknown)'),
1313

1414
// default to process.cwd() where it exists to replicate svelte4 behavior (and make Deno work with this as well)
@@ -44,110 +44,120 @@ const common = {
4444
warningFilter: fun(() => true)
4545
};
4646

47-
export const validate_module_options =
48-
/** @type {Validator<ModuleCompileOptions, ValidatedModuleCompileOptions>} */ (
49-
object({
50-
...common
51-
})
52-
);
47+
const component_options = {
48+
accessors: deprecate(w.options_deprecated_accessors, boolean(false)),
5349

54-
export const validate_component_options =
55-
/** @type {Validator<CompileOptions, ValidatedCompileOptions>} */ (
56-
object({
57-
...common,
50+
css: validator('external', (input) => {
51+
if (input === true || input === false) {
52+
throw_error(
53+
'The boolean options have been removed from the css option. Use "external" instead of false and "injected" instead of true'
54+
);
55+
}
56+
if (input === 'none') {
57+
throw_error(
58+
'css: "none" is no longer a valid option. If this was crucial for you, please open an issue on GitHub with your use case.'
59+
);
60+
}
5861

59-
accessors: deprecate(w.options_deprecated_accessors, boolean(false)),
62+
if (input !== 'external' && input !== 'injected') {
63+
throw_error(`css should be either "external" (default, recommended) or "injected"`);
64+
}
6065

61-
css: validator('external', (input) => {
62-
if (input === true || input === false) {
63-
throw_error(
64-
'The boolean options have been removed from the css option. Use "external" instead of false and "injected" instead of true'
65-
);
66-
}
67-
if (input === 'none') {
68-
throw_error(
69-
'css: "none" is no longer a valid option. If this was crucial for you, please open an issue on GitHub with your use case.'
70-
);
71-
}
66+
return input;
67+
}),
7268

73-
if (input !== 'external' && input !== 'injected') {
74-
throw_error(`css should be either "external" (default, recommended) or "injected"`);
75-
}
69+
cssHash: fun(({ css, hash }) => {
70+
return `svelte-${hash(css)}`;
71+
}),
72+
73+
// TODO this is a sourcemap option, would be good to put under a sourcemap namespace
74+
cssOutputFilename: string(undefined),
75+
76+
customElement: boolean(false),
77+
78+
discloseVersion: boolean(true),
7679

77-
return input;
78-
}),
80+
immutable: deprecate(w.options_deprecated_immutable, boolean(false)),
7981

80-
cssHash: fun(({ css, hash }) => {
81-
return `svelte-${hash(css)}`;
82-
}),
82+
legacy: removed(
83+
'The legacy option has been removed. If you are using this because of legacy.componentApi, use compatibility.componentApi instead'
84+
),
85+
86+
compatibility: object({
87+
componentApi: list([4, 5], 5)
88+
}),
89+
90+
loopGuardTimeout: warn_removed(w.options_removed_loop_guard_timeout),
91+
92+
name: string(undefined),
8393

84-
// TODO this is a sourcemap option, would be good to put under a sourcemap namespace
85-
cssOutputFilename: string(undefined),
94+
namespace: list(['html', 'mathml', 'svg']),
8695

87-
customElement: boolean(false),
96+
modernAst: boolean(false),
8897

89-
discloseVersion: boolean(true),
98+
outputFilename: string(undefined),
9099

91-
immutable: deprecate(w.options_deprecated_immutable, boolean(false)),
100+
preserveComments: boolean(false),
92101

93-
legacy: removed(
94-
'The legacy option has been removed. If you are using this because of legacy.componentApi, use compatibility.componentApi instead'
95-
),
102+
fragments: list(['html', 'tree']),
96103

97-
compatibility: object({
98-
componentApi: list([4, 5], 5)
99-
}),
104+
preserveWhitespace: boolean(false),
100105

101-
loopGuardTimeout: warn_removed(w.options_removed_loop_guard_timeout),
106+
runes: boolean(undefined),
102107

103-
name: string(undefined),
108+
hmr: boolean(false),
104109

105-
namespace: list(['html', 'mathml', 'svg']),
110+
sourcemap: validator(undefined, (input) => {
111+
// Source maps can take on a variety of values, including string, JSON, map objects from magic-string and source-map,
112+
// so there's no good way to check type validity here
113+
return input;
114+
}),
106115

107-
modernAst: boolean(false),
116+
enableSourcemap: warn_removed(w.options_removed_enable_sourcemap),
108117

109-
outputFilename: string(undefined),
118+
hydratable: warn_removed(w.options_removed_hydratable),
110119

111-
preserveComments: boolean(false),
120+
format: removed(
121+
'The format option has been removed in Svelte 4, the compiler only outputs ESM now. Remove "format" from your compiler options. ' +
122+
'If you did not set this yourself, bump the version of your bundler plugin (vite-plugin-svelte/rollup-plugin-svelte/svelte-loader)'
123+
),
112124

113-
fragments: list(['html', 'tree']),
125+
tag: removed(
126+
'The tag option has been removed in Svelte 5. Use `<svelte:options customElement="tag-name" />` inside the component instead. ' +
127+
'If that does not solve your use case, please open an issue on GitHub with details.'
128+
),
114129

115-
preserveWhitespace: boolean(false),
130+
sveltePath: removed(
131+
'The sveltePath option has been removed in Svelte 5. ' +
132+
'If this option was crucial for you, please open an issue on GitHub with your use case.'
133+
),
116134

117-
runes: boolean(undefined),
135+
// These two were primarily created for svelte-preprocess (https://github.com/sveltejs/svelte/pull/6194),
136+
// but with new TypeScript compilation modes strictly separating types it's not necessary anymore
137+
errorMode: removed(
138+
'The errorMode option has been removed. If you are using this through svelte-preprocess with TypeScript, ' +
139+
'use the https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax setting instead'
140+
),
118141

119-
hmr: boolean(false),
142+
varsReport: removed(
143+
'The vars option has been removed. If you are using this through svelte-preprocess with TypeScript, ' +
144+
'use the https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax setting instead'
145+
)
146+
};
120147

121-
sourcemap: validator(undefined, (input) => {
122-
// Source maps can take on a variety of values, including string, JSON, map objects from magic-string and source-map,
123-
// so there's no good way to check type validity here
124-
return input;
125-
}),
148+
export const validate_module_options =
149+
/** @type {Validator<ModuleCompileOptions, ValidatedModuleCompileOptions>} */ (
150+
object({
151+
...common_options,
152+
...Object.fromEntries(Object.keys(component_options).map((key) => [key, () => {}]))
153+
})
154+
);
126155

127-
enableSourcemap: warn_removed(w.options_removed_enable_sourcemap),
128-
hydratable: warn_removed(w.options_removed_hydratable),
129-
format: removed(
130-
'The format option has been removed in Svelte 4, the compiler only outputs ESM now. Remove "format" from your compiler options. ' +
131-
'If you did not set this yourself, bump the version of your bundler plugin (vite-plugin-svelte/rollup-plugin-svelte/svelte-loader)'
132-
),
133-
tag: removed(
134-
'The tag option has been removed in Svelte 5. Use `<svelte:options customElement="tag-name" />` inside the component instead. ' +
135-
'If that does not solve your use case, please open an issue on GitHub with details.'
136-
),
137-
sveltePath: removed(
138-
'The sveltePath option has been removed in Svelte 5. ' +
139-
'If this option was crucial for you, please open an issue on GitHub with your use case.'
140-
),
141-
// These two were primarily created for svelte-preprocess (https://github.com/sveltejs/svelte/pull/6194),
142-
// but with new TypeScript compilation modes strictly separating types it's not necessary anymore
143-
errorMode: removed(
144-
'The errorMode option has been removed. If you are using this through svelte-preprocess with TypeScript, ' +
145-
'use the https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax setting instead'
146-
),
147-
varsReport: removed(
148-
'The vars option has been removed. If you are using this through svelte-preprocess with TypeScript, ' +
149-
'use the https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax setting instead'
150-
)
156+
export const validate_component_options =
157+
/** @type {Validator<CompileOptions, ValidatedCompileOptions>} */ (
158+
object({
159+
...common_options,
160+
...component_options
151161
})
152162
);
153163

0 commit comments

Comments
 (0)