Skip to content

Commit 0d9674e

Browse files
authored
Merge pull request microsoft#568 from Microsoft/pgonzal/merged-declaration
[api-extractor] Fix a bug with handling of merged declarations
2 parents 6eb13d7 + 759bc49 commit 0d9674e

12 files changed

Lines changed: 144 additions & 33 deletions

File tree

‎apps/api-extractor/src/api/ApiItem.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,3 @@ export type ApiMember = IApiProperty | IApiMethod | IApiConstructor;
401401
*/
402402
export type ApiItem = IApiProperty | ApiMember | IApiFunction | IApiConstructor |
403403
IApiClass | IApiEnum | IApiEnumMember | IApiInterface | IApiNamespace | IApiPackage;
404-
405-
/**
406-
* Describes a return type and description of the return type
407-
* that is given in documentation comments.
408-
*
409-
* @alpha
410-
*/
411-
export interface IApiReturnValue {
412-
type: string;
413-
description: MarkupBasicElement[];
414-
}

‎apps/api-extractor/src/generators/packageTypings/AstDeclaration.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ export class AstDeclaration {
9494
throw new Error('Program Bug: Invalid call to notifyChildAttach()');
9595
}
9696

97+
if (this.astSymbol.analyzed) {
98+
throw new Error('Program Bug: _notifyChildAttach() called after analysis is already complete');
99+
}
100+
97101
this._analyzedChildren.push(child);
98102
}
99103

