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

[fix] warning on reactive use of module const (#6606) #6607

Merged
merged 2 commits into from
Aug 3, 2021

Conversation

OJFord
Copy link
Contributor

@OJFord OJFord commented Aug 1, 2021

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with [feat], [fix], [chore], or [docs].
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

NB there are two warnings, but I also see them on master:

[...]/svelte/src/compiler/compile/create_module.ts
  100:3   warning  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion
  100:36  warning  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion

Fixes #6606.

This generated a warning:

<script context="module">
  export const foo = 123;
</script>

<script>
  $: console.log(foo);
</script>

while this did not:

<script>
  const foo = 123;
  $: console.log(foo);
</script>

We don't need a warning to tell us that we will not be reactive to a
variable that isn't going to change anyway; regardless of whether or not
it's in a module.

(Maybe there should be a 'no reactive variable used' warning, but this
also happens in cases where other mutable variables are used; such as a
shared const formatter function, formatting a prop.)

This generated a warning:

    <script context="module">
      export const foo = 123;
    </script>

    <script>
      $: console.log(foo);
    </script>

while this did not:

    <script>
      const foo = 123;
      $: console.log(foo);
    </script>

We don't need a warning to tell us that we will not be reactive to a
variable that isn't going to change anyway; regardless of whether or not
it's in a module.

(Maybe there should be a 'no reactive variable used' warning, but this
also happens in cases where other mutable variables are used; such as a
shared const formatter function, formatting a prop.)
@OJFord OJFord changed the title [fix] #6606: warning on reactive use of module const [fix] warning on reactive use of module const (#6606) Aug 1, 2021
@Conduitry Conduitry merged commit f482399 into sveltejs:master Aug 3, 2021
@OJFord
Copy link
Contributor Author

OJFord commented Aug 4, 2021

Thanks!

@OJFord OJFord deleted the fix-6606 branch August 4, 2021 01:46
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.

{some const} is declared in a module script and will not be reactive
4 participants