Skip to content

fix: properly transform $props.id when $props is assigned to props #2694

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 2 commits into from
Feb 25, 2025

Conversation

paoloricciuti
Copy link
Member

This is a bit of weird one and I'm not sure there's a better way to handle this. The problem is that when you are doing this

<script>
    let props = $props();
    let id = $props.id();
</script>

the second $props identifier was not considered a rune because it's not an immediate function call. There's a catch tho: even if we check that the parent is a call expression and the text is $props.id we can't rule that out immediately because it depends if the props variable comes from the assignment of $props() or not. But the scope we have here is far less powerful than the one in the svelte compiler. So i had to do this weird dance where i still add the possible store in the array but i also save the fact that comes from $props.id...then while walking if i encounter an identifier props which is in a variable declaration i check if the variable declaration initializer is $props().

It should cover all the edge cases but it's a bit convoluted. Also i would've loved to add some comments here and there but everytime i open that file my vscode crashes 😳

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah the store autosubscription syntax really bites us there 😅

@dummdidumm dummdidumm merged commit c942382 into sveltejs:master Feb 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants