Skip to content

TypeScript with importHelpers may throw errors when instance and module script present #373

Open
@dummdidumm

Description

@dummdidumm

Describe the bug
When using TypeScript and setting the tsconfig setting importHelpers to true, TypeScript will not inline transpilation helpers and instead import them from tslib. Since the instance and module script are transpiled independently, these imports may get duplicated which results in a "X was already declared" error.

This came up in sveltejs/kit#1577

To Reproduce
tsconfig:

// ...
"importHelpers": true,
"target": "es2019"
// ...

Svelte file:

<script lang="ts" context="module">
  export async function foo() {}
</script>

<script lang="ts" context="module">
  export async function bar() {}
</script>

Expected behavior
Imports are deduplicated somehow. Since this is a special case I think it's okay to have special code for it. For example doing a regex for check for tslib imports, store them somewhere and filter out duplicated imports in the next transformation.

Information about your project:

  • Your browser and the version: irrelevant

  • Your operating system: irrelevant

  • svelte-preprocess version 4.7.3

  • Whether your project uses Webpack or Rollup: Rollup/Vite

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions