( imports: ParsedJSDocImports, kind: JSDocApiKind, bucket: ExportBucket | null, apiName: string )
| 2045 | } |
| 2046 | |
| 2047 | function importGuidance( |
| 2048 | imports: ParsedJSDocImports, |
| 2049 | kind: JSDocApiKind, |
| 2050 | bucket: ExportBucket | null, |
| 2051 | apiName: string |
| 2052 | ): JSDocApiImportGuidance | null { |
| 2053 | if (kind !== "root-declaration" || bucket !== "value" || !isIdentifierName(apiName)) { |
| 2054 | return null |
| 2055 | } |
| 2056 | if (imports.flatNames.includes(apiName) && imports.barrel !== null) { |
| 2057 | return { |
| 2058 | style: "named-barrel", |
| 2059 | importDeclaration: `import { ${apiName} } from "${imports.barrel.module}"`, |
| 2060 | usage: apiName |
| 2061 | } |
| 2062 | } |
| 2063 | if (imports.barrel?.type === "namespace") { |
| 2064 | if (!isIdentifierName(imports.barrel.name)) return null |
| 2065 | return { |
| 2066 | style: "namespace-barrel", |
| 2067 | importDeclaration: `import { ${imports.barrel.name} } from "${imports.barrel.module}"`, |
| 2068 | usage: `${imports.barrel.name}.${apiName}` |
| 2069 | } |
| 2070 | } |
| 2071 | if (imports.barrel?.type === "flat") { |
| 2072 | return { |
| 2073 | style: "named-barrel", |
| 2074 | importDeclaration: `import { ${apiName} } from "${imports.barrel.module}"`, |
| 2075 | usage: apiName |
| 2076 | } |
| 2077 | } |
| 2078 | return { |
| 2079 | style: "named-module", |
| 2080 | importDeclaration: `import { ${apiName} } from "${imports.module}"`, |
| 2081 | usage: apiName |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | function makeApi(input: { |
| 2086 | readonly file: JSDocModelFile |
no test coverage detected