Skip to content

Commit

Permalink
fix: Preserve usused imports when esbuild transforms ts in svelte (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhmushan committed Nov 30, 2021
1 parent 29dcb8e commit 1056575
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/esbuild/svelte.ts
Expand Up @@ -67,6 +67,11 @@ export const sveltePlugin = ({
sourcefile: args.path,
loader: 'ts',
sourcemap: true,
tsconfigRaw: {
compilerOptions: {
importsNotUsedAsValues: 'preserve',
},
},
})
return {
code,
Expand Down
18 changes: 14 additions & 4 deletions test/index.test.ts
Expand Up @@ -429,20 +429,30 @@ test('bundle svelte without styles', async (t) => {
})

test('svelte: typescript support', async (t) => {
const { outFiles } = await run(t.title, {
const { outFiles, output } = await run(t.title, {
'input.ts': `import App from './App.svelte'
export { App }
`,
'App.svelte': `
<script lang="ts">
let msg: string = 'hello svelte'
import Component from './Component.svelte'
let say: string = 'hello'
let name: string = 'svelte'
</script>
<span>{msg}</span>
<Component {name}>{say}</Component>
`,
'Component.svelte': `
<script lang="ts">
export let name: string
</script>
<slot /> {name}
`,
})

t.deepEqual(outFiles, ['input.js'])
t.assert(output.includes('// Component.svelte'))
})

test('onSuccess', async (t) => {
Expand Down Expand Up @@ -643,7 +653,7 @@ test('multiple entry with the same base name', async (t) => {
t.deepEqual(outFiles, ['bar/input.js', 'input.js'])
})

test('windows backslash in entry', async (t) => {
test('windows: backslash in entry', async (t) => {
const { outFiles } = await run(
t.title,
{ 'src/input.ts': `export const foo = 1` },
Expand Down

0 comments on commit 1056575

Please sign in to comment.