diff --git a/.changeset/red-masks-confess.md b/.changeset/red-masks-confess.md new file mode 100644 index 000000000000..b17e3ee00d93 --- /dev/null +++ b/.changeset/red-masks-confess.md @@ -0,0 +1,5 @@ +--- +'svelte-migrate': patch +--- + +Fix error placement on (arrow) function when checking load input diff --git a/packages/migrate/migrations/routes/migrate_page_js/samples.md b/packages/migrate/migrations/routes/migrate_page_js/samples.md index 95980cc70a16..697b9a62834a 100644 --- a/packages/migrate/migrations/routes/migrate_page_js/samples.md +++ b/packages/migrate/migrations/routes/migrate_page_js/samples.md @@ -269,14 +269,14 @@ export async function load({ stuff }) { ## Bails on non-destructured param ```js before -export async function load(input) { +export const load = (input) => { return {}; } ``` ```js after throw new Error("@migration task: Check if you need to migrate the load function input (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693)"); -export async function load(input) { +export const load = (input) => { return {}; } ``` diff --git a/packages/migrate/migrations/routes/utils.js b/packages/migrate/migrations/routes/utils.js index e8ae2f9eb0b5..c774cb999cdf 100644 --- a/packages/migrate/migrations/routes/utils.js +++ b/packages/migrate/migrations/routes/utils.js @@ -203,11 +203,6 @@ export function indent_at_line(content, offset) { * @param {string} [suggestion] */ export function manual_return_migration(node, str, comment_nr, suggestion) { - // handle case where this is called on a (arrow) function - if (ts.isFunctionExpression(node) || ts.isArrowFunction(node)) { - node = node.parent.parent.parent; - } - manual_migration(node, str, 'Migrate this return statement', comment_nr, suggestion); } @@ -219,6 +214,11 @@ export function manual_return_migration(node, str, comment_nr, suggestion) { * @param {string} [suggestion] */ export function manual_migration(node, str, message, comment_nr, suggestion) { + // handle case where this is called on a (arrow) function + if (ts.isFunctionExpression(node) || ts.isArrowFunction(node)) { + node = node.parent.parent.parent; + } + const indent = indent_at_line(str.original, node.getStart()); let appended = '';