‎apps/api-extractor/src/generators/packageTypings/AstSymbol.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export class AstSymbol {
5959

6060
private readonly _rootAstSymbol: AstSymbol;
6161

62+
// This flag is unused if this is not the root symbol.
63+
// Being "analyzed" is a property of the root symbol.
6264
private _analyzed: boolean = false;
6365

6466
public constructor(parameters: IAstSymbolParameters) {
@@ -83,9 +85,12 @@ export class AstSymbol {
8385
/**
8486
* Returns true if the AstSymbolTable.analyze() was called for this object.
8587
* See that function for details.
88+
* @remarks
89+
* AstSymbolTable.analyze() is always performed on the root AstSymbol. This function
90+
* returns true if-and-only-if the root symbol was analyzed.
8691
*/
8792
public get analyzed(): boolean {
88-
return this._analyzed;
93+
return this.rootAstSymbol._analyzed;
8994
}
9095

9196
/**
@@ -108,6 +113,9 @@ export class AstSymbol {
108113
* @internal
109114
*/
110115
public _notifyDeclarationAttach(astDeclaration: AstDeclaration): void {
116+
if (this.analyzed) {
117+
throw new Error('Program Bug: _notifyDeclarationAttach() called after analysis is already complete');
118+
}
111119
this._astDeclarations.push(astDeclaration);
112120
}
113121

@@ -117,6 +125,9 @@ export class AstSymbol {
117125
* @internal
118126
*/
119127
public _notifyAnalyzed(): void {
128+
if (this.rootAstSymbol !== this) {
129+
throw new Error('Program Bug: _notifyAnalyzed() called for an AstSymbol which is not the root');
130+
}
120131
this._analyzed = true;
121132
}
122133

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class AstSymbolTable {
139139
this._analyzeChildTree(astDeclaration.declaration, astDeclaration);
140140
}
141141

142-
astSymbol._notifyAnalyzed();
142+
rootAstSymbol._notifyAnalyzed();
143143

144144
if (!astSymbol.astImport) {
145145
// If this symbol is not imported, then we also analyze any referencedAstSymbols
@@ -224,10 +224,6 @@ export class AstSymbolTable {
224224
for (const childNode of node.getChildren()) {
225225
this._analyzeChildTree(childNode, newGoverningAstDeclaration || governingAstDeclaration);
226226
}
227-
228-
if (newGoverningAstDeclaration) {
229-
newGoverningAstDeclaration.astSymbol._notifyAnalyzed();
230-
}
231227
}
232228

233229
// tslint:disable-next-line:no-unused-variable

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,40 @@ export declare interface IInterfaceAsDefaultExport {
172172
member: string;
173173
}
174174

175+
/**
176+
* IMergedInterface instance 1.
177+
* @alpha
178+
*/
179+
export declare interface IMergedInterface {
180+
type: string;
181+
reference: IMergedInterfaceReferencee;
182+
}
183+
184+
/**
185+
* IMergedInterface instance 2.
186+
* @alpha
187+
*/
188+
export declare interface IMergedInterface {
189+
type: string;
190+
reference: IMergedInterfaceReferencee;
191+
}
192+
193+
/**
194+
* @alpha
195+
*/
196+
export declare interface IMergedInterfaceReferencee {
197+
}
198+
199+
/**
200+
* api-extractor-test-01
201+
*
202+
* @remarks
203+
* This library is consumed by api-extractor-test-02 and api-extractor-test-03.
204+
* It tests the basic types of definitions, and all the weird cases for following
205+
* chains of type aliases.
206+
*
207+
* @packagedocumentation
208+
*/
175209
/**
176210
* A simple, normal definition
177211
* @public

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ export declare interface IInterfaceAsDefaultExport {
172172
member: string;
173173
}
174174

175+
// Removed for this release type: IMergedInterface
176+
177+
// Removed for this release type: IMergedInterfaceReferencee
178+
179+
/**
180+
* api-extractor-test-01
181+
*
182+
* @remarks
183+
* This library is consumed by api-extractor-test-02 and api-extractor-test-03.
184+
* It tests the basic types of definitions, and all the weird cases for following
185+
* chains of type aliases.
186+
*
187+
* @packagedocumentation
188+
*/
175189
/**
176190
* A simple, normal definition
177191
* @public

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ export declare interface IInterfaceAsDefaultExport {
165165
member: string;
166166
}
167167

168+
// Removed for this release type: IMergedInterface
169+
170+
// Removed for this release type: IMergedInterfaceReferencee
171+
172+
/**
173+
* api-extractor-test-01
174+
*
175+
* @remarks
176+
* This library is consumed by api-extractor-test-02 and api-extractor-test-03.
177+
* It tests the basic types of definitions, and all the weird cases for following
178+
* chains of type aliases.
179+
*
180+
* @packagedocumentation
181+
*/
168182
/**
169183
* A simple, normal definition
170184
* @public

‎build-tests/api-extractor-test-01/etc/api-extractor-test-01.api.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ interface IInterfaceAsDefaultExport {
8787
member: string;
8888
}
8989

90+
// @alpha
91+
interface IMergedInterface {
92+
// (undocumented)
93+
reference: IMergedInterfaceReferencee;
94+
// (undocumented)
95+
type: string;
96+
}
97+
98+
// @alpha (undocumented)
99+
interface IMergedInterfaceReferencee {
100+
}
101+
90102
// @public
91103
interface ISimpleInterface {
92104
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
* @alpha
6+
*/
7+
export interface IMergedInterfaceReferencee {
8+
}
9+
10+
/**
11+
* IMergedInterface instance 1.
12+
* @alpha
13+
*/
14+
export interface IMergedInterface {
15+
type: string;
16+
reference: IMergedInterfaceReferencee;
17+
}
18+
19+
/**
20+
* IMergedInterface instance 2.
21+
* @alpha
22+
*/
23+
export interface IMergedInterface {
24+
type: string;
25+
reference: IMergedInterfaceReferencee;
26+
}

‎build-tests/api-extractor-test-01/src/index.ts‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
* @packagedocumentation
1313
*/
1414

15-
/**
16-
* Test the alias-following logic: This class gets aliased twice before being
17-
* exported from the package.
18-
*/
19-
export { ReexportedClass1 as ReexportedClass } from './ReexportedClass1';
20-
2115
/**
2216
* A simple, normal definition
2317
* @public
@@ -86,20 +80,28 @@ export class DecoratorTest {
8680
}
8781
}
8882

89-
export { ForgottenExportConsumer1 } from './ForgottenExportConsumer1';
90-
export { ForgottenExportConsumer2 } from './ForgottenExportConsumer2';
91-
export { ForgottenExportConsumer3 } from './ForgottenExportConsumer3';
92-
93-
export { default as IInterfaceAsDefaultExport } from './IInterfaceAsDefaultExport';
94-
9583
export { default as AbstractClass } from './AbstractClass';
9684
export { default as AbstractClass2, AbstractClass3 } from './AbstractClass2';
9785

86+
export { ClassWithTypeLiterals } from './ClassWithTypeLiterals';
87+
88+
export * from './DeclarationMerging';
89+
9890
export {
9991
DefaultExportEdgeCase,
10092
default as ClassExportedAsDefault
10193
} from './DefaultExportEdgeCase';
10294

103-
export { TypeReferencesInAedoc as _TypeReferencesInAedoc } from './TypeReferencesInAedoc';
95+
export { ForgottenExportConsumer1 } from './ForgottenExportConsumer1';
96+
export { ForgottenExportConsumer2 } from './ForgottenExportConsumer2';
97+
export { ForgottenExportConsumer3 } from './ForgottenExportConsumer3';
10498

105-
export { ClassWithTypeLiterals } from './ClassWithTypeLiterals';
99+
export { default as IInterfaceAsDefaultExport } from './IInterfaceAsDefaultExport';
100+
101+
/**
102+
* Test the alias-following logic: This class gets aliased twice before being
103+
* exported from the package.
104+
*/
105+
export { ReexportedClass1 as ReexportedClass } from './ReexportedClass1';
106+
107+
export { TypeReferencesInAedoc as _TypeReferencesInAedoc } from './TypeReferencesInAedoc';

0 commit comments

Comments
 (0)