Skip to content

Commit e108a12

Browse files
committed
Added support for generating @deprecated tags.
1 parent dfa1470 commit e108a12

File tree

3 files changed

+33
-103
lines changed

3 files changed

+33
-103
lines changed

package-lock.json

Lines changed: 1 addition & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TypeScriptWriter } from './typescript-writer';
2-
import { DefinitionBuilder } from './definition-builder';
32

43
/**
54
* Enumerates the valid TypeScript access modifiers.
@@ -23,6 +22,13 @@ export interface DefinitionBase {
2322
description?: string[];
2423
}
2524

25+
export interface HasJsDocTags {
26+
/**
27+
* Writes the @deprecated annotation, marking a symbol as being deprecated.
28+
*/
29+
deprecated?: string;
30+
}
31+
2632
/**
2733
* Defines a decorator.
2834
*/
@@ -59,7 +65,7 @@ export interface Decoratable {
5965
/**
6066
* The base interface for class-, interface and enumeration definitions.
6167
*/
62-
export interface TypeDefinition extends DefinitionBase, NamedDefinition {
68+
export interface TypeDefinition extends DefinitionBase, NamedDefinition, HasJsDocTags {
6369
/**
6470
* Indicates if the 'export' keyword should be written. The default value is false.
6571
*/
@@ -104,7 +110,7 @@ export interface VariableDefinition extends DefinitionBase, NamedDefinition {
104110
/**
105111
* Represents a TypeScript property.
106112
*/
107-
export interface PropertyDefinition extends DefinitionBase, NamedDefinition, Decoratable {
113+
export interface PropertyDefinition extends DefinitionBase, NamedDefinition, Decoratable, HasJsDocTags {
108114
/**
109115
* The full type name of the property. If the type is an array,
110116
* the collection must be part of the name (e.g. 'Array<string>'
@@ -187,7 +193,7 @@ export interface ParameterDefinition extends DefinitionBase, NamedDefinition {
187193
/**
188194
* Represents a TypeScript function.
189195
*/
190-
export interface FunctionDefinition extends DefinitionBase {
196+
export interface FunctionDefinition extends DefinitionBase, HasJsDocTags {
191197
/**
192198
* Get or sets the name of the function. This field is required,
193199
* except when isConstructor is true.
@@ -236,7 +242,6 @@ export interface FunctionDefinition extends DefinitionBase {
236242
isConstructor?: boolean;
237243
}
238244

239-
240245
/**
241246
* Represents a TypeScript class.
242247
*/
@@ -269,7 +274,7 @@ export interface ClassDefinition extends TypeDefinition, Decoratable {
269274
/**
270275
* Represents a TypeScript enumeration member.
271276
*/
272-
export interface EnumMemberDefinition extends DefinitionBase, NamedDefinition {
277+
export interface EnumMemberDefinition extends DefinitionBase, NamedDefinition, HasJsDocTags {
273278
/**
274279
* The value of the member, which can either be a number or a string.
275280
* This field is optional. If this field has a value, an initializer

src/typescript-writer.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as opts from './options';
44
import { CodeWriter, TextWriter, NameUtility, CodeWriterUtility } from '@yellicode/core';
55
import { TypeNameProvider } from '@yellicode/elements';
66
import { TypeScriptTypeNameProvider } from './typescript-type-name-provider';
7-
import { ClassDefinition, InterfaceDefinition, EnumDefinition, PropertyDefinition, FunctionDefinition, ParameterDefinition, DecoratorDefinition, VariableDefinition } from './model';
7+
import { ClassDefinition, InterfaceDefinition, EnumDefinition, PropertyDefinition, FunctionDefinition, ParameterDefinition, DecoratorDefinition, VariableDefinition, HasJsDocTags } from './model';
88
import { DefinitionBuilder } from './definition-builder';
99

1010
/**
@@ -145,8 +145,7 @@ export class TypeScriptWriter extends CodeWriter {
145145
*/
146146
public writeVariableDeclaration(definition: VariableDefinition, kind: 'const' | 'let'): this {
147147
if (definition.description) {
148-
// Yes, variables can have docs!
149-
this.writeJsDocLines(definition.description);
148+
this.writeJsDocLines(definition.description); // Yes, variables can have docs!
150149
}
151150
this.writeIndent();
152151
if (definition.export) {
@@ -214,9 +213,8 @@ export class TypeScriptWriter extends CodeWriter {
214213
}
215214
else definition = cls;
216215

217-
if (definition.description) {
218-
this.writeJsDocLines(definition.description);
219-
}
216+
this.writeJsDocLines(definition.description, definition);
217+
220218
if (definition.decorators) {
221219
this.writeDecorators(definition.decorators, false);
222220
}
@@ -270,9 +268,7 @@ export class TypeScriptWriter extends CodeWriter {
270268
}
271269
else definition = iface;
272270

273-
if (definition.description) {
274-
this.writeJsDocLines(definition.description);
275-
}
271+
this.writeJsDocLines(definition.description, definition);
276272
this.writeIndent();
277273
if (definition.export) {
278274
this.write(`export `);
@@ -341,9 +337,8 @@ export class TypeScriptWriter extends CodeWriter {
341337
const hasDefaultValue = t !== 'undefined'; // '!== undefined' to allow for empty strings and explicit null
342338

343339
// Description
344-
if (definition.description) {
345-
this.writeJsDocLines(definition.description);
346-
}
340+
this.writeJsDocLines(definition.description, definition);
341+
347342
// Start a new, indented line
348343
this.writeIndent();
349344

@@ -439,9 +434,7 @@ export class TypeScriptWriter extends CodeWriter {
439434
}
440435
else definition = enumeration;
441436

442-
if (definition.description) {
443-
this.writeJsDocLines(definition.description);
444-
}
437+
this.writeJsDocLines(definition.description, definition);
445438
this.writeIndent();
446439
if (definition.export) {
447440
this.write(`export `);
@@ -460,9 +453,7 @@ export class TypeScriptWriter extends CodeWriter {
460453
this.increaseIndent();
461454
for (let i = 0, len = definition.members.length; i < len; i++) {
462455
const member = definition.members[i];
463-
if (member.description) {
464-
this.writeJsDocLines(member.description);
465-
}
456+
this.writeJsDocLines(member.description, member);
466457
this.writeIndent();
467458
this.write(member.name);
468459
if (member.value || member.value === 0) {
@@ -782,9 +773,19 @@ export class TypeScriptWriter extends CodeWriter {
782773
return this;
783774
}
784775

785-
public writeJsDocLines(lines: string[]): this {
786-
if (lines.length === 0)
776+
public writeJsDocLines(lines: string[]): this;
777+
public writeJsDocLines(lines: string[] | undefined, taggedSymbol: HasJsDocTags | undefined): this;
778+
public writeJsDocLines(lines: string[] | undefined, taggedSymbol?: HasJsDocTags): this {
779+
lines = lines || [];
780+
781+
if (taggedSymbol) {
782+
if (taggedSymbol.deprecated) {
783+
lines.push(`@deprecated ${taggedSymbol.deprecated}`);
784+
}
785+
}
786+
if (lines.length === 0) {
787787
return this;
788+
}
788789

789790
this.writeLine('/**');
790791

0 commit comments

Comments
 (0)