( specifier: string, name: string, importer: SourceModule, localOnly: boolean, seen: Set<string> )
| 2940 | } |
| 2941 | |
| 2942 | private findExportedType( |
| 2943 | specifier: string, |
| 2944 | name: string, |
| 2945 | importer: SourceModule, |
| 2946 | localOnly: boolean, |
| 2947 | seen: Set<string> |
| 2948 | ): ExportedType { |
| 2949 | // a type carries no value, so a host asks no bundler to resolve it |
| 2950 | const resolved = this.resolve(specifier, importer, () => false) |
| 2951 | // a JS module's types are in the .d.ts beside it |
| 2952 | const target = |
| 2953 | resolved instanceof SourceModule ? |
| 2954 | (this.declarationsOf(resolved) ?? resolved) |
| 2955 | : resolved |
| 2956 | if (!(target instanceof SourceModule)) return { kind: "opaque" } |
| 2957 | if (seen.has(target.id)) return { kind: "missing" } |
| 2958 | seen.add(target.id) |
| 2959 | for (const statement of target.program.body) { |
| 2960 | if (statement.type === "ExportNamedDeclaration") { |
| 2961 | const declaration = statement.declaration |
| 2962 | if ( |
| 2963 | (declaration?.type === "TSInterfaceDeclaration" || |
| 2964 | declaration?.type === "TSTypeAliasDeclaration") && |
| 2965 | declaration.id.name === name |
| 2966 | ) |
| 2967 | return { kind: "local", declaration, module: target } |
| 2968 | for (const exported of statement.specifiers) { |
| 2969 | if (exportNameOf(exported.exported) !== name) continue |
| 2970 | const localName = exportNameOf(exported.local) |
| 2971 | if (statement.source) { |
| 2972 | return this.resolveExportedType( |
| 2973 | statement.source.value, |
| 2974 | localName, |
| 2975 | target, |
| 2976 | localOnly, |
| 2977 | seen |
| 2978 | ) |
| 2979 | } |
| 2980 | const local = this.localTypeOf(target, localName) |
| 2981 | if (local) |
| 2982 | return { kind: "local", declaration: local, module: target } |
| 2983 | const imported = importedNameOf(target, localName) |
| 2984 | return imported && imported[1] !== "*" ? |
| 2985 | this.resolveExportedType( |
| 2986 | imported[0], |
| 2987 | imported[1], |
| 2988 | target, |
| 2989 | localOnly, |
| 2990 | seen |
| 2991 | ) |
| 2992 | : { kind: "opaque" } |
| 2993 | } |
| 2994 | } else if ( |
| 2995 | statement.type === "ExportAllDeclaration" && |
| 2996 | !statement.exported |
| 2997 | ) { |
| 2998 | const found = this.resolveExportedType( |
| 2999 | statement.source.value, |
no test coverage detected