Skip to content

Migrate: comments on props are either detached or deleted #13631

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

Closed
paoloricciuti opened this issue Oct 16, 2024 · 1 comment · Fixed by #13698
Closed

Migrate: comments on props are either detached or deleted #13631

paoloricciuti opened this issue Oct 16, 2024 · 1 comment · Fixed by #13698
Labels

Comments

@paoloricciuti
Copy link
Member

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

REPL

Logs

No response

System Info

repl

Severity

annoyance

@benmccann
Copy link
Member

Yes, I agree with making a typedef and moving the comments there. Current situation seems quite bad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants