@const can be inside an if block as well
See original GitHub issueDescribe the bug
Since Svelte 3.48 @const
is allowed to be inside an #if
as well, the extension however still complains about this.
Reproduction
{#if true}
{@const test = 123}
{/if}
Expected behaviour
Code above is not marked as an error.
System Info
- OS: [Windows]
- IDE: [VSCode]
- Svelte for Vs Code: [v105.16.0]
Which package is the issue about?
Svelte for VS Code
Additional Information, eg. Screenshots
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Use if else to declare a `let` or `const` to use after the if/else?
let and const are block level scoped meaning they can only be used within the block they have been defined in ie. {...
Read more >const - JavaScript - MDN Web Docs - Mozilla
The const declaration creates block-scoped constants, much like variables declared using the let keyword. The value of a constant can't be ...
Read more >Implementing {@const} in if block - YouTube
Your browser can 't play this video. ... Implementing {@ const } in if block Walkthrough of my thought process and approach.
Read more >How the let, const, and var Keywords Work in JavaScript
In JavaScript, we use scope as a way to identify where and whether we can use a variable. The variables may exist within...
Read more >Allow @const inside an if block #7241 - sveltejs/svelte - GitHub
I want to make a {@const a = b} declaration inside an {#if cond} block, but svelte complains about it's parent.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We might need some time with this one. It’s tricky to implement this into the svelte2tsx transformation for type check.
I have some ideas about how to do this in the old transformation but haven’t finished it yet. I can add a PR later. Don’t have to wait for it though I also think we can get the new transformation supported first.