Skip to content

Commit ae7dadd

Browse files
committed
Preserve TypeScript import symbol output
Limit direct import-alias resolution to generated Svelte sources and imports from .svelte modules so ordinary TypeScript indexes remain byte-for-byte unchanged. Amp-Thread-ID: https://ampcode.com/threads/T-01a029e2-5095-710a-9cce-0c6d8645c173
1 parent 4bd1f5b commit ae7dadd

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/FileIndexer.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,11 @@ export class FileIndexer {
637637
const alias = node.name
638638
? this.checker.getSymbolAtLocation(node.name)
639639
: undefined
640-
if (alias && (alias.flags & ts.SymbolFlags.Alias) !== 0) {
640+
if (
641+
(sourceInfo?.isSvelte || isSvelteImport(node)) &&
642+
alias &&
643+
(alias.flags & ts.SymbolFlags.Alias) !== 0
644+
) {
641645
const imported = this.checker.getAliasedSymbol(alias)
642646
for (const declaration of imported.declarations || []) {
643647
return this.scipSymbol(declaration)
@@ -915,6 +919,20 @@ function isAnonymousContainerOfSymbols(node: ts.Node): boolean {
915919
)
916920
}
917921

922+
function isSvelteImport(
923+
node: ts.ImportSpecifier | ts.ImportClause | ts.NamespaceImport
924+
): boolean {
925+
let parent: ts.Node | undefined = node.parent
926+
while (parent && !ts.isImportDeclaration(parent)) {
927+
parent = parent.parent
928+
}
929+
return (
930+
!!parent &&
931+
ts.isStringLiteral(parent.moduleSpecifier) &&
932+
parent.moduleSpecifier.text.endsWith('.svelte')
933+
)
934+
}
935+
918936
function scriptElementKind(
919937
node: ts.Node,
920938
sym: ts.Symbol

0 commit comments

Comments
 (0)