Skip to content

Auto-import of component adds a new <script> tag if <script> is below markup #547

@ItalyPaleAle

Description

@ItalyPaleAle

Describe the bug
In my Svelte components, I put the <script> block after the markup. When I use the auto-import feature to import a new component, the language server adds a new <script> tag at the beginning of the file, which causes a compielr error.

To Reproduce

Start with this component:

<p>Hello World!</p>
<Foo />

<script>
import Foo from './Foo.svelte'
</script>

After <Foo /> type the name of another component not yet imported, such as <Bar then let auto-complete finish the import.

Expected behavior
This should appear:

<p>Hello World!</p>
<Foo />
<Bar />

<script>
import Foo from './Foo.svelte'
import Bar from './Bar.svelte'
</script>

Actual behavior

This appears instead (which causes a compiler error because you can't have more than 1 script tag):

<script>
import Bar from './Bar.svelte'
</script>

<p>Hello World!</p>
<Foo />
<Bar />

<script>
import Foo from './Foo.svelte'
</script>

System (please complete the following information):

  • OS: Linux
  • IDE: VS Code
  • Plugin/Package: svelte.svelte-vscode

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions