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

fix: Preserve usused imports when esbuild transforms ts in svelte #476

Merged
merged 1 commit into from Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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