Skip to content

Commit b78f907

Browse files
committed
Demote IndentedWriter to be part of api-documenter, since it's now the only NPM package that needs this class
1 parent 18106bd commit b78f907

7 files changed

Lines changed: 56 additions & 60 deletions

File tree

apps/api-documenter/src/markdown/CustomMarkdownEmitter.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import * as colors from 'colors';
66
import {
77
DocNode, DocLinkTag, StringBuilder
88
} from '@microsoft/tsdoc';
9+
import {
10+
ApiModel,
11+
IResolveDeclarationReferenceResult,
12+
ApiItem
13+
} from '@microsoft/api-extractor-model';
14+
915
import { CustomDocNodeKind } from '../nodes/CustomDocNodeKind';
1016
import { DocHeading } from '../nodes/DocHeading';
1117
import { DocNoteBox } from '../nodes/DocNoteBox';
@@ -17,12 +23,7 @@ import {
1723
IMarkdownEmitterContext,
1824
IMarkdownEmitterOptions
1925
} from './MarkdownEmitter';
20-
import {
21-
ApiModel,
22-
IResolveDeclarationReferenceResult,
23-
ApiItem,
24-
IndentedWriter
25-
} from '@microsoft/api-extractor-model';
26+
import { IndentedWriter } from '../utils/IndentedWriter';
2627

2728
export interface ICustomMarkdownEmitterOptions extends IMarkdownEmitterOptions {
2829
contextApiItem: ApiItem | undefined;

apps/api-documenter/src/markdown/MarkdownEmitter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import {
1717
DocEscapedText,
1818
DocErrorText
1919
} from '@microsoft/tsdoc';
20-
import { IndentedWriter } from '@microsoft/api-extractor-model';
2120
import { InternalError } from '@microsoft/node-core-library';
2221

22+
import { IndentedWriter } from '../utils/IndentedWriter';
23+
2324
export interface IMarkdownEmitterOptions {
2425
}
2526

apps/api-documenter/src/utils/IndentedWriter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import { StringBuilder, IStringBuilder } from '@microsoft/node-core-library';
2929
* two
3030
* end
3131
* ```
32-
*
33-
* @beta
3432
*/
3533
export class IndentedWriter {
3634
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"isEnabled": true
2+
"isEnabled": false
33
}

apps/api-extractor-model/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
export { AedocDefinitions } from './aedoc/AedocDefinitions';
1313
export { ReleaseTag } from './aedoc/ReleaseTag';
1414

15-
export { IndentedWriter } from './IndentedWriter';
16-
1715
// items
1816
export {
1917
IApiDeclaredItemOptions,

apps/api-extractor/src/generators/DtsRollupGenerator.ts

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
/* tslint:disable:no-bitwise */
55

66
import * as ts from 'typescript';
7-
import { FileSystem, NewlineKind, InternalError } from '@microsoft/node-core-library';
8-
import {
9-
IndentedWriter,
10-
ReleaseTag
11-
} from '@microsoft/api-extractor-model';
7+
import { FileSystem, NewlineKind, InternalError, StringBuilder } from '@microsoft/node-core-library';
8+
import { ReleaseTag } from '@microsoft/api-extractor-model';
129

1310
import { Collector } from '../collector/Collector';
1411
import { TypeScriptHelpers } from '../analyzer/TypeScriptHelpers';
@@ -45,40 +42,60 @@ export enum DtsRollupKind {
4542
PublicRelease
4643
}
4744

45+
// This helper class used by DtsRollupGenerator
46+
class StringWriter extends StringBuilder {
47+
public readonly stringBuilder: StringBuilder = new StringBuilder();
48+
49+
public write(s: string): void {
50+
this.stringBuilder.append(s);
51+
}
52+
53+
public writeLine(s: string = ''): void {
54+
if (s.length > 0) {
55+
this.stringBuilder.append(s);
56+
}
57+
this.stringBuilder.append('\n');
58+
}
59+
60+
public toString(): string {
61+
return this.stringBuilder.toString();
62+
}
63+
}
64+
4865
export class DtsRollupGenerator {
4966
/**
5067
* Generates the typings file and writes it to disk.
5168
*
5269
* @param dtsFilename - The *.d.ts output filename
5370
*/
5471
public static writeTypingsFile(collector: Collector, dtsFilename: string, dtsKind: DtsRollupKind): void {
55-
const indentedWriter: IndentedWriter = new IndentedWriter();
72+
const stringWriter: StringWriter = new StringWriter();
5673

57-
DtsRollupGenerator._generateTypingsFileContent(collector, indentedWriter, dtsKind);
74+
DtsRollupGenerator._generateTypingsFileContent(collector, stringWriter, dtsKind);
5875

59-
FileSystem.writeFile(dtsFilename, indentedWriter.toString(), {
76+
FileSystem.writeFile(dtsFilename, stringWriter.toString(), {
6077
convertLineEndings: NewlineKind.CrLf,
6178
ensureFolderExists: true
6279
});
6380
}
6481

65-
private static _generateTypingsFileContent(collector: Collector, indentedWriter: IndentedWriter,
82+
private static _generateTypingsFileContent(collector: Collector, stringWriter: StringWriter,
6683
dtsKind: DtsRollupKind): void {
6784

6885
if (collector.workingPackage.tsdocParserContext) {
69-
indentedWriter.writeLine(collector.workingPackage.tsdocParserContext.sourceRange.toString());
70-
indentedWriter.writeLine();
86+
stringWriter.writeLine(collector.workingPackage.tsdocParserContext.sourceRange.toString());
87+
stringWriter.writeLine();
7188
}
7289

7390
// Emit the triple slash directives
7491
for (const typeDirectiveReference of collector.dtsTypeReferenceDirectives) {
7592
// tslint:disable-next-line:max-line-length
7693
// https://github.com/Microsoft/TypeScript/blob/611ebc7aadd7a44a4c0447698bfda9222a78cb66/src/compiler/declarationEmitter.ts#L162
77-
indentedWriter.writeLine(`/// <reference types="${typeDirectiveReference}" />`);
94+
stringWriter.writeLine(`/// <reference types="${typeDirectiveReference}" />`);
7895
}
7996

