From f21740a5d3f60dbdc1c879d742e427ce865ed7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 20 May 2026 18:37:58 +0800 Subject: [PATCH] Support types re-exported via `export *` Add support for resolving types re-exported with `export * from '...'`. Introduces extractExportAllSpecifiers and a new exportAllTypeSources map on ParsedFileEntry, populates it while parsing (recursively following export-all chains using the cache and an inProgress set to avoid cycles), and falls back to exportAllTypeSources when resolving imported type names. This allows types and generic templates exported through export-all declarations to be discovered and resolved. --- packages/proton/src/ast/import-resolver.ts | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/proton/src/ast/import-resolver.ts b/packages/proton/src/ast/import-resolver.ts index 0d1a4f6a..c662818c 100644 --- a/packages/proton/src/ast/import-resolver.ts +++ b/packages/proton/src/ast/import-resolver.ts @@ -19,6 +19,7 @@ export interface ParsedFileEntry { concrete: ProtobufMessage[]; templates: Map; importedTypeSources: Map; + exportAllTypeSources: Map; resolveImportedTypeName: ImportedTypeNameResolver; exportedWrappers: Map; } @@ -91,6 +92,16 @@ function extractValueImports(sf: ts.SourceFile): ImportClause[] { return result; } +function extractExportAllSpecifiers(sf: ts.SourceFile): string[] { + const result: string[] = []; + for (const stmt of sf.statements) { + if (!ts.isExportDeclaration(stmt) || stmt.exportClause) continue; + const spec = stmt.moduleSpecifier; + if (spec && ts.isStringLiteral(spec)) result.push(spec.text); + } + return result; +} + /** Resolve a relative module specifier to an absolute file path. Returns null if not found. */ function resolveModulePath(specifier: string, importerPath: string): string | null { if (!specifier.startsWith('.')) return null; // skip bare/alias specifiers @@ -401,6 +412,7 @@ function parseFileForDefinitions( const templates = new Map(); const resolveImportedTypeName = createImportedTypeNameResolver(sf); const importedTypeSources = new Map(); + const exportAllTypeSources = new Map(); // Collect imported wrapper bindings under their LOCAL names so this file's // forwarders can match against them. Skip work entirely if there's no cache @@ -437,6 +449,24 @@ function parseFileForDefinitions( importedTypeSources.set(imp.localName, resolved); } + if (cache) { + const inProgress = parsing ?? new Set(); + inProgress.add(absolutePath); + for (const specifier of extractExportAllSpecifiers(sf)) { + const resolved = resolveModulePath(specifier, absolutePath); + if (!resolved || inProgress.has(resolved)) continue; + let entry = cache.get(resolved); + if (!entry) { + entry = parseFileForDefinitions(resolved, undefined, cache, inProgress); + cache.set(resolved, entry); + } + for (const msg of entry.concrete) exportAllTypeSources.set(msg.name, resolved); + for (const name of entry.templates.keys()) exportAllTypeSources.set(name, resolved); + for (const [name, source] of entry.exportAllTypeSources) exportAllTypeSources.set(name, source); + } + inProgress.delete(absolutePath); + } + for (const stmt of sf.statements) { if (!ts.isInterfaceDeclaration(stmt)) continue; if (stmt.typeParameters?.length) { @@ -453,6 +483,7 @@ function parseFileForDefinitions( concrete, templates, importedTypeSources, + exportAllTypeSources, resolveImportedTypeName, exportedWrappers, }; @@ -592,7 +623,7 @@ export function resolveImports( return; } - const importedPath = from.importedTypeSources.get(typeName); + const importedPath = from.importedTypeSources.get(typeName) ?? from.exportAllTypeSources.get(typeName); if (!importedPath) return; resolveTypeName(typeName, getEntry(importedPath));