Skip to content

Commit bdc45fd

Browse files
breaking: rename legacy.componentApi to compatibility.componentApi (#12370)
* breaking: rename `legacy.componentApi` to `compatibility.legacyComponent` closes #12112 * fix * rename to compatibility.componentApi * update changeset * tidy up * default to 5 --------- Co-authored-by: Simon Holthausen <[email protected]>
1 parent 256e609 commit bdc45fd

File tree

14 files changed

+41
-30
lines changed

14 files changed

+41
-30
lines changed

.changeset/sour-tomatoes-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
breaking: rename `legacy.componentApi` to `compatibility.componentApi`

packages/svelte/messages/client-errors/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
## component_api_invalid_new
1818

19-
> Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `legacy.componentApi` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information
19+
> Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `compatibility.componentApi` compiler option to `4` to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information
2020
2121
## each_key_duplicate
2222

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export function analyze_component(root, source, options) {
383383
? true
384384
: (runes ? false : !!options.accessors) ||
385385
// because $set method needs accessors
386-
!!options.legacy?.componentApi,
386+
options.compatibility?.componentApi === 4,
387387
reactive_statements: new Map(),
388388
binding_groups: new Map(),
389389
slot_names: new Map(),

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export function client_component(source, analysis, options) {
283283
}
284284
}
285285

286-
if (options.legacy.componentApi) {
286+
if (options.compatibility.componentApi === 4) {
287287
component_returned_object.push(
288288
b.init('$set', b.id('$.update_legacy_props')),
289289
b.init(
@@ -474,7 +474,7 @@ export function client_component(source, analysis, options) {
474474
body.unshift(b.imports([], 'svelte/internal/disclose-version'));
475475
}
476476

477-
if (options.legacy.componentApi) {
477+
if (options.compatibility.componentApi === 4) {
478478
body.unshift(b.imports([['createClassComponent', '$$_createClassComponent']], 'svelte/legacy'));
479479
component_block.body.unshift(
480480
b.if(

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ export function server_component(analysis, options) {
21722172
should_inject_props ? [b.id('$$payload'), b.id('$$props')] : [b.id('$$payload')],
21732173
component_block
21742174
);
2175-
if (options.legacy.componentApi) {
2175+
if (options.compatibility.componentApi === 4) {
21762176
body.unshift(b.imports([['render', '$$_render']], 'svelte/server'));
21772177
body.push(
21782178
component_function,

packages/svelte/src/compiler/types/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ export interface CompileOptions extends ModuleCompileOptions {
141141
/**
142142
* @deprecated Use these only as a temporary solution before migrating your code
143143
*/
144-
legacy?: {
144+
compatibility?: {
145145
/**
146146
* Applies a transformation so that the default export of Svelte files can still be instantiated the same way as in Svelte 4 —
147147
* as a class when compiling for the browser (as though using `createClassComponent(MyComponent, {...})` from `svelte/legacy`)
148148
* or as an object with a `.render(...)` method when compiling for the server
149-
* @default false
149+
* @default 5
150150
*/
151-
componentApi?: boolean;
151+
componentApi?: 4 | 5;
152152
};
153153
/**
154154
* An initial sourcemap that will be merged into the final output sourcemap.
@@ -226,7 +226,7 @@ export type ValidatedCompileOptions = ValidatedModuleCompileOptions &
226226
Required<CompileOptions>,
227227
| keyof ModuleCompileOptions
228228
| 'name'
229-
| 'legacy'
229+
| 'compatibility'
230230
| 'outputFilename'
231231
| 'cssOutputFilename'
232232
| 'sourcemap'
@@ -236,7 +236,7 @@ export type ValidatedCompileOptions = ValidatedModuleCompileOptions &
236236
outputFilename: CompileOptions['outputFilename'];
237237
cssOutputFilename: CompileOptions['cssOutputFilename'];
238238
sourcemap: CompileOptions['sourcemap'];
239-
legacy: Required<Required<CompileOptions>['legacy']>;
239+
compatibility: Required<Required<CompileOptions>['compatibility']>;
240240
runes: CompileOptions['runes'];
241241
customElementOptions: SvelteOptions['customElement'];
242242
hmr: CompileOptions['hmr'];

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ export const validate_component_options =
7878

7979
immutable: deprecate(w.options_deprecated_immutable, boolean(false)),
8080

81-
legacy: object({
82-
componentApi: boolean(false)
81+
legacy: removed(
82+
'The legacy option has been removed. If you are using this because of legacy.componentApi, use compatibility.componentApi instead'
83+
),
84+
85+
compatibility: object({
86+
componentApi: list([4, 5], 5)
8387
}),
8488

8589
loopGuardTimeout: warn_removed(w.options_removed_loop_guard_timeout),

packages/svelte/src/internal/client/dom/legacy/misc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function bubble_event($$props, event) {
4141
}
4242

4343
/**
44-
* Used to simulate `$on` on a component instance when `legacy.componentApi` is `true`
44+
* Used to simulate `$on` on a component instance when `compatibility.componentApi === 4`
4545
* @param {Record<string, any>} $$props
4646
* @param {string} event_name
4747
* @param {Function} event_callback
@@ -53,7 +53,7 @@ export function add_legacy_event_listener($$props, event_name, event_callback) {
5353
}
5454

5555
/**
56-
* Used to simulate `$set` on a component instance when `legacy.componentApi` is `true`.
56+
* Used to simulate `$set` on a component instance when `compatibility.componentApi === 4`.
5757
* Needs component accessors so that it can call the setter of the prop. Therefore doesn't
5858
* work for updating props in `$$props` or `$$restProps`.
5959
* @this {Record<string, any>}

packages/svelte/src/internal/client/errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ export function component_api_changed(parent, method, component) {
7676
}
7777

7878
/**
79-
* Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `legacy.componentApi` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information
79+
* Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `compatibility.componentApi` compiler option to `4` to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information
8080
* @param {string} component
8181
* @param {string} name
8282
* @returns {never}
8383
*/
8484
export function component_api_invalid_new(component, name) {
8585
if (DEV) {
86-
const error = new Error(`component_api_invalid_new\nAttempted to instantiate ${component} with \`new ${name}\`, which is no longer valid in Svelte 5. If this component is not under your control, set the \`legacy.componentApi\` compiler option to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information`);
86+
const error = new Error(`component_api_invalid_new\nAttempted to instantiate ${component} with \`new ${name}\`, which is no longer valid in Svelte 5. If this component is not under your control, set the \`compatibility.componentApi\` compiler option to \`4\` to keep it working. See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information`);
8787

8888
error.name = 'Svelte error';
8989
throw error;

packages/svelte/tests/runtime-legacy/samples/binding-this-legacy-component-api/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { test } from '../../test';
33

44
export default test({
55
compileOptions: {
6-
legacy: {
7-
componentApi: true
6+
compatibility: {
7+
componentApi: 4
88
}
99
},
1010
html: '<button>0</button>',

0 commit comments

Comments
 (0)