Skip to content

Commit c036f68

Browse files
support api review
1 parent 363af5b commit c036f68

File tree

11 files changed

+61
-31
lines changed

11 files changed

+61
-31
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,20 @@ export class ApiReportGenerator {
303303
case ts.SyntaxKind.ExportKeyword:
304304
case ts.SyntaxKind.DefaultKeyword:
305305
case ts.SyntaxKind.DeclareKeyword:
306+
if (astDeclaration.parent) {
307+
// Keep it as is for nested declarations.
308+
break;
309+
}
310+
if (
311+
ts.isModuleDeclaration(astDeclaration.declaration) &&
312+
!astDeclaration.declaration.modifiers?.includes(span.node as ts.Modifier)
313+
) {
314+
// Keep it as is for nested declarations. Handle special cases inside namespace. e.g.:
315+
// - export declaration: "export {};", "export { A as B };"
316+
// - variable declaration: "export const a: number, b: number;"
317+
break;
318+
}
319+
306320
// Delete any explicit "export" or "declare" keywords -- we will re-add them below
307321
span.modification.skipAll();
308322
break;
@@ -314,6 +328,11 @@ export class ApiReportGenerator {
314328
case ts.SyntaxKind.ModuleKeyword:
315329
case ts.SyntaxKind.TypeKeyword:
316330
case ts.SyntaxKind.FunctionKeyword:
331+
if (astDeclaration.parent) {
332+
// Keep it as is for nested declarations
333+
break;
334+
}
335+
317336
// Replace the stuff we possibly deleted above
318337
let replacedModifiers: string = '';
319338

@@ -385,6 +404,17 @@ export class ApiReportGenerator {
385404
}
386405

387406
span.modification.prefix = referencedEntity.nameForEmit;
407+
408+
if (
409+
ts.isExportSpecifier(span.node.parent) &&
410+
!span.node.parent.propertyName &&
411+
span.node.getText().trim() !== referencedEntity.nameForEmit
412+
) {
413+
// For "export { A }" (inside namespace), if "A" is renamed (e.g. renamed to "B"),
414+
// we need to emit as "export { B as A }" instead
415+
span.modification.prefix += ' as ' + span.node.getText().trim();
416+
}
417+
388418
// For debugging:
389419
// span.modification.prefix += '/*R=FIX*/';
390420
} else {

build-tests/api-documenter-scenarios/etc/inheritedMembers/api-documenter-scenarios.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export type IInterfaceLikeTypeAlias = {
7676
// @public (undocumented)
7777
export namespace Namespace1 {
7878
// (undocumented)
79-
export class Class3 {
79+
class Class3 {
8080
someMethod(x: boolean | string): void;
8181
someOverload(x: boolean): void;
8282
someOverload(x: string): void;

build-tests/api-extractor-lib1-test/etc/api-extractor-lib1-test.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export interface Lib1Interface {
2727
// @public (undocumented)
2828
export namespace Lib1Namespace {
2929
// (undocumented)
30-
export namespace Inner {
30+
namespace Inner {
3131
// (undocumented)
32-
export class X {
32+
class X {
3333
}
3434
}
3535
// (undocumented)
36-
export class Y {
36+
class Y {
3737
}
3838
}
3939

build-tests/api-extractor-scenarios/etc/apiItemKinds/api-extractor-scenarios.api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ export namespace n1 {
4242
// (undocumented)
4343
export namespace n2 {
4444
// (undocumented)
45-
export class SomeClass3 {
45+
class SomeClass3 {
4646
}
4747
}
4848
// (undocumented)
49-
export class SomeClass1 {
49+
class SomeClass1 {
5050
}
5151
// (undocumented)
5252
export class SomeClass2 extends SomeClass1 {
5353
}
54-
{};
54+
export {};
5555
}
5656

5757
// @public (undocumented)
5858
export namespace n1 {
5959
// (undocumented)
60-
export class SomeClass4 {
60+
class SomeClass4 {
6161
}
6262
}
6363

build-tests/api-extractor-scenarios/etc/docReferences/api-extractor-scenarios.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function failWithMissingReference(): void;
1717
// @public (undocumented)
1818
export namespace MyNamespace {
1919
// (undocumented)
20-
export class MyClass {
20+
class MyClass {
2121
// @beta
2222
myMethod(x: number): number;
2323
}

build-tests/api-extractor-scenarios/etc/docReferences3/api-extractor-scenarios.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// @public (undocumented)
88
export namespace A {
99
// (undocumented)
10-
export class B {
10+
class B {
1111
// (undocumented)
1212
myMethod(): void;
1313
}

build-tests/api-extractor-scenarios/etc/includeForgottenExports/api-extractor-scenarios.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ export function someFunction7(): AnotherDuplicateName_2;
8282
// @public (undocumented)
8383
export namespace SomeNamespace1 {
8484
// (undocumented)
85-
export class ForgottenExport3 {
85+
class ForgottenExport3 {
8686
}
8787
// (undocumented)
8888
export function someFunction3(): ForgottenExport3;
89-
{};
89+
export {};
9090
}
9191

9292
// (No @packageDocumentation comment for this package)

build-tests/api-extractor-scenarios/etc/mergedDeclarations/api-extractor-scenarios.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ export interface MergedInterfaces {
4545
// @public (undocumented)
4646
export namespace MergedNamespaces {
4747
// (undocumented)
48-
export class SomeClass {
48+
class SomeClass {
4949
}
5050
}
5151

5252
// @public (undocumented)
5353
export namespace MergedNamespaces {
5454
// (undocumented)
55-
export class AnotherClass {
55+
class AnotherClass {
5656
}
5757
}
5858

build-tests/api-extractor-scenarios/etc/namespaceDeclaration/api-extractor-scenarios.api.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
// @public (undocumented)
88
export namespace AllExportedNS {
99
// (undocumented)
10-
export class ExportedClass {
10+
class ExportedClass {
1111
}
1212
// (undocumented)
13-
export interface ExportedInterface {
13+
interface ExportedInterface {
1414
}
1515
}
1616

@@ -20,7 +20,7 @@ export class FinalRenamedClass {
2020

2121
// @public (undocumented)
2222
export namespace PartalExportedNS {
23-
const // (undocumented)
23+
export const // (undocumented)
2424
var1 = 1, // (undocumented)
2525
var2 = 2;
2626
// (undocumented)
@@ -29,15 +29,15 @@ export namespace PartalExportedNS {
2929
prop: UnexportedClass;
3030
}
3131
// (undocumented)
32-
export interface UnexportedClass {
32+
interface UnexportedClass {
3333
}
34-
{};
34+
export {};
3535
}
3636

3737
// @public (undocumented)
3838
export namespace ReexportNS {
39-
{ FinalRenamedClass };
40-
{ FinalRenamedClass as RenamedClass3 };
39+
export { FinalRenamedClass as RenamedClass };
40+
export { FinalRenamedClass as RenamedClass3 };
4141
}
4242

4343
// (No @packageDocumentation comment for this package)

build-tests/api-extractor-scenarios/etc/referenceTokens/api-extractor-scenarios.api.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ export namespace n1 {
1313
// (undocumented)
1414
export namespace n3 {
1515
// (undocumented)
16-
export function someFunction3(): n2.n3.SomeType3;
16+
function someFunction3(): n2.n3.SomeType3;
1717
// (undocumented)
18-
export type SomeType3 = number;
18+
type SomeType3 = number;
1919
}
2020
// (undocumented)
2121
export function someFunction2(): SomeType2;
2222
// (undocumented)
23-
export type SomeType2 = number;
24-
{};
23+
type SomeType2 = number;
24+
export {};
2525
}
2626
// (undocumented)
2727
export function someFunction1(): SomeType1;
2828
// (undocumented)
29-
export type SomeType1 = number;
30-
{};
29+
type SomeType1 = number;
30+
export {};
3131
}
3232

3333
// @public (undocumented)

0 commit comments

Comments
 (0)