Skip to content

Commit f95c709

Browse files
committed
future-proof
1 parent 2c11ee3 commit f95c709

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

packages/svelte/src/compiler/migrate/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import { regex_is_valid_identifier } from '../phases/patterns.js';
1010

1111
/**
1212
* Does a best-effort migration of Svelte code towards using runes, event attributes and render tags.
13+
* May throw an error if the code is too complex to migrate automatically.
14+
*
1315
* @param {string} source
14-
* @returns {string}
16+
* @returns {{ code: string; }}
1517
*/
1618
export function migrate(source) {
1719
try {
@@ -145,7 +147,7 @@ export function migrate(source) {
145147
}
146148
}
147149

148-
return str.toString();
150+
return { code: str.toString() };
149151
} catch (e) {
150152
// eslint-disable-next-line no-console
151153
console.error('Error while migrating Svelte code');

packages/svelte/types/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,12 @@ declare module 'svelte/compiler' {
10881088
export const VERSION: string;
10891089
/**
10901090
* Does a best-effort migration of Svelte code towards using runes, event attributes and render tags.
1091+
* May throw an error if the code is too complex to migrate automatically.
1092+
*
10911093
* */
1092-
export function migrate(source: string): string;
1094+
export function migrate(source: string): {
1095+
code: string;
1096+
};
10931097
class Scope {
10941098

10951099
constructor(root: ScopeRoot, parent: Scope | null, porous: boolean);

sites/svelte-5-preview/src/lib/Repl.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
if (file.name === $selected?.name) {
171171
return {
172172
...file,
173-
source: result.source
173+
source: result.result.code
174174
};
175175
}
176176
return file;

sites/svelte-5-preview/src/lib/workers/compiler/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ function compile({ id, source, options, return_ast }) {
136136
/** @param {import("../workers").MigrateMessageData} param0 */
137137
function migrate({ id, source }) {
138138
try {
139-
source = svelte.migrate(source);
139+
const result = svelte.migrate(source);
140140

141141
return {
142142
id,
143-
source
143+
result
144144
};
145145
} catch (err) {
146146
// @ts-ignore
147147
let message = `/*\nError migrating ${err.filename ?? 'component'}:\n${err.message}\n*/`;
148148

149149
return {
150150
id,
151-
source,
151+
result: { code: source },
152152
error: message
153153
};
154154
}

sites/svelte-5-preview/src/lib/workers/workers.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ export type BundleMessageData = {
2929

3030
export type MigrateMessageData = {
3131
id: number;
32-
source: string;
32+
result: { code: string };
3333
error?: string;
3434
};

0 commit comments

Comments
 (0)