question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@const can be inside an if block as well

See original GitHub issue

Describe the bug

Since Svelte 3.48 @const is allowed to be inside an #if as well, the extension however still complains about this.

image

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:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonlyu123commented, May 3, 2022

We might need some time with this one. It’s tricky to implement this into the svelte2tsx transformation for type check.

0reactions
jasonlyu123commented, May 7, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found