Skip to content

Commit aef3ec9

Browse files
authored
Merge pull request microsoft#924 from Microsoft/pgonzal/ae-symbol-rollups
[api-extractor] Fix an issue where EcmaScript symbols weren't being emitted in .d.ts rollups
2 parents 42db5fb + 43d208d commit aef3ec9

12 files changed

Lines changed: 94 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export class AstSymbolTable {
197197
// is this a reference to another AstSymbol?
198198
case ts.SyntaxKind.TypeReference: // general type references
199199
case ts.SyntaxKind.ExpressionWithTypeArguments: // special case for e.g. the "extends" keyword
200+
case ts.SyntaxKind.ComputedPropertyName: // used for EcmaScript "symbols", e.g. "[toPrimitive]".
200201
{
201202
// Sometimes the type reference will involve multiple identifiers, e.g. "a.b.C".
202203
// In this case, we only need to worry about importing the first identifier,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ export class DtsRollupGenerator {
346346
const listPrefix: string = list.getSourceFile().text
347347
.substring(list.getStart(), list.declarations[0].getStart());
348348
span.modification.prefix = 'declare ' + listPrefix + span.modification.prefix;
349+
350+
if (dtsEntry.exported) {
351+
span.modification.prefix = 'export ' + span.modification.prefix;
352+
}
353+
349354
span.modification.suffix = ';';
350355
}
351356
break;

build-tests/api-extractor-test-01/dist/beta/api-extractor-test-01.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ export declare class AmbientConsumer {
7171
export declare class ClassExportedAsDefault {
7272
}
7373

74+
/**
75+
* @public
76+
*/
77+
export declare class ClassWithSymbols {
78+
readonly [unexportedCustomSymbol]: number;
79+
readonly [locallyExportedCustomSymbol]: string;
80+
[fullyExportedCustomSymbol](): void;
81+
}
82+
7483
/**
7584
* This class illustrates some cases involving type literals.
7685
* @public
@@ -129,6 +138,8 @@ export declare class ForgottenExportConsumer3 {
129138
test2(): IForgottenDirectDependency | undefined;
130139
}
131140

141+
export declare const fullyExportedCustomSymbol: unique symbol;
142+
132143
/**
133144
* This class is directly consumed by ForgottenExportConsumer3.
134145
*/
@@ -183,6 +194,8 @@ export declare interface IInterfaceAsDefaultExport {
183194
export declare interface ISimpleInterface {
184195
}
185196

197+
declare const locallyExportedCustomSymbol: unique symbol;
198+
186199
/**
187200
* This class gets aliased twice before being exported from the package.
188201
* @public
@@ -211,6 +224,8 @@ export declare class TypeReferencesInAedoc {
211224
getValue3(arg1: TypeReferencesInAedoc): TypeReferencesInAedoc;
212225
}
213226

227+
declare const unexportedCustomSymbol: unique symbol;
228+
214229
/**
215230
* Example decorator
216231
* @public

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ export declare class AmbientConsumer {
7171
export declare class ClassExportedAsDefault {
7272
}
7373

74+
/**
75+
* @public
76+
*/
77+
export declare class ClassWithSymbols {
78+
readonly [unexportedCustomSymbol]: number;
79+
readonly [locallyExportedCustomSymbol]: string;
80+
[fullyExportedCustomSymbol](): void;
81+
}
82+
7483
/**
7584
* This class illustrates some cases involving type literals.
7685
* @public
@@ -129,6 +138,8 @@ export declare class ForgottenExportConsumer3 {
129138
test2(): IForgottenDirectDependency | undefined;
130139
}
131140

141+
export declare const fullyExportedCustomSymbol: unique symbol;
142+
132143
/**
133144
* This class is directly consumed by ForgottenExportConsumer3.
134145
*/
@@ -203,6 +214,8 @@ export declare interface IMergedInterfaceReferencee {
203214
export declare interface ISimpleInterface {
204215
}
205216

217+
declare const locallyExportedCustomSymbol: unique symbol;
218+
206219
/**
207220
* This class gets aliased twice before being exported from the package.
208221
* @public
@@ -231,6 +244,8 @@ export declare class TypeReferencesInAedoc {
231244
getValue3(arg1: TypeReferencesInAedoc): TypeReferencesInAedoc;
232245
}
233246

247+
declare const unexportedCustomSymbol: unique symbol;
248+
234249
/**
235250
* Example decorator
236251
* @public

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ export declare class AmbientConsumer {
7171
export declare class ClassExportedAsDefault {
7272
}
7373

74+
/**
75+
* @public
76+
*/
77+
export declare class ClassWithSymbols {
78+
readonly [unexportedCustomSymbol]: number;
79+
readonly [locallyExportedCustomSymbol]: string;
80+
[fullyExportedCustomSymbol](): void;
81+
}
82+
7483
/**
7584
* This class illustrates some cases involving type literals.
7685
* @public
@@ -122,6 +131,8 @@ export declare class ForgottenExportConsumer2 {
122131

123132
/* Excluded from this release type: ForgottenExportConsumer3 */
124133

134+
export declare const fullyExportedCustomSymbol: unique symbol;
135+
125136
/**
126137
* This class is directly consumed by ForgottenExportConsumer3.
127138
*/
@@ -176,6 +187,8 @@ export declare interface IInterfaceAsDefaultExport {
176187
export declare interface ISimpleInterface {
177188
}
178189

190+
declare const locallyExportedCustomSymbol: unique symbol;
191+
179192
/**
180193
* This class gets aliased twice before being exported from the package.
181194
* @public
@@ -204,6 +217,8 @@ export declare class TypeReferencesInAedoc {
204217
getValue3(arg1: TypeReferencesInAedoc): TypeReferencesInAedoc;
205218
}
206219

220+
declare const unexportedCustomSymbol: unique symbol;
221+
207222
/**
208223
* Example decorator
209224
* @public

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class AmbientConsumer {
2929
class ClassExportedAsDefault {
3030
}
3131

32+
// @public (undocumented)
33+
class ClassWithSymbols {
34+
// (undocumented)
35+
readonly __computed: number;
36+
}
37+
3238
// @public
3339
class ClassWithTypeLiterals {
3440
method1(vector: {
@@ -112,3 +118,4 @@ class TypeReferencesInAedoc {
112118
// @public
113119
export function virtual(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): void;
114120

121+
// WARNING: Unsupported export: fullyExportedCustomSymbol
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
const unexportedCustomSymbol: unique symbol = Symbol('unexportedCustomSymbol');
5+
export const locallyExportedCustomSymbol: unique symbol = Symbol('locallyExportedCustomSymbol');
6+
export const fullyExportedCustomSymbol: unique symbol = Symbol('fullyExportedCustomSymbol');
7+
8+
/**
9+
* @public
10+
*/
11+
export class ClassWithSymbols {
12+
public readonly [unexportedCustomSymbol]: number = 123;
13+
14+
public get [locallyExportedCustomSymbol](): string {
15+
return 'hello';
16+
}
17+
18+
public [fullyExportedCustomSymbol](): void {
19+
}
20+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export {
9292
default as ClassExportedAsDefault
9393
} from './DefaultExportEdgeCase';
9494

95+
export { ClassWithSymbols, fullyExportedCustomSymbol } from './EcmaScriptSymbols';
96+
9597
export { ForgottenExportConsumer1 } from './ForgottenExportConsumer1';
9698
export { ForgottenExportConsumer2 } from './ForgottenExportConsumer2';
9799
export { ForgottenExportConsumer3 } from './ForgottenExportConsumer3';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ export declare enum RegularEnum {
121121
/* Excluded from this release type: _InternalMember */
122122
}
123123

124-
declare const variableDeclaration: string;
124+
export declare const variableDeclaration: string;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,4 @@ export declare enum RegularEnum {
224224
_InternalMember = 102
225225
}
226226

227-
declare const variableDeclaration: string;
227+
export declare const variableDeclaration: string;

0 commit comments

Comments
 (0)