(
node: ts.ModuleDeclaration,
diagnostics: Array<JSDocModelDiagnostic>,
linkContext: { readonly checker: ts.TypeChecker; readonly entry: ProgramCacheEntry; readonly cwd: string },
isInsideDeclare = false
)
| 3208 | } |
| 3209 | |
| 3210 | function parseNamespaceTs( |
| 3211 | node: ts.ModuleDeclaration, |
| 3212 | diagnostics: Array<JSDocModelDiagnostic>, |
| 3213 | linkContext: { readonly checker: ts.TypeChecker; readonly entry: ProgramCacheEntry; readonly cwd: string }, |
| 3214 | isInsideDeclare = false |
| 3215 | ): ParsedNamespace | undefined { |
| 3216 | if (!ts.isIdentifier(node.name)) return undefined |
| 3217 | if (!isInsideDeclare && !hasDeclareModifier(node)) { |
| 3218 | diagnostics.push({ |
| 3219 | ...diagnostic("namespace-declare", "Namespaces must be declared with declare namespace"), |
| 3220 | range: nodeRange(node) |
| 3221 | }) |
| 3222 | return undefined |
| 3223 | } |
| 3224 | const documented = parseDocumentedTs(node, "namespace", diagnostics, true, linkContext) |
| 3225 | if (documented === undefined) return undefined |
| 3226 | const declarations: Array<ParsedNamespaceDeclaration> = [] |
| 3227 | const namespaces: Array<ParsedNamespace> = [] |
| 3228 | if (node.body !== undefined && ts.isModuleBlock(node.body)) { |
| 3229 | for (const statement of node.body.statements) { |
| 3230 | if (!hasExportModifier(statement)) continue |
| 3231 | if (ts.isModuleDeclaration(statement)) { |
| 3232 | const nested = parseNamespaceTs(statement, diagnostics, linkContext, true) |
| 3233 | if (nested !== undefined) namespaces.push(nested) |
| 3234 | continue |
| 3235 | } |
| 3236 | if (ts.isEnumDeclaration(statement)) { |
| 3237 | diagnostics.push({ ...diagnostic("enum", "Enums are not allowed"), range: nodeRange(statement) }) |
| 3238 | continue |
| 3239 | } |
| 3240 | const bucket = bucketOfTs(statement) |
| 3241 | if (bucket !== "type") { |
| 3242 | diagnostics.push({ |
| 3243 | ...diagnostic("namespace-value", "Namespace exports must be type declarations"), |
| 3244 | range: nodeRange(statement) |
| 3245 | }) |
| 3246 | continue |
| 3247 | } |
| 3248 | const nestedDocumented = parseDocumentedTs(statement, "namespace-declaration", diagnostics, true, linkContext) |
| 3249 | if (nestedDocumented === undefined) continue |
| 3250 | const name = declarationName(statement) |
| 3251 | if (name === undefined || name.length === 0) { |
| 3252 | diagnostics.push({ |
| 3253 | ...diagnostic("missing-name", "Namespace declaration name could not be determined"), |
| 3254 | range: nodeRange(statement) |
| 3255 | }) |
| 3256 | continue |
| 3257 | } |
| 3258 | declarations.push({ |
| 3259 | name, |
| 3260 | signature: null, |
| 3261 | range: publicDeclarationRange(statement, name), |
| 3262 | description: nestedDocumented.core.description, |
| 3263 | examples: nestedDocumented.core.examples, |
| 3264 | tags: nestedDocumented.tags as ParsedNamespaceTags, |
| 3265 | members: parseDeclarationMembersTs(statement, diagnostics, linkContext) |
| 3266 | }) |
| 3267 | } |
no test coverage detected