Skip to content

fix: Keep inlined JSDoc comments in property conversion of svelte-migrate #15567

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

Merged
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/happy-cameras-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

Keep inlined trailing JSDoc comments of properties when running svelte-migrate
7 changes: 5 additions & 2 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,6 @@ function extract_type_and_comment(declarator, state, path) {
const comment_start = /** @type {any} */ (comment_node)?.start;
const comment_end = /** @type {any} */ (comment_node)?.end;
let comment = comment_node && str.original.substring(comment_start, comment_end);

if (comment_node) {
str.update(comment_start, comment_end, '');
}
Expand Down Expand Up @@ -1673,6 +1672,11 @@ function extract_type_and_comment(declarator, state, path) {
state.has_type_or_fallback = true;
const match = /@type {(.+)}/.exec(comment_node.value);
if (match) {
// try to find JSDoc comments after a hyphen `-`
const jsdocComment = /@type {.+} (?:\w+|\[.*?\]) - (.+)/.exec(comment_node.value);
if (jsdocComment) {
cleaned_comment += jsdocComment[1]?.trim();
}
return {
type: match[1],
comment: cleaned_comment,
Expand All @@ -1693,7 +1697,6 @@ function extract_type_and_comment(declarator, state, path) {
};
}
}

return {
type: 'any',
comment: state.uses_ts ? comment : cleaned_comment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
export let type_no_comment;

/** @type {boolean} type_with_comment - One-line declaration with comment */
export let type_with_comment;

/**
* This is optional
*/
Expand All @@ -40,4 +43,10 @@
export let inline_multiline_trailing_comment = 'world'; /*
* this is a same-line trailing multiline comment
**/

/** @type {number} [default_value=1] */
export let default_value = 1;

/** @type {number} [comment_default_value=1] - This has a comment and an optional value. */
export let comment_default_value = 1;
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,33 @@















/**
* @typedef {Object} Props
* @property {string} comment - My wonderful comment
* @property {number} another_comment - My wonderful other comment
* @property {any} one_line - one line comment
* @property {any} no_comment
* @property {boolean} type_no_comment
* @property {boolean} type_with_comment - One-line declaration with comment
* @property {any} [optional] - This is optional
* @property {any} inline_commented - this should stay a comment
* @property {any} inline_commented_merged - This comment should be merged - with this inline comment
* @property {string} [inline_multiline_leading_comment] - this is a same-line leading multiline comment
* @property {string} [inline_multiline_trailing_comment] - this is a same-line trailing multiline comment
* @property {number} [default_value]
* @property {number} [comment_default_value] - This has a comment and an optional value.
*/

/** @type {Props} */
Expand All @@ -36,10 +45,13 @@
one_line,
no_comment,
type_no_comment,
type_with_comment,
optional = {stuff: true},
inline_commented,
inline_commented_merged,
inline_multiline_leading_comment = 'world',
inline_multiline_trailing_comment = 'world'
inline_multiline_trailing_comment = 'world',
default_value = 1,
comment_default_value = 1
} = $props();
</script>