8097
for (const libDirectiveReference of collector.dtsLibReferenceDirectives) {
81-
indentedWriter.writeLine(`/// <reference lib="${libDirectiveReference}" />`);
98+
stringWriter.writeLine(`/// <reference lib="${libDirectiveReference}" />`);
8299
}
83100

84101
// Emit the imports
@@ -95,17 +112,17 @@ export class DtsRollupGenerator {
95112
switch (astImport.importKind) {
96113
case AstImportKind.NamedImport:
97114
if (entity.nameForEmit !== astImport.exportName) {
98-
indentedWriter.write(`import { ${astImport.exportName} as ${entity.nameForEmit} }`);
115+
stringWriter.write(`import { ${astImport.exportName} as ${entity.nameForEmit} }`);
99116
} else {
100-
indentedWriter.write(`import { ${astImport.exportName} }`);
117+
stringWriter.write(`import { ${astImport.exportName} }`);
101118
}
102-
indentedWriter.writeLine(` from '${astImport.modulePath}';`);
119+
stringWriter.writeLine(` from '${astImport.modulePath}';`);
103120
break;
104121
case AstImportKind.StarImport:
105-
indentedWriter.writeLine(`import * as ${entity.nameForEmit} from '${astImport.modulePath}';`);
122+
stringWriter.writeLine(`import * as ${entity.nameForEmit} from '${astImport.modulePath}';`);
106123
break;
107124
case AstImportKind.EqualsImport:
108-
indentedWriter.writeLine(`import ${entity.nameForEmit} = require('${astImport.modulePath}');`);
125+
stringWriter.writeLine(`import ${entity.nameForEmit} = require('${astImport.modulePath}');`);
109126
break;
110127
default:
111128
throw new InternalError('Unimplemented AstImportKind');
@@ -121,8 +138,8 @@ export class DtsRollupGenerator {
121138
const releaseTag: ReleaseTag = symbolMetadata ? symbolMetadata.releaseTag : ReleaseTag.None;
122139

123140
if (!this._shouldIncludeReleaseTag(releaseTag, dtsKind)) {
124-
indentedWriter.writeLine();
125-
indentedWriter.writeLine(`/* Excluded from this release type: ${entity.nameForEmit} */`);
141+
stringWriter.writeLine();
142+
stringWriter.writeLine(`/* Excluded from this release type: ${entity.nameForEmit} */`);
126143
continue;
127144
}
128145

@@ -131,38 +148,38 @@ export class DtsRollupGenerator {
131148
// Emit all the declarations for this entry
132149
for (const astDeclaration of entity.astEntity.astDeclarations || []) {
133150

134-
indentedWriter.writeLine();
151+
stringWriter.writeLine();
135152

136153
const span: Span = new Span(astDeclaration.declaration);
137154
DtsRollupGenerator._modifySpan(collector, span, entity, astDeclaration, dtsKind);
138-
indentedWriter.writeLine(span.getModifiedText());
155+
stringWriter.writeLine(span.getModifiedText());
139156
}
140157
}
141158

142159
if (!entity.shouldInlineExport) {
143160
for (const exportName of entity.exportNames) {
144161
if (exportName === ts.InternalSymbolName.Default) {
145-
indentedWriter.writeLine(`export default ${entity.nameForEmit};`);
162+
stringWriter.writeLine(`export default ${entity.nameForEmit};`);
146163
} else if (entity.nameForEmit !== exportName) {
147-
indentedWriter.writeLine(`export { ${entity.nameForEmit} as ${exportName} }`);
164+
stringWriter.writeLine(`export { ${entity.nameForEmit} as ${exportName} }`);
148165
} else {
149-
indentedWriter.writeLine(`export { ${exportName} }`);
166+
stringWriter.writeLine(`export { ${exportName} }`);
150167
}
151168
}
152169
}
153170
}
154171

155172
if (collector.starExportedExternalModulePaths.length > 0) {
156-
indentedWriter.writeLine();
173+
stringWriter.writeLine();
157174
for (const starExportedExternalModulePath of collector.starExportedExternalModulePaths) {
158-
indentedWriter.writeLine(`export * from "${starExportedExternalModulePath}";`);
175+
stringWriter.writeLine(`export * from "${starExportedExternalModulePath}";`);
159176
}
160177
}
161178

162179
// Emit "export { }" which is a special directive that prevents consumers from importing declarations
163180
// that don't have an explicit "export" modifier.
164-
indentedWriter.writeLine();
165-
indentedWriter.writeLine('export { }');
181+
stringWriter.writeLine();
182+
stringWriter.writeLine('export { }');
166183
}
167184

168185
/**

common/reviews/api/api-extractor-model.api.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -674,25 +674,6 @@ interface IExcerptTokenRange {
674674
startIndex: number;
675675
}
676676

677-
// @beta
678-
declare class IndentedWriter {
679-
// (undocumented)
680-
constructor(builder?: IStringBuilder);
681-
decreaseIndent(): void;
682-
defaultIndentPrefix: string;
683-
ensureNewLine(): void;
684-
ensureSkippedLine(): void;
685-
getText(): string;
686-
increaseIndent(indentPrefix?: string): void;
687-
indentScope(scope: () => void, indentPrefix?: string): void;
688-
peekLastCharacter(): string;
689-
peekSecondLastCharacter(): string;
690-
// (undocumented)
691-
toString(): string;
692-
write(message: string): void;
693-
writeLine(message?: string): void;
694-
}
695-
696677
// @public
697678
interface IParameterOptions {
698679
// (undocumented)

0 commit comments

Comments
 (0)