| 5 | import { Writer } from './Writer' |
| 6 | |
| 7 | export class ConstDeclaration implements BasicBuilder { |
| 8 | private docComment?: DocComment |
| 9 | private value?: ValueBuilder |
| 10 | |
| 11 | constructor( |
| 12 | readonly name: string, |
| 13 | readonly type?: TypeBuilder, |
| 14 | ) {} |
| 15 | |
| 16 | setDocComment(docComment: DocComment): this { |
| 17 | this.docComment = docComment |
| 18 | return this |
| 19 | } |
| 20 | |
| 21 | setValue(value: ValueBuilder): this { |
| 22 | this.value = value |
| 23 | return this |
| 24 | } |
| 25 | |
| 26 | write(writer: Writer): void { |
| 27 | if (this.docComment) { |
| 28 | writer.write(this.docComment) |
| 29 | } |
| 30 | writer.write('const ').write(this.name) |
| 31 | if (this.type) { |
| 32 | writer.write(': ').write(this.type) |
| 33 | } |
| 34 | if (this.value) { |
| 35 | writer.write(' = ').write(this.value) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | export function constDeclaration(name: string, type?: TypeBuilder) { |
| 41 | return new ConstDeclaration(name, type) |
nothing calls this directly
no outgoing calls
no test coverage detected