Skip to content
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

How to handle reusing variable in different if blocks #1310

Open
TwitchBronBron opened this issue Sep 28, 2024 · 0 comments
Open

How to handle reusing variable in different if blocks #1310

TwitchBronBron opened this issue Sep 28, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@TwitchBronBron
Copy link
Member

TwitchBronBron commented Sep 28, 2024

I noticed a few spots in the jellyfin-roku app that they reuse the same variable name multiple times. In typescript this is not a big deal because let and const variables are block-scoped, so they'd only exist inside the if block. But in brs/bs, all variables exist at the function level.

Not sure how difficult this would be without implementing full-blown branch tracking, but perhaps we could do some specific logic to this exact use case: when a variable is defined, and there's very clear code following it. Like everything in the same block after the declaration would know it's just that one type.

image

Perhaps this might even be easier to just enable a bsconfig flag for enforcing block-scoped variables.

Anyway, just wanted to track this so we could have a conversation. There are several valid use cases where we just want to reuse the same variable name because it's temporary, but we don't want to lose the typing with it as it flows down the file.

@TwitchBronBron TwitchBronBron added the enhancement New feature or request label Sep 28, 2024
@TwitchBronBron TwitchBronBron added this to the v1.1.0 milestone Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant