Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fix error placement on (arrow) function when checking load input #5840

Merged
merged 1 commit into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-masks-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-migrate': patch
---

Fix error placement on (arrow) function when checking load input
4 changes: 2 additions & 2 deletions packages/migrate/migrations/routes/migrate_page_js/samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
```
10 changes: 5 additions & 5 deletions packages/migrate/migrations/routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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 = '';
Expand Down