Skip to content

Commit 9545980

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 a34ddd6 commit 9545980

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
@@ -568,7 +568,11 @@ export class FileIndexer {
568568
const alias = node.name
569569
? this.checker.getSymbolAtLocation(node.name)
570570
: undefined
571-
if (alias && (alias.flags & ts.SymbolFlags.Alias) !== 0) {
571+
if (
572+
(sourceInfo?.isSvelte || isSvelteImport(node)) &&
573+
alias &&
574+
(alias.flags & ts.SymbolFlags.Alias) !== 0
575+
) {
572576
const imported = this.checker.getAliasedSymbol(alias)
573577
for (const declaration of imported.declarations || []) {
574578
return this.scipSymbol(declaration)
@@ -846,6 +850,20 @@ function isAnonymousContainerOfSymbols(node: ts.Node): boolean {
846850
)
847851
}
848852

853+
function isSvelteImport(
854+
node: ts.ImportSpecifier | ts.ImportClause | ts.NamespaceImport
855+
): boolean {
856+
let parent: ts.Node | undefined = node.parent
857+
while (parent && !ts.isImportDeclaration(parent)) {
858+
parent = parent.parent
859+
}
860+
return (
861+
!!parent &&
862+
ts.isStringLiteral(parent.moduleSpecifier) &&
863+
parent.moduleSpecifier.text.endsWith('.svelte')
864+
)
865+
}
866+
849867
function scriptElementKind(
850868
node: ts.Node,
851869
sym: ts.Symbol

0 commit comments

Comments
 (0)