Skip to content

Commit d40e260

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 f3a757d commit d40e260

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
@@ -605,7 +605,11 @@ export class FileIndexer {
605605
const alias = node.name
606606
? this.checker.getSymbolAtLocation(node.name)
607607
: undefined
608-
if (alias && (alias.flags & ts.SymbolFlags.Alias) !== 0) {
608+
if (
609+
(sourceInfo?.isSvelte || isSvelteImport(node)) &&
610+
alias &&
611+
(alias.flags & ts.SymbolFlags.Alias) !== 0
612+
) {
609613
const imported = this.checker.getAliasedSymbol(alias)
610614
for (const declaration of imported.declarations || []) {
611615
return this.scipSymbol(declaration)
@@ -883,6 +887,20 @@ function isAnonymousContainerOfSymbols(node: ts.Node): boolean {
883887
)
884888
}
885889

890+
function isSvelteImport(
891+
node: ts.ImportSpecifier | ts.ImportClause | ts.NamespaceImport
892+
): boolean {
893+
let parent: ts.Node | undefined = node.parent
894+
while (parent && !ts.isImportDeclaration(parent)) {
895+
parent = parent.parent
896+
}
897+
return (
898+
!!parent &&
899+
ts.isStringLiteral(parent.moduleSpecifier) &&
900+
parent.moduleSpecifier.text.endsWith('.svelte')
901+
)
902+
}
903+
886904
function scriptElementKind(
887905
node: ts.Node,
888906
sym: ts.Symbol

0 commit comments

Comments
 (0)