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

Regression: reactive variables inside brackets raise an error #310

Closed
dkzlv opened this issue Jul 15, 2020 · 4 comments
Closed

Regression: reactive variables inside brackets raise an error #310

dkzlv opened this issue Jul 15, 2020 · 4 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@dkzlv
Copy link

dkzlv commented Jul 15, 2020

Describe the bug
Reactive variables appear to be unassigned to the compiler, if you define them in a reactive block with curly braces, both in template and in script tag.

To Reproduce

<script lang="ts">
  export let check: boolean;

  let derived: string;
  $: {
    derived = check.toString();
  }

  // Variable 'derived' is used before being assigned.
  console.log(derived.toUpperCase())
</script>

<!-- Variable 'derived' is used before being assigned. -->
{derived.toUpperCase()}

Expected behavior
Shouldn't report any errors here.

System (please complete the following information):
OS: Mac OS 10.15.3
IDE: VS Code
Plugin/Package: Svelte for VS Code (the new official one)

Additional context
Used to work a week ago. It works fine if you change the syntax to $: derived = ... without the brackets.
Also, svelte-check doesn't report any errors here.

@dkzlv dkzlv added the bug Something isn't working label Jul 15, 2020
@jasonlyu123
Copy link
Member

the one in the script is correct. I'll see what we can do about the one in the template

@dkzlv
Copy link
Author

dkzlv commented Jul 16, 2020

Same goes for other cases like this:

let sliceStart: number, sliceEnd: number;
$: [sliceStart, sliceEnd] = [page * limit, page * limit + limit];

It also says these two variables are used before assigning.

@jasonlyu123
Copy link
Member

jasonlyu123 commented Jul 16, 2020

This raises another problem

let d = 1;
$: a = d;
console.log(a)

The console.log(a) is used before declare because the compiler moves all the reactive to after no-reactive. So this should also show an error

https://svelte.dev/repl/1001568f2498473bbfb665129876259b?version=3.24.0

@jasonlyu123 jasonlyu123 added the Fixed Fixed in master branch. Pending production release. label Jul 29, 2020
@jasonlyu123
Copy link
Member

Let's track the used before declare in a separate issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

3 participants