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

organize-imports does not work when there is a module script block #221

Closed
PatrickG opened this issue Jun 22, 2020 · 3 comments
Closed

organize-imports does not work when there is a module script block #221

PatrickG opened this issue Jun 22, 2020 · 3 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@PatrickG
Copy link
Member

PatrickG commented Jun 22, 2020

Describe the bug
organize-imports does not work when there is a <script context="module"> block

To Reproduce

<script context="module">
  // do whatever
</script>

<script lang="ts">
  import B from './B';
  import A from './A';
</script>

Expected behavior
Imports should be organized in both script blocks.

@PatrickG PatrickG added the bug Something isn't working label Jun 22, 2020
dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Aug 14, 2020
sveltejs#221
```
<script context="module">
  import {c} from './c';
</script>

<script lang="ts">
  import B from './B';
  import A from './A';
</script>

<A>{c}</A>
```

---->

```
<script context="module">
  import A from './A';
  import { c } from './c';
  // do whatever
</script>

<script lang="ts">

</script>

<A>{c}</A>
```
dummdidumm added a commit that referenced this issue Aug 14, 2020
#221
```
<script context="module">
  import {c} from './c';
</script>

<script lang="ts">
  import B from './B';
  import A from './A';
</script>

<A>{c}</A>
```

---->

```
<script context="module">
  import A from './A';
  import { c } from './c';
</script>

<script lang="ts">

</script>

<A>{c}</A>
```
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Aug 14, 2020
@PatrickG
Copy link
Member Author

PatrickG commented Mar 10, 2021

I think the fix in #454 is not the best option.

When using functions - that are imported in the module script block - in reactive statements, svelte warns that the function is not reactive.
For example: "listen" is declared in a module script and will not be reactive.

The imports should stay in the script block in which they are defined, the imports should be sorted independent from each other.

I know the functions will not be reactive when imported in the regular script block, but the warning would be gone

@dummdidumm
Copy link
Member

This sounds more like inconsistent behavior in Svelte itself. Svelte should throw the warning in both cases since it's an import.

@PatrickG
Copy link
Member Author

You are right.

Related sveltejs/svelte#5847 sveltejs/svelte#5954

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

2 participants