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

VSCode Organize Imports breaks when typing $props #2607

Open
coryvirok opened this issue Nov 27, 2024 · 0 comments
Open

VSCode Organize Imports breaks when typing $props #2607

coryvirok opened this issue Nov 27, 2024 · 0 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@coryvirok
Copy link

coryvirok commented Nov 27, 2024

Describe the bug

In certain situations, running VSCode's organize imports action will result in broken code.

E.g. Running organize imports on the following file produces broken code

<script lang="ts">
  import { page } from '$app/stores'

  let { foo }: { foo: string } = $props()
  console.log(foo, $page.url)
</script>

results in

<script lang="ts">
  import { page } from '$app/stores'
 { foo: string } = $props()
  console.log(foo, $page.url)
</script>

This does not happen if $props is typed using a type/interface:

<script lang="ts">
  import { page } from '$app/stores'

  interface Props {
    foo: string
  }

  let { foo }: Props = $props()
  console.log(foo, $page.url)
</script>

Nor does it happen if there are no imports.

Reproduction

<script lang="ts">
  import { page } from '$app/stores'

  let { foo }: { foo: string } = $props()
  console.log(foo, $page.url)
</script>

Expected behaviour

Unused imports are removed and the code is unmodified otherwise.

System Info

  • OS: MacOS
  • IDE: VSCode
  • Svelte for VSCode extension: v109.3.2

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

@coryvirok coryvirok added the bug Something isn't working label Nov 27, 2024
dummdidumm added a commit that referenced this issue Nov 29, 2024
...by adding a generated semicolon at the end. That prevents TypeScript from going up until the next semicolon it finds, which may be from another generated code, messing up the generated->original end position

#2608
#2607
dummdidumm added a commit that referenced this issue Nov 29, 2024
...by adding a generated semicolon at the end. That prevents TypeScript from going up until the next semicolon it finds, which may be from another generated code, messing up the generated->original end position

#2608
#2607
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Nov 29, 2024
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