Skip to content

Commit 6a6777e

Browse files
authored
Fix false positives for type-only import in rules that use compilation (#139)
1 parent b1d7d45 commit 6a6777e

File tree

3 files changed

+13
-38
lines changed

3 files changed

+13
-38
lines changed

src/shared/svelte-compile-warns.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ export function getSvelteCompileWarnings(
101101
importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Preserve,
102102
sourceMap: true,
103103
},
104-
transformers: {
105-
before: [createTsImportTransformer(ts)],
106-
},
107104
})
108105

109106
const outputText = `${output.outputText}\n`
@@ -387,38 +384,3 @@ function getWarningsFromCode(
387384
]
388385
}
389386
}
390-
391-
/**
392-
* @see https://github.com/sveltejs/eslint-plugin-svelte3/blob/259263ccaf69c59e473d9bfa39706b0955eccfbd/src/preprocess.js#L194
393-
* MIT License @ Conduitry
394-
*/
395-
function createTsImportTransformer(
396-
ts: TS,
397-
): typescript.TransformerFactory<typescript.SourceFile> {
398-
const factory = ts.factory
399-
/**
400-
* https://github.com/sveltejs/svelte-preprocess/blob/main/src/transformers/typescript.ts
401-
* TypeScript transformer for preserving imports correctly when preprocessing TypeScript files
402-
*/
403-
return (context: typescript.TransformationContext) => {
404-
/** visitor */
405-
function visit(node: typescript.Node): typescript.Node {
406-
if (ts.isImportDeclaration(node)) {
407-
if (node.importClause && node.importClause.isTypeOnly) {
408-
return factory.createEmptyStatement()
409-
}
410-
411-
return factory.createImportDeclaration(
412-
node.decorators,
413-
node.modifiers,
414-
node.importClause,
415-
node.moduleSpecifier,
416-
)
417-
}
418-
419-
return ts.visitEachChild(node, (child) => visit(child), context)
420-
}
421-
422-
return (node: typescript.SourceFile) => ts.visitNode(node, visit)
423-
}
424-
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script lang="ts">
2+
import type { Writable } from "svelte/store"
3+
import { writable } from "svelte/store"
4+
let a: Writable = writable(42)
5+
</script>
6+
7+
{{ $a }}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script lang="ts">
2+
import { type Writable, writable } from "svelte/store"
3+
let a: Writable = writable(42)
4+
</script>
5+
6+
{{ $a }}

0 commit comments

Comments
 (0)