Skip to content

Commit 7cc4d56

Browse files
authored
feat: ignore component options in compileModule (#16362)
1 parent c785178 commit 7cc4d56

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)
@@ -48,110 +48,120 @@ const common = {
4848
})
4949
};
5050

51-
export const validate_module_options =
52-
/** @type {Validator<ModuleCompileOptions, ValidatedModuleCompileOptions>} */ (
53-
object({
54-
...common
55-
})
56-
);
51+
const component_options = {
52+
accessors: deprecate(w.options_deprecated_accessors, boolean(false)),
5753

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

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

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

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

81-
return input;
82-
}),
84+
immutable: deprecate(w.options_deprecated_immutable, boolean(false)),
8385

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

88-
// TODO this is a sourcemap option, would be good to put under a sourcemap namespace
89-
cssOutputFilename: string(undefined),
98+
namespace: list(['html', 'mathml', 'svg']),
9099

91-
customElement: boolean(false),
100+
modernAst: boolean(false),
92101

93-
discloseVersion: boolean(true),
102+
outputFilename: string(undefined),
94103

95-
immutable: deprecate(w.options_deprecated_immutable, boolean(false)),
104+
preserveComments: boolean(false),
96105

97-
legacy: removed(
98-
'The legacy option has been removed. If you are using this because of legacy.componentApi, use compatibility.componentApi instead'
99-
),
106+
fragments: list(['html', 'tree']),
100107

101-
compatibility: object({
102-
componentApi: list([4, 5], 5)
103-
}),
108+
preserveWhitespace: boolean(false),
104109

105-
loopGuardTimeout: warn_removed(w.options_removed_loop_guard_timeout),
110+
runes: boolean(undefined),
106111

107-
name: string(undefined),
112+
hmr: boolean(false),
108113

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

111-
modernAst: boolean(false),
120+
enableSourcemap: warn_removed(w.options_removed_enable_sourcemap),
112121

113-
outputFilename: string(undefined),
122+
hydratable: warn_removed(w.options_removed_hydratable),
114123

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

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

119-
preserveWhitespace: boolean(false),
134+
sveltePath: removed(
135+
'The sveltePath option has been removed in Svelte 5. ' +
136+
'If this option was crucial for you, please open an issue on GitHub with your use case.'
137+
),
120138

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

123-
hmr: boolean(false),
146+
varsReport: removed(
147+
'The vars option has been removed. If you are using this through svelte-preprocess with TypeScript, ' +
148+
'use the https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax setting instead'
149+
)
150+
};
124151

125-
sourcemap: validator(undefined, (input) => {
126-
// Source maps can take on a variety of values, including string, JSON, map objects from magic-string and source-map,
127-
// so there's no good way to check type validity here
128-
return input;
129-
}),
152+
export const validate_module_options =
153+
/** @type {Validator<ModuleCompileOptions, ValidatedModuleCompileOptions>} */ (
154+
object({
155+
...common_options,
156+
...Object.fromEntries(Object.keys(component_options).map((key) => [key, () => {}]))
157+
})
158+
);
130159

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

0 commit comments

Comments
 (0)