Repository: sveltejs/svelte (JavaScript) — Bug Fix

Issue:
{some const} is declared in a module script and will not be reactive
### Describe the bug

#5847 added a warning when module variables are used reactively in non-module script.

This warning is triggered even if the variable is `const`. (And used reactively together with non-const variables, presumably!)

### Reproduction

```svelte
<script context="module">
export const doFoos = (a, b, c) => [a, b, c];
export const foo = 123;
</script>

<script>
export let bar;

$: foobar = doFoos(foo, bar, null);
</script>
```

### Logs

```shell
(!) Plugin svelte: "doFoos" is declared in a module script and will not be reactive
(!) Plugin svelte: "foo" is declared in a module script and will not be reactive
```


### System Info

```shell
System:
    OS: Linux 5.13 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz
    Memory: 4.66 GB / 15.56 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.6.0 - /usr/bin/node
    Yarn: 1.22.11 - /usr/bin/yarn
    npm: 7.20.3 - /usr/bin/npm
  Browsers:
    Firefox: 90.0.2
```


### Severity

annoyance
{some const} is declared in a module script and will not be reactive
### Describe the bug

#5847 added a warning when module variables are used reactively in non-module script.

This warning is triggered even if the variable is `const`. (And used reactively together with non-const variables, presumably!)

### Reproduction

```svelte
<script context="module">
export const doFoos = (a, b, c) => [a, b, c];
export const foo = 123;
</script>

<script>
export let bar;

$: foobar = doFoos(foo, bar, null);
</script>
```

### Logs

```shell
(!) Plugin svelte: "doFoos" is declared in a module script and will not be reactive
(!) Plugin svelte: "foo" is declared in a module script and will not be reactive
```


### System Info

```shell
System:
    OS: Linux 5.13 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz
    Memory: 4.66 GB / 15.56 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.6.0 - /usr/bin/node
    Yarn: 1.22.11 - /usr/bin/yarn
    npm: 7.20.3 - /usr/bin/npm
  Browsers:
    Firefox: 90.0.2
```


### Severity

annoyance


Discussion:

Resolving patch:
diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts
--- a/src/compiler/compile/Component.ts
+++ b/src/compiler/compile/Component.ts
@@ -1310,7 +1310,7 @@ export default class Component {
 
 								if (variable) {
 									variable.is_reactive_dependency = true;
-									if (variable.module) {
+									if (variable.module && variable.writable) {
 										should_add_as_dependency = false;
 										module_dependencies.add(name);
 									}


Test patch:
diff --git a/test/validator/samples/reactive-module-const-variable/input.svelte b/test/validator/samples/reactive-module-const-variable/input.svelte
new file mode 100644
--- /dev/null
+++ b/test/validator/samples/reactive-module-const-variable/input.svelte
@@ -0,0 +1,9 @@
+<script context="module">
+	export const foo = 123;
+	export const doFoo = (foo) => foo;
+</script>
+
+<script>
+	$: bar = foo;
+	$: doFoo(bar);
+</script>
diff --git a/test/validator/samples/reactive-module-const-variable/warnings.json b/test/validator/samples/reactive-module-const-variable/warnings.json
new file mode 100644
--- /dev/null
+++ b/test/validator/samples/reactive-module-const-variable/warnings.json
@@ -0,0 +1,2 @@
+[
+]