-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the bug
A common pattern if you are building a large application with svelte is to document you props with JSDoc or at least with comment.
Currently the migration script falls a bit short for this very common situation:
<script>
/**
* My wonderful comment
* @type {string}
*/
export let comment;
/**
* My wonderful other comment
* @type {number}
*/
export let another_comment;
</script>is converted into
<script>
/** @type {{comment: string, another_comment: number}} */
let { comment, another_comment } = $props();
</script>And just like that all time spent into writing documentation for your props is trashed.
The situation is a bit worst if the comment is a line comment
<script>
// pay attention to this
export let comment;
let totally_innocuous_state = 0;
/**
* My wonderful other comment
*/
export let another_comment;
</script>is converted into this
<script>
// pay attention to this
let totally_innocuous_state = 0;
/** @type {{comment: any, another_comment: any}} */
let { comment, another_comment } = $props();
</script>i thought of moving all the comments related to props above the props but that could be just confusing. But what if we use another approach.
This also works in JSDoc
<script>
/**
* @typedef {Object} Props
* @property {string} comment - My wonderful comment
* @property {string} another_comment - My wonderful other comment
*/
/** @type {Props} */
let { comment, another_comment } = $props();
</script>and we could even move the lines comments there (even tho it's not exactly right i would be less pissed to have a line comment in the JSDoc that have it lingering around the file)
Do you think is worth?
Reproduction
Logs
No response
System Info
replSeverity
annoyance