Skip to content

Commit c01444e

Browse files
committed
Add support for enums, type aliases, and interface methods
1 parent a99341e commit c01444e

File tree

10 files changed

+316
-11
lines changed

10 files changed

+316
-11
lines changed

apps/api-extractor/src/generators/packageTypings/AstSymbolTable.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,25 @@ export class AstSymbolTable {
107107
* This function determines which node types will generate an AstDeclaration.
108108
*/
109109
public isAstDeclaration(node: ts.Node): boolean {
110+
// (alphabetical order)
110111
switch (node.kind) {
111112
case ts.SyntaxKind.ClassDeclaration:
112-
case ts.SyntaxKind.MethodDeclaration:
113-
case ts.SyntaxKind.PropertySignature:
114-
case ts.SyntaxKind.PropertyDeclaration:
115-
case ts.SyntaxKind.InterfaceDeclaration:
113+
case ts.SyntaxKind.EnumDeclaration:
114+
case ts.SyntaxKind.EnumMember:
116115
case ts.SyntaxKind.FunctionDeclaration:
116+
case ts.SyntaxKind.InterfaceDeclaration:
117+
case ts.SyntaxKind.MethodDeclaration:
118+
case ts.SyntaxKind.MethodSignature:
119+
117120
// ModuleDeclaration is used for both "module" and "namespace" declarations
118121
case ts.SyntaxKind.ModuleDeclaration:
119-
case ts.SyntaxKind.VariableDeclaration:
120-
// This is used for "import * as file from 'file';"
122+
case ts.SyntaxKind.PropertyDeclaration:
123+
case ts.SyntaxKind.PropertySignature:
124+
125+
// SourceFile is used for "import * as file from 'file';"
121126
case ts.SyntaxKind.SourceFile:
127+
case ts.SyntaxKind.TypeAliasDeclaration:
128+
case ts.SyntaxKind.VariableDeclaration:
122129
return true;
123130
}
124131
return false;
@@ -248,7 +255,8 @@ export class AstSymbolTable {
248255

249256
for (const declaration of followedSymbol.declarations || []) {
250257
if (!this.isAstDeclaration(declaration)) {
251-
throw new Error('Program Bug: Followed a symbol with an invalid declaration: ' + followedSymbol.name);
258+
throw new Error(`Program Bug: The "${followedSymbol.name}" symbol uses the construct`
259+
+ ` "${ts.SyntaxKind[declaration.kind]}" which may be an unimplemented language feature`);
252260
}
253261
}
254262

build-tests/api-extractor-test-04/dist/index-internal.d.ts

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export declare class AlphaClass {
2727
* This is a beta class
2828
* @beta
2929
*/
30-
export declare class BetaClass {
30+
export declare class BetaClass implements BetaInterface {
3131
/**
3232
* This is a comment
3333
*/
@@ -44,6 +44,48 @@ export declare class BetaClass {
4444
_internalMember(): void;
4545
}
4646

47+
/**
48+
* This is a beta interface
49+
* @beta
50+
*/
51+
export declare interface BetaInterface {
52+
/**
53+
* This is a comment
54+
*/
55+
undecoratedMember(): void;
56+
/**
57+
* This is an alpha comment
58+
* @alpha
59+
*/
60+
alphaMember(): void;
61+
/**
62+
* This is an internal member
63+
* @internal
64+
*/
65+
_internalMember(): void;
66+
}
67+
68+
/**
69+
* This is a const enum marked as \@beta
70+
* @beta
71+
*/
72+
export declare const enum ConstEnum {
73+
/**
74+
* This member inherits its \@beta status from the parent
75+
*/
76+
BetaMember2 = "BetaMember2",
77+
/**
78+
* This member is marked as \@alpha
79+
* @alpha
80+
*/
81+
AlphaMember = "AlphaMember",
82+
/**
83+
* This member is marked as \@internal
84+
* @internal
85+
*/
86+
_InternalMember = "_InternalMember",
87+
}
88+
4789
/**
4890
* This is a "beta" namespace.
4991
* @beta
@@ -87,6 +129,11 @@ export declare namespace EntangledNamespace {
87129
}
88130
}
89131

132+
/**
133+
* This is an exported type alias.
134+
*/
135+
export declare type ExportedAlias = AlphaClass;
136+
90137
/**
91138
* This is an internal class
92139
* @internal
@@ -103,6 +150,11 @@ export declare class InternalClass {
103150
* @public
104151
*/
105152
export declare class PublicClass {
153+
/**
154+
* This is a beta field
155+
* @beta
156+
*/
157+
betaField: string;
106158
/**
107159
* This is a comment
108160
*/
@@ -123,3 +175,26 @@ export declare class PublicClass {
123175
*/
124176
_internalMember(): void;
125177
}
178+
179+
/**
180+
* This is a regular enum marked as \@beta
181+
* @beta
182+
*/
183+
export declare enum RegularEnum {
184+
/**
185+
* This member inherits its \@beta status from the parent
186+
*/
187+
BetaMember = 100,
188+
/**
189+
* This member is marked as \@alpha
190+
* @alpha
191+
*/
192+
AlphaMember = 101,
193+
/**
194+
* This member is marked as \@internal
195+
* @internal
196+
*/
197+
_InternalMember = 102,
198+
}
199+
200+
declare const variableDeclaration: string;

build-tests/api-extractor-test-04/dist/index-preview.d.ts

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* This is a beta class
1414
* @beta
1515
*/
16-
export declare class BetaClass {
16+
export declare class BetaClass implements BetaInterface {
1717
/**
1818
* This is a comment
1919
*/
@@ -30,6 +30,48 @@ export declare class BetaClass {
3030
_internalMember(): void;
3131
}
3232

33+
/**
34+
* This is a beta interface
35+
* @beta
36+
*/
37+
export declare interface BetaInterface {
38+
/**
39+
* This is a comment
40+
*/
41+
undecoratedMember(): void;
42+
/**
43+
* This is an alpha comment
44+
* @alpha
45+
*/
46+
alphaMember(): void;
47+
/**
48+
* This is an internal member
49+
* @internal
50+
*/
51+
_internalMember(): void;
52+
}
53+
54+
/**
55+
* This is a const enum marked as \@beta
56+
* @beta
57+
*/
58+
export declare const enum ConstEnum {
59+
/**
60+
* This member inherits its \@beta status from the parent
61+
*/
62+
BetaMember2 = "BetaMember2",
63+
/**
64+
* This member is marked as \@alpha
65+
* @alpha
66+
*/
67+
AlphaMember = "AlphaMember",
68+
/**
69+
* This member is marked as \@internal
70+
* @internal
71+
*/
72+
_InternalMember = "_InternalMember",
73+
}
74+
3375
/**
3476
* This is a "beta" namespace.
3577
* @beta
@@ -73,13 +115,23 @@ export declare namespace EntangledNamespace {
73115
}
74116
}
75117

118+
/**
119+
* This is an exported type alias.
120+
*/
121+
export declare type ExportedAlias = AlphaClass;
122+
76123
// Removed for this release type: InternalClass
77124

78125
/**
79126
* This is a public class
80127
* @public
81128
*/
82129
export declare class PublicClass {
130+
/**
131+
* This is a beta field
132+
* @beta
133+
*/
134+
betaField: string;
83135
/**
84136
* This is a comment
85137
*/
@@ -100,3 +152,26 @@ export declare class PublicClass {
100152
*/
101153
_internalMember(): void;
102154
}
155+
156+
/**
157+
* This is a regular enum marked as \@beta
158+
* @beta
159+
*/
160+
export declare enum RegularEnum {
161+
/**
162+
* This member inherits its \@beta status from the parent
163+
*/
164+
BetaMember = 100,
165+
/**
166+
* This member is marked as \@alpha
167+
* @alpha
168+
*/
169+
AlphaMember = 101,
170+
/**
171+
* This member is marked as \@internal
172+
* @internal
173+
*/
174+
_InternalMember = 102,
175+
}
176+
177+
declare const variableDeclaration: string;

build-tests/api-extractor-test-04/dist/index-public.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,29 @@
1111

1212
// Removed for this release type: BetaClass
1313

14+
// Removed for this release type: BetaInterface
15+
16+
// Removed for this release type: ConstEnum
17+
1418
// Removed for this release type: EntangledNamespace
1519

20+
/**
21+
* This is an exported type alias.
22+
*/
23+
export declare type ExportedAlias = AlphaClass;
24+
1625
// Removed for this release type: InternalClass
1726

1827
/**
1928
* This is a public class
2029
* @public
2130
*/
2231
export declare class PublicClass {
32+
/**
33+
* This is a beta field
34+
* @beta
35+
*/
36+
betaField: string;
2337
/**
2438
* This is a comment
2539
*/
@@ -40,3 +54,7 @@ export declare class PublicClass {
4054
*/
4155
_internalMember(): void;
4256
}
57+
58+
// Removed for this release type: RegularEnum
59+
60+
declare const variableDeclaration: string;

build-tests/api-extractor-test-04/etc/api-extractor-test-04.api.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@ class AlphaClass {
66
}
77

88
// @beta
9-
class BetaClass {
9+
class BetaClass implements BetaInterface {
1010
// @internal
1111
_internalMember(): void;
1212
// @alpha
1313
alphaMember(): void;
1414
undecoratedMember(): void;
1515
}
1616

17+
// @beta
18+
interface BetaInterface {
19+
// @internal
20+
_internalMember(): void;
21+
// @alpha
22+
alphaMember(): void;
23+
undecoratedMember(): void;
24+
}
25+
26+
// @beta
27+
enum ConstEnum {
28+
// @internal
29+
_InternalMember = "_InternalMember",
30+
// @alpha
31+
AlphaMember = "AlphaMember",
32+
BetaMember2 = "BetaMember2"
33+
}
34+
1735
// WARNING: Unsupported export "N2" Currently the "namespace" block only supports constant variables.
1836
// WARNING: Unsupported export "N3" Currently the "namespace" block only supports constant variables.
1937
// @beta
@@ -33,7 +51,20 @@ class PublicClass {
3351
// @alpha
3452
alphaMember(): void;
3553
// @beta
54+
betaField: string;
55+
// @beta
3656
betaMember(): void;
3757
undecoratedMember(): void;
3858
}
3959

60+
// @beta
61+
enum RegularEnum {
62+
// @internal
63+
_InternalMember = 102,
64+
// @alpha
65+
AlphaMember = 101,
66+
BetaMember = 100
67+
}
68+
69+
// WARNING: Unsupported export: variableDeclaration
70+
// WARNING: Unsupported export: ExportedAlias

build-tests/api-extractor-test-04/src/BetaClass.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import { BetaInterface } from './BetaInterface';
5+
46
/**
57
* This is a beta class
68
* @beta
79
*/
8-
export class BetaClass {
10+
export class BetaClass implements BetaInterface {
911
/**
1012
* This is a comment
1113
*/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
/**
5+
* This is a beta interface
6+
* @beta
7+
*/
8+
export interface BetaInterface {
9+
/**
10+
* This is a comment
11+
*/
12+
undecoratedMember(): void;
13+
14+
/**
15+
* This is an alpha comment
16+
* @alpha
17+
*/
18+
alphaMember(): void;
19+
20+
/**
21+
* This is an internal member
22+
* @internal
23+
*/
24+
_internalMember(): void;
25+
}

0 commit comments

Comments
 (0)