Skip to content

Commit

Permalink
[fix] Migrate type comments on arrow functions (#5933)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Aug 16, 2022
1 parent 7f51caf commit f950398
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-crews-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-migrate': patch
---

Migrate type comments on arrow functions
2 changes: 2 additions & 0 deletions packages/migrate/migrations/routes/migrate_page_js/samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export function load() {
## Arrow function load
```js before
/** @type {import('./$types').Load} */
export const load = () => ({
props: {
a: 1
Expand All @@ -199,6 +200,7 @@ export const load = () => ({
```
```js after
/** @type {import('./$types').PageLoad} */
export const load = () => ({
a: 1
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function load() {
## Arrow function GET

```js before
/** @type {import('./$types').RequestHandler} */
export const GET = () => ({
body: {
a: 1
Expand All @@ -100,6 +101,7 @@ export const GET = () => ({
```

```js after
/** @type {import('./$types').PageServerLoad} */
export const load = () => ({
a: 1
});
Expand Down
5 changes: 3 additions & 2 deletions packages/migrate/migrations/routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,10 @@ export function read_samples(test_file) {
*/
export function rewrite_type(node, code, old_type, new_type) {
// @ts-ignore
if (node.jsDoc) {
let jsDoc = node.jsDoc || node.parent?.parent?.parent?.jsDoc;
if (jsDoc) {
// @ts-ignore
for (const comment of node.jsDoc) {
for (const comment of jsDoc) {
const str = comment.getText();
const index = str.indexOf(old_type);

Expand Down

0 comments on commit f950398

Please sign in to comment.