Skip to content

Commit f365be4

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 1c79870 commit f365be4

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
@@ -575,7 +575,11 @@ export class FileIndexer {
575575
const alias = node.name
576576
? this.checker.getSymbolAtLocation(node.name)
577577
: undefined
578-
if (alias && (alias.flags & ts.SymbolFlags.Alias) !== 0) {
578+
if (
579+
(sourceInfo?.isSvelte || isSvelteImport(node)) &&
580+
alias &&
581+
(alias.flags & ts.SymbolFlags.Alias) !== 0
582+
) {
579583
const imported = this.checker.getAliasedSymbol(alias)
580584
for (const declaration of imported.declarations || []) {
581585
return this.scipSymbol(declaration)
@@ -853,6 +857,20 @@ function isAnonymousContainerOfSymbols(node: ts.Node): boolean {
853857
)
854858
}
855859

860+
function isSvelteImport(
861+
node: ts.ImportSpecifier | ts.ImportClause | ts.NamespaceImport
862+
): boolean {
863+
let parent: ts.Node | undefined = node.parent
864+
while (parent && !ts.isImportDeclaration(parent)) {
865+
parent = parent.parent
866+
}
867+
return (
868+
!!parent &&
869+
ts.isStringLiteral(parent.moduleSpecifier) &&
870+
parent.moduleSpecifier.text.endsWith('.svelte')
871+
)
872+
}
873+
856874
function scriptElementKind(
857875
node: ts.Node,
858876
sym: ts.Symbol

0 commit comments

Comments
 (0)