@microsoft/api-extractor 7.29.5 → 7.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rollup.d.ts +26 -2
- package/lib/analyzer/AstNamespaceImport.d.ts +5 -0
- package/lib/analyzer/AstNamespaceImport.d.ts.map +1 -1
- package/lib/analyzer/AstNamespaceImport.js +1 -0
- package/lib/analyzer/AstNamespaceImport.js.map +1 -1
- package/lib/analyzer/ExportAnalyzer.d.ts.map +1 -1
- package/lib/analyzer/ExportAnalyzer.js +2 -1
- package/lib/analyzer/ExportAnalyzer.js.map +1 -1
- package/lib/api/ExtractorConfig.d.ts +4 -0
- package/lib/api/ExtractorConfig.d.ts.map +1 -1
- package/lib/api/ExtractorConfig.js +8 -0
- package/lib/api/ExtractorConfig.js.map +1 -1
- package/lib/api/ExtractorMessageId.d.ts +1 -1
- package/lib/api/ExtractorMessageId.js.map +1 -1
- package/lib/api/IConfigFile.d.ts +21 -1
- package/lib/api/IConfigFile.d.ts.map +1 -1
- package/lib/api/IConfigFile.js.map +1 -1
- package/lib/collector/Collector.d.ts +7 -1
- package/lib/collector/Collector.d.ts.map +1 -1
- package/lib/collector/Collector.js +57 -32
- package/lib/collector/Collector.js.map +1 -1
- package/lib/collector/CollectorEntity.d.ts +60 -27
- package/lib/collector/CollectorEntity.d.ts.map +1 -1
- package/lib/collector/CollectorEntity.js +91 -28
- package/lib/collector/CollectorEntity.js.map +1 -1
- package/lib/enhancers/DocCommentEnhancer.d.ts.map +1 -1
- package/lib/enhancers/DocCommentEnhancer.js +3 -1
- package/lib/enhancers/DocCommentEnhancer.js.map +1 -1
- package/lib/enhancers/ValidationEnhancer.d.ts.map +1 -1
- package/lib/enhancers/ValidationEnhancer.js +7 -5
- package/lib/enhancers/ValidationEnhancer.js.map +1 -1
- package/lib/generators/ApiModelGenerator.d.ts +1 -1
- package/lib/generators/ApiModelGenerator.d.ts.map +1 -1
- package/lib/generators/ApiModelGenerator.js +100 -75
- package/lib/generators/ApiModelGenerator.js.map +1 -1
- package/lib/generators/ApiReportGenerator.js +2 -2
- package/lib/generators/ApiReportGenerator.js.map +1 -1
- package/lib/generators/DeclarationReferenceGenerator.d.ts +4 -8
- package/lib/generators/DeclarationReferenceGenerator.d.ts.map +1 -1
- package/lib/generators/DeclarationReferenceGenerator.js +77 -70
- package/lib/generators/DeclarationReferenceGenerator.js.map +1 -1
- package/lib/schemas/api-extractor-defaults.json +4 -2
- package/lib/schemas/api-extractor-template.json +24 -5
- package/lib/schemas/api-extractor.schema.json +11 -1
- package/package.json +3 -4
|
@@ -32,19 +32,16 @@ const DeclarationReference_1 = require("@microsoft/tsdoc/lib-commonjs/beta/Decla
|
|
|
32
32
|
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
33
33
|
const TypeScriptHelpers_1 = require("../analyzer/TypeScriptHelpers");
|
|
34
34
|
const TypeScriptInternals_1 = require("../analyzer/TypeScriptInternals");
|
|
35
|
+
const AstNamespaceImport_1 = require("../analyzer/AstNamespaceImport");
|
|
35
36
|
class DeclarationReferenceGenerator {
|
|
36
|
-
constructor(
|
|
37
|
-
this.
|
|
38
|
-
this._workingPackageName = workingPackageName;
|
|
39
|
-
this._program = program;
|
|
40
|
-
this._typeChecker = typeChecker;
|
|
41
|
-
this._bundledPackageNames = bundledPackageNames;
|
|
37
|
+
constructor(collector) {
|
|
38
|
+
this._collector = collector;
|
|
42
39
|
}
|
|
43
40
|
/**
|
|
44
41
|
* Gets the UID for a TypeScript Identifier that references a type.
|
|
45
42
|
*/
|
|
46
43
|
getDeclarationReferenceForIdentifier(node) {
|
|
47
|
-
const symbol = this.
|
|
44
|
+
const symbol = this._collector.typeChecker.getSymbolAtLocation(node);
|
|
48
45
|
if (symbol !== undefined) {
|
|
49
46
|
const isExpression = DeclarationReferenceGenerator._isInExpressionContext(node);
|
|
50
47
|
return (this.getDeclarationReferenceForSymbol(symbol, isExpression ? ts.SymbolFlags.Value : ts.SymbolFlags.Type) ||
|
|
@@ -80,59 +77,44 @@ class DeclarationReferenceGenerator {
|
|
|
80
77
|
right.valueDeclaration &&
|
|
81
78
|
left.valueDeclaration === right.valueDeclaration));
|
|
82
79
|
}
|
|
83
|
-
|
|
80
|
+
_getNavigationToSymbol(symbol) {
|
|
81
|
+
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
82
|
+
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
84
83
|
const parent = TypeScriptInternals_1.TypeScriptInternals.getSymbolParent(symbol);
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
// If it's global or from an external library, then use either Members or Exports. It's not possible for
|
|
85
|
+
// global symbols or external library symbols to be Locals.
|
|
86
|
+
const isGlobal = !!sourceFile && !ts.isExternalModule(sourceFile);
|
|
87
|
+
const isFromExternalLibrary = !!sourceFile && this._collector.program.isSourceFileFromExternalLibrary(sourceFile);
|
|
88
|
+
if (isGlobal || isFromExternalLibrary) {
|
|
89
|
+
if (parent &&
|
|
90
|
+
parent.members &&
|
|
92
91
|
DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)) {
|
|
93
92
|
return "#" /* Navigation.Members */;
|
|
94
93
|
}
|
|
95
|
-
|
|
96
|
-
DeclarationReferenceGenerator._isSameSymbol(parent.globalExports.get(symbol.escapedName), symbol)) {
|
|
97
|
-
return 'global';
|
|
98
|
-
}
|
|
94
|
+
return "." /* Navigation.Exports */;
|
|
99
95
|
}
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
96
|
+
// Otherwise, this symbol is from the current package. If we've found an associated consumable
|
|
97
|
+
// `CollectorEntity`, then use Exports. We use `consumable` here instead of `exported` because
|
|
98
|
+
// if the symbol is exported from a non-consumable `AstNamespaceImport`, we don't want to use
|
|
99
|
+
// Exports. We should use Locals instead.
|
|
100
|
+
const entity = this._collector.tryGetEntityForSymbol(symbol);
|
|
101
|
+
if (entity === null || entity === void 0 ? void 0 : entity.consumable) {
|
|
102
|
+
return "." /* Navigation.Exports */;
|
|
103
|
+
}
|
|
104
|
+
// If its parent symbol is not a source file, then use either Exports or Members. If the parent symbol
|
|
105
|
+
// is a source file, but it wasn't exported from the package entry point (in the check above), then the
|
|
106
|
+
// symbol is a local, so fall through below.
|
|
107
|
+
if (parent && !DeclarationReferenceGenerator._isExternalModuleSymbol(parent)) {
|
|
108
|
+
if (parent.members &&
|
|
109
|
+
DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)) {
|
|
113
110
|
return "#" /* Navigation.Members */;
|
|
114
111
|
}
|
|
115
|
-
|
|
116
|
-
// enum members are exports
|
|
117
|
-
return "." /* Navigation.Exports */;
|
|
118
|
-
}
|
|
119
|
-
if (ts.isExportSpecifier(declaration) ||
|
|
120
|
-
ts.isExportAssignment(declaration) ||
|
|
121
|
-
ts.isExportSpecifier(declaration) ||
|
|
122
|
-
ts.isExportDeclaration(declaration) ||
|
|
123
|
-
ts.isNamedExports(declaration)) {
|
|
124
|
-
return "." /* Navigation.Exports */;
|
|
125
|
-
}
|
|
126
|
-
// declarations are exports if they have an `export` modifier.
|
|
127
|
-
if (ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Export) {
|
|
128
|
-
return "." /* Navigation.Exports */;
|
|
129
|
-
}
|
|
130
|
-
if (ts.isSourceFile(declaration.parent) && !ts.isExternalModule(declaration.parent)) {
|
|
131
|
-
// declarations in a source file are global if the source file is not a module.
|
|
132
|
-
return 'global';
|
|
133
|
-
}
|
|
112
|
+
return "." /* Navigation.Exports */;
|
|
134
113
|
}
|
|
135
|
-
//
|
|
114
|
+
// Otherwise, we have a local symbol, so use a Locals navigation. These are either:
|
|
115
|
+
//
|
|
116
|
+
// 1. Symbols that are exported from a file module but not the package entry point.
|
|
117
|
+
// 2. Symbols that are not exported from their parent module.
|
|
136
118
|
return "~" /* Navigation.Locals */;
|
|
137
119
|
}
|
|
138
120
|
static _getMeaningOfSymbol(symbol, meaning) {
|
|
@@ -184,19 +166,24 @@ class DeclarationReferenceGenerator {
|
|
|
184
166
|
return undefined;
|
|
185
167
|
}
|
|
186
168
|
_symbolToDeclarationReference(symbol, meaning, includeModuleSymbols) {
|
|
169
|
+
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
170
|
+
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
187
171
|
let followedSymbol = symbol;
|
|
188
172
|
if (followedSymbol.flags & ts.SymbolFlags.ExportValue) {
|
|
189
|
-
followedSymbol = this.
|
|
173
|
+
followedSymbol = this._collector.typeChecker.getExportSymbolOfSymbol(followedSymbol);
|
|
190
174
|
}
|
|
191
175
|
if (followedSymbol.flags & ts.SymbolFlags.Alias) {
|
|
192
|
-
followedSymbol = this.
|
|
176
|
+
followedSymbol = this._collector.typeChecker.getAliasedSymbol(followedSymbol);
|
|
177
|
+
// Without this logic, we end up following the symbol `ns` in `import * as ns from './file'` to
|
|
178
|
+
// the actual file `file.ts`. We don't want to do this, so revert to the original symbol.
|
|
179
|
+
if (followedSymbol.flags & ts.SymbolFlags.ValueModule) {
|
|
180
|
+
followedSymbol = symbol;
|
|
181
|
+
}
|
|
193
182
|
}
|
|
194
183
|
if (DeclarationReferenceGenerator._isExternalModuleSymbol(followedSymbol)) {
|
|
195
184
|
if (!includeModuleSymbols) {
|
|
196
185
|
return undefined;
|
|
197
186
|
}
|
|
198
|
-
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
199
|
-
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
200
187
|
return new DeclarationReference_1.DeclarationReference(this._sourceFileToModuleSource(sourceFile));
|
|
201
188
|
}
|
|
202
189
|
// Do not generate a declaration reference for a type parameter.
|
|
@@ -208,6 +195,10 @@ class DeclarationReferenceGenerator {
|
|
|
208
195
|
return undefined;
|
|
209
196
|
}
|
|
210
197
|
let localName = followedSymbol.name;
|
|
198
|
+
const entity = this._collector.tryGetEntityForSymbol(followedSymbol);
|
|
199
|
+
if (entity === null || entity === void 0 ? void 0 : entity.nameForEmit) {
|
|
200
|
+
localName = entity.nameForEmit;
|
|
201
|
+
}
|
|
211
202
|
if (followedSymbol.escapedName === ts.InternalSymbolName.Constructor) {
|
|
212
203
|
localName = 'constructor';
|
|
213
204
|
}
|
|
@@ -231,12 +222,10 @@ class DeclarationReferenceGenerator {
|
|
|
231
222
|
}
|
|
232
223
|
}
|
|
233
224
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
navigation = "." /* Navigation.Exports */;
|
|
225
|
+
const navigation = this._getNavigationToSymbol(followedSymbol);
|
|
226
|
+
// If the symbol is a global, ensure the source is global.
|
|
227
|
+
if (sourceFile && !ts.isExternalModule(sourceFile) && parentRef.source !== DeclarationReference_1.GlobalSource.instance) {
|
|
228
|
+
parentRef = new DeclarationReference_1.DeclarationReference(DeclarationReference_1.GlobalSource.instance);
|
|
240
229
|
}
|
|
241
230
|
return parentRef
|
|
242
231
|
.addNavigationStep(navigation, localName)
|
|
@@ -245,7 +234,26 @@ class DeclarationReferenceGenerator {
|
|
|
245
234
|
_getParentReference(symbol) {
|
|
246
235
|
var _a;
|
|
247
236
|
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
248
|
-
|
|
237
|
+
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
238
|
+
// Note that it's possible for a symbol to be exported from an entry point as well as one or more
|
|
239
|
+
// namespaces. In that case, it's not clear what to choose as its parent. Today's logic is neither
|
|
240
|
+
// perfect nor particularly stable to API items being renamed and shuffled around.
|
|
241
|
+
const entity = this._collector.tryGetEntityForSymbol(symbol);
|
|
242
|
+
if (entity) {
|
|
243
|
+
if (entity.exportedFromEntryPoint) {
|
|
244
|
+
return new DeclarationReference_1.DeclarationReference(this._sourceFileToModuleSource(sourceFile));
|
|
245
|
+
}
|
|
246
|
+
const firstExportingConsumableParent = entity.getFirstExportingConsumableParent();
|
|
247
|
+
if (firstExportingConsumableParent &&
|
|
248
|
+
firstExportingConsumableParent.astEntity instanceof AstNamespaceImport_1.AstNamespaceImport) {
|
|
249
|
+
const parentSymbol = TypeScriptInternals_1.TypeScriptInternals.tryGetSymbolForDeclaration(firstExportingConsumableParent.astEntity.declaration, this._collector.typeChecker);
|
|
250
|
+
if (parentSymbol) {
|
|
251
|
+
return this._symbolToDeclarationReference(parentSymbol, parentSymbol.flags,
|
|
252
|
+
/*includeModuleSymbols*/ true);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// Next, try to find a parent symbol via the symbol tree.
|
|
249
257
|
const parentSymbol = TypeScriptInternals_1.TypeScriptInternals.getSymbolParent(symbol);
|
|
250
258
|
if (parentSymbol) {
|
|
251
259
|
return this._symbolToDeclarationReference(parentSymbol, parentSymbol.flags,
|
|
@@ -265,14 +273,13 @@ class DeclarationReferenceGenerator {
|
|
|
265
273
|
// but its reference still needs to be qualified with the parent reference for `n`.
|
|
266
274
|
const grandParent = (_a = declaration === null || declaration === void 0 ? void 0 : declaration.parent) === null || _a === void 0 ? void 0 : _a.parent;
|
|
267
275
|
if (grandParent && ts.isModuleDeclaration(grandParent)) {
|
|
268
|
-
const grandParentSymbol = TypeScriptInternals_1.TypeScriptInternals.tryGetSymbolForDeclaration(grandParent, this.
|
|
276
|
+
const grandParentSymbol = TypeScriptInternals_1.TypeScriptInternals.tryGetSymbolForDeclaration(grandParent, this._collector.typeChecker);
|
|
269
277
|
if (grandParentSymbol) {
|
|
270
278
|
return this._symbolToDeclarationReference(grandParentSymbol, grandParentSymbol.flags,
|
|
271
279
|
/*includeModuleSymbols*/ true);
|
|
272
280
|
}
|
|
273
281
|
}
|
|
274
282
|
// At this point, we have a local symbol in a module.
|
|
275
|
-
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
276
283
|
if (sourceFile && ts.isExternalModule(sourceFile)) {
|
|
277
284
|
return new DeclarationReference_1.DeclarationReference(this._sourceFileToModuleSource(sourceFile));
|
|
278
285
|
}
|
|
@@ -281,23 +288,23 @@ class DeclarationReferenceGenerator {
|
|
|
281
288
|
}
|
|
282
289
|
}
|
|
283
290
|
_getPackageName(sourceFile) {
|
|
284
|
-
if (this.
|
|
285
|
-
const packageJson = this.
|
|
291
|
+
if (this._collector.program.isSourceFileFromExternalLibrary(sourceFile)) {
|
|
292
|
+
const packageJson = this._collector.packageJsonLookup.tryLoadNodePackageJsonFor(sourceFile.fileName);
|
|
286
293
|
if (packageJson && packageJson.name) {
|
|
287
294
|
return packageJson.name;
|
|
288
295
|
}
|
|
289
296
|
return DeclarationReferenceGenerator.unknownReference;
|
|
290
297
|
}
|
|
291
|
-
return this.
|
|
298
|
+
return this._collector.workingPackage.name;
|
|
292
299
|
}
|
|
293
300
|
_sourceFileToModuleSource(sourceFile) {
|
|
294
301
|
if (sourceFile && ts.isExternalModule(sourceFile)) {
|
|
295
302
|
const packageName = this._getPackageName(sourceFile);
|
|
296
|
-
if (this.
|
|
303
|
+
if (this._collector.bundledPackageNames.has(packageName)) {
|
|
297
304
|
// The api-extractor.json config file has a "bundledPackages" setting, which causes imports from
|
|
298
305
|
// certain NPM packages to be treated as part of the working project. In this case, we need to
|
|
299
306
|
// substitute the working package name.
|
|
300
|
-
return new DeclarationReference_1.ModuleSource(this.
|
|
307
|
+
return new DeclarationReference_1.ModuleSource(this._collector.workingPackage.name);
|
|
301
308
|
}
|
|
302
309
|
else {
|
|
303
310
|
return new DeclarationReference_1.ModuleSource(packageName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeclarationReferenceGenerator.js","sourceRoot":"","sources":["../../src/generators/DeclarationReferenceGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+BAA+B;AAC/B,+CAAiC;AACjC,kGAMiE;AACjE,oEAAkG;AAClG,qEAAkE;AAClE,yEAAsE;AAEtE,MAAa,6BAA6B;IASxC,YACE,iBAAoC,EACpC,kBAA0B,EAC1B,OAAmB,EACnB,WAA2B,EAC3B,mBAAwC;QAExC,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAC5C,IAAI,CAAC,mBAAmB,GAAG,kBAAkB,CAAC;QAC9C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;IAClD,CAAC;IAED;;OAEG;IACI,oCAAoC,CAAC,IAAmB;QAC7D,MAAM,MAAM,GAA0B,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAClF,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,MAAM,YAAY,GAAY,6BAA6B,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;YACzF,OAAO,CACL,IAAI,CAAC,gCAAgC,CACnC,MAAM,EACN,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAC1D;gBACD,IAAI,CAAC,gCAAgC,CACnC,MAAM,EACN,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAC1D;gBACD,IAAI,CAAC,gCAAgC,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CACxE,CA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AI,EAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE;YACjD,MAAM,WAAW,GAAW,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;YAE7D,IAAI,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;gBAC9C,gGAAgG;gBAChG,+FAA+F;gBAC/F,uCAAuC;gBACvC,OAAO,IAAI,mCAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;aACnD;iBAAM;gBACL,OAAO,IAAI,mCAAY,CAAC,WAAW,CAAC,CAAC;aACtC;SACF;QACD,OAAO,mCAAY,CAAC,QAAQ,CAAC;IAC/B,CAAC;;AA3VH,sEA4VC;AA3VwB,8CAAgB,GAAW,GAAG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/* eslint-disable no-bitwise */\nimport * as ts from 'typescript';\nimport {\n DeclarationReference,\n ModuleSource,\n GlobalSource,\n Navigation,\n Meaning\n} from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';\nimport { PackageJsonLookup, INodePackageJson, InternalError } from '@rushstack/node-core-library';\nimport { TypeScriptHelpers } from '../analyzer/TypeScriptHelpers';\nimport { TypeScriptInternals } from '../analyzer/TypeScriptInternals';\n\nexport class DeclarationReferenceGenerator {\n public static readonly unknownReference: string = '?';\n\n private _packageJsonLookup: PackageJsonLookup;\n private _workingPackageName: string;\n private _program: ts.Program;\n private _typeChecker: ts.TypeChecker;\n private _bundledPackageNames: ReadonlySet<string>;\n\n public constructor(\n packageJsonLookup: PackageJsonLookup,\n workingPackageName: string,\n program: ts.Program,\n typeChecker: ts.TypeChecker,\n bundledPackageNames: ReadonlySet<string>\n ) {\n this._packageJsonLookup = packageJsonLookup;\n this._workingPackageName = workingPackageName;\n this._program = program;\n this._typeChecker = typeChecker;\n this._bundledPackageNames = bundledPackageNames;\n }\n\n /**\n * Gets the UID for a TypeScript Identifier that references a type.\n */\n public getDeclarationReferenceForIdentifier(node: ts.Identifier): DeclarationReference | undefined {\n const symbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(node);\n if (symbol !== undefined) {\n const isExpression: boolean = DeclarationReferenceGenerator._isInExpressionContext(node);\n return (\n this.getDeclarationReferenceForSymbol(\n symbol,\n isExpression ? ts.SymbolFlags.Value : ts.SymbolFlags.Type\n ) ||\n this.getDeclarationReferenceForSymbol(\n symbol,\n isExpression ? ts.SymbolFlags.Type : ts.SymbolFlags.Value\n ) ||\n this.getDeclarationReferenceForSymbol(symbol, ts.SymbolFlags.Namespace)\n );\n }\n }\n\n /**\n * Gets the DeclarationReference for a TypeScript Symbol for a given meaning.\n */\n public getDeclarationReferenceForSymbol(\n symbol: ts.Symbol,\n meaning: ts.SymbolFlags\n ): DeclarationReference | undefined {\n return this._symbolToDeclarationReference(symbol, meaning, /*includeModuleSymbols*/ false);\n }\n\n private static _isInExpressionContext(node: ts.Node): boolean {\n switch (node.parent.kind) {\n case ts.SyntaxKind.TypeQuery:\n return true;\n case ts.SyntaxKind.QualifiedName:\n return DeclarationReferenceGenerator._isInExpressionContext(node.parent);\n default:\n return false;\n }\n }\n\n private static _isExternalModuleSymbol(symbol: ts.Symbol): boolean {\n return (\n !!(symbol.flags & ts.SymbolFlags.ValueModule) &&\n symbol.valueDeclaration !== undefined &&\n ts.isSourceFile(symbol.valueDeclaration)\n );\n }\n\n private static _isSameSymbol(left: ts.Symbol | undefined, right: ts.Symbol): boolean {\n return (\n left === right ||\n !!(\n left &&\n left.valueDeclaration &&\n right.valueDeclaration &&\n left.valueDeclaration === right.valueDeclaration\n )\n );\n }\n\n private static _getNavigationToSymbol(symbol: ts.Symbol): Navigation | 'global' {\n const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);\n // First, try to determine navigation to symbol via its parent.\n if (parent) {\n if (\n parent.exports &&\n DeclarationReferenceGenerator._isSameSymbol(parent.exports.get(symbol.escapedName), symbol)\n ) {\n return Navigation.Exports;\n }\n if (\n parent.members &&\n DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)\n ) {\n return Navigation.Members;\n }\n if (\n parent.globalExports &&\n DeclarationReferenceGenerator._isSameSymbol(parent.globalExports.get(symbol.escapedName), symbol)\n ) {\n return 'global';\n }\n }\n\n // Next, try determining navigation to symbol by its node\n if (symbol.valueDeclaration) {\n const declaration: ts.Declaration = ts.isBindingElement(symbol.valueDeclaration)\n ? ts.walkUpBindingElementsAndPatterns(symbol.valueDeclaration)\n : symbol.valueDeclaration;\n if (ts.isClassElement(declaration) && ts.isClassLike(declaration.parent)) {\n // class members are an \"export\" if they have the static modifier.\n return ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Static\n ? Navigation.Exports\n : Navigation.Members;\n }\n if (ts.isTypeElement(declaration) || ts.isObjectLiteralElement(declaration)) {\n // type and object literal element members are just members\n return Navigation.Members;\n }\n if (ts.isEnumMember(declaration)) {\n // enum members are exports\n return Navigation.Exports;\n }\n if (\n ts.isExportSpecifier(declaration) ||\n ts.isExportAssignment(declaration) ||\n ts.isExportSpecifier(declaration) ||\n ts.isExportDeclaration(declaration) ||\n ts.isNamedExports(declaration)\n ) {\n return Navigation.Exports;\n }\n // declarations are exports if they have an `export` modifier.\n if (ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Export) {\n return Navigation.Exports;\n }\n if (ts.isSourceFile(declaration.parent) && !ts.isExternalModule(declaration.parent)) {\n // declarations in a source file are global if the source file is not a module.\n return 'global';\n }\n }\n // all other declarations are locals\n return Navigation.Locals;\n }\n\n private static _getMeaningOfSymbol(symbol: ts.Symbol, meaning: ts.SymbolFlags): Meaning | undefined {\n if (symbol.flags & meaning & ts.SymbolFlags.Class) {\n return Meaning.Class;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Enum) {\n return Meaning.Enum;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Interface) {\n return Meaning.Interface;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.TypeAlias) {\n return Meaning.TypeAlias;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Function) {\n return Meaning.Function;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Variable) {\n return Meaning.Variable;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Module) {\n return Meaning.Namespace;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.ClassMember) {\n return Meaning.Member;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Constructor) {\n return Meaning.Constructor;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.EnumMember) {\n return Meaning.Member;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Signature) {\n if (symbol.escapedName === ts.InternalSymbolName.Call) {\n return Meaning.CallSignature;\n }\n if (symbol.escapedName === ts.InternalSymbolName.New) {\n return Meaning.ConstructSignature;\n }\n if (symbol.escapedName === ts.InternalSymbolName.Index) {\n return Meaning.IndexSignature;\n }\n }\n if (symbol.flags & meaning & ts.SymbolFlags.TypeParameter) {\n // This should have already been handled in `getDeclarationReferenceOfSymbol`.\n throw new InternalError('Not supported.');\n }\n return undefined;\n }\n\n private _symbolToDeclarationReference(\n symbol: ts.Symbol,\n meaning: ts.SymbolFlags,\n includeModuleSymbols: boolean\n ): DeclarationReference | undefined {\n let followedSymbol: ts.Symbol = symbol;\n if (followedSymbol.flags & ts.SymbolFlags.ExportValue) {\n followedSymbol = this._typeChecker.getExportSymbolOfSymbol(followedSymbol);\n }\n if (followedSymbol.flags & ts.SymbolFlags.Alias) {\n followedSymbol = this._typeChecker.getAliasedSymbol(followedSymbol);\n }\n\n if (DeclarationReferenceGenerator._isExternalModuleSymbol(followedSymbol)) {\n if (!includeModuleSymbols) {\n return undefined;\n }\n const declaration: ts.Node | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n }\n\n // Do not generate a declaration reference for a type parameter.\n if (followedSymbol.flags & ts.SymbolFlags.TypeParameter) {\n return undefined;\n }\n\n let parentRef: DeclarationReference | undefined = this._getParentReference(followedSymbol);\n if (!parentRef) {\n return undefined;\n }\n\n let localName: string = followedSymbol.name;\n if (followedSymbol.escapedName === ts.InternalSymbolName.Constructor) {\n localName = 'constructor';\n } else {\n const wellKnownName: string | undefined = TypeScriptHelpers.tryDecodeWellKnownSymbolName(\n followedSymbol.escapedName\n );\n if (wellKnownName) {\n // TypeScript binds well-known ECMAScript symbols like 'Symbol.iterator' as '__@iterator'.\n // This converts a string like '__@iterator' into the property name '[Symbol.iterator]'.\n localName = wellKnownName;\n } else if (TypeScriptHelpers.isUniqueSymbolName(followedSymbol.escapedName)) {\n for (const decl of followedSymbol.declarations || []) {\n const declName: ts.DeclarationName | undefined = ts.getNameOfDeclaration(decl);\n if (declName && ts.isComputedPropertyName(declName)) {\n const lateName: string | undefined = TypeScriptHelpers.tryGetLateBoundName(declName);\n if (lateName !== undefined) {\n localName = lateName;\n break;\n }\n }\n }\n }\n }\n\n let navigation: Navigation | 'global' =\n DeclarationReferenceGenerator._getNavigationToSymbol(followedSymbol);\n if (navigation === 'global') {\n if (parentRef.source !== GlobalSource.instance) {\n parentRef = new DeclarationReference(GlobalSource.instance);\n }\n navigation = Navigation.Exports;\n }\n\n return parentRef\n .addNavigationStep(navigation, localName)\n .withMeaning(DeclarationReferenceGenerator._getMeaningOfSymbol(followedSymbol, meaning));\n }\n\n private _getParentReference(symbol: ts.Symbol): DeclarationReference | undefined {\n const declaration: ts.Node | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n\n // First, try to find a parent symbol via the symbol tree.\n const parentSymbol: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);\n if (parentSymbol) {\n return this._symbolToDeclarationReference(\n parentSymbol,\n parentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n\n // If that doesn't work, try to find a parent symbol via the node tree. As far as we can tell,\n // this logic is only needed for local symbols within namespaces. For example:\n //\n // ```\n // export namespace n {\n // type SomeType = number;\n // export function someFunction(): SomeType { return 5; }\n // }\n // ```\n //\n // In the example above, `SomeType` doesn't have a parent symbol per the TS internal API above,\n // but its reference still needs to be qualified with the parent reference for `n`.\n const grandParent: ts.Node | undefined = declaration?.parent?.parent;\n if (grandParent && ts.isModuleDeclaration(grandParent)) {\n const grandParentSymbol: ts.Symbol | undefined = TypeScriptInternals.tryGetSymbolForDeclaration(\n grandParent,\n this._typeChecker\n );\n if (grandParentSymbol) {\n return this._symbolToDeclarationReference(\n grandParentSymbol,\n grandParentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n }\n\n // At this point, we have a local symbol in a module.\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n } else {\n return new DeclarationReference(GlobalSource.instance);\n }\n }\n\n private _getPackageName(sourceFile: ts.SourceFile): string {\n if (this._program.isSourceFileFromExternalLibrary(sourceFile)) {\n const packageJson: INodePackageJson | undefined = this._packageJsonLookup.tryLoadNodePackageJsonFor(\n sourceFile.fileName\n );\n\n if (packageJson && packageJson.name) {\n return packageJson.name;\n }\n return DeclarationReferenceGenerator.unknownReference;\n }\n return this._workingPackageName;\n }\n\n private _sourceFileToModuleSource(sourceFile: ts.SourceFile | undefined): GlobalSource | ModuleSource {\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n const packageName: string = this._getPackageName(sourceFile);\n\n if (this._bundledPackageNames.has(packageName)) {\n // The api-extractor.json config file has a \"bundledPackages\" setting, which causes imports from\n // certain NPM packages to be treated as part of the working project. In this case, we need to\n // substitute the working package name.\n return new ModuleSource(this._workingPackageName);\n } else {\n return new ModuleSource(packageName);\n }\n }\n return GlobalSource.instance;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DeclarationReferenceGenerator.js","sourceRoot":"","sources":["../../src/generators/DeclarationReferenceGenerator.ts"],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C,gBAAgB,CAAC;SACvD;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC;IAC7C,CAAC;IAEO,yBAAyB,CAAC,UAAqC;QACrE,IAAI,UAAU,IAAI,EAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE;YACjD,MAAM,WAAW,GAAW,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;YAE7D,IAAI,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;gBACxD,gGAAgG;gBAChG,+FAA+F;gBAC/F,uCAAuC;gBACvC,OAAO,IAAI,mCAAY,CAAC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;aAC9D;iBAAM;gBACL,OAAO,IAAI,mCAAY,CAAC,WAAW,CAAC,CAAC;aACtC;SACF;QACD,OAAO,mCAAY,CAAC,QAAQ,CAAC;IAC/B,CAAC;;AAtWH,sEAuWC;AAtWwB,8CAAgB,GAAW,GAAG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/* eslint-disable no-bitwise */\nimport * as ts from 'typescript';\nimport {\n DeclarationReference,\n ModuleSource,\n GlobalSource,\n Navigation,\n Meaning\n} from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';\nimport { INodePackageJson, InternalError } from '@rushstack/node-core-library';\nimport { TypeScriptHelpers } from '../analyzer/TypeScriptHelpers';\nimport { TypeScriptInternals } from '../analyzer/TypeScriptInternals';\nimport { Collector } from '../collector/Collector';\nimport { CollectorEntity } from '../collector/CollectorEntity';\nimport { AstNamespaceImport } from '../analyzer/AstNamespaceImport';\n\nexport class DeclarationReferenceGenerator {\n public static readonly unknownReference: string = '?';\n\n private _collector: Collector;\n\n public constructor(collector: Collector) {\n this._collector = collector;\n }\n\n /**\n * Gets the UID for a TypeScript Identifier that references a type.\n */\n public getDeclarationReferenceForIdentifier(node: ts.Identifier): DeclarationReference | undefined {\n const symbol: ts.Symbol | undefined = this._collector.typeChecker.getSymbolAtLocation(node);\n if (symbol !== undefined) {\n const isExpression: boolean = DeclarationReferenceGenerator._isInExpressionContext(node);\n return (\n this.getDeclarationReferenceForSymbol(\n symbol,\n isExpression ? ts.SymbolFlags.Value : ts.SymbolFlags.Type\n ) ||\n this.getDeclarationReferenceForSymbol(\n symbol,\n isExpression ? ts.SymbolFlags.Type : ts.SymbolFlags.Value\n ) ||\n this.getDeclarationReferenceForSymbol(symbol, ts.SymbolFlags.Namespace)\n );\n }\n }\n\n /**\n * Gets the DeclarationReference for a TypeScript Symbol for a given meaning.\n */\n public getDeclarationReferenceForSymbol(\n symbol: ts.Symbol,\n meaning: ts.SymbolFlags\n ): DeclarationReference | undefined {\n return this._symbolToDeclarationReference(symbol, meaning, /*includeModuleSymbols*/ false);\n }\n\n private static _isInExpressionContext(node: ts.Node): boolean {\n switch (node.parent.kind) {\n case ts.SyntaxKind.TypeQuery:\n return true;\n case ts.SyntaxKind.QualifiedName:\n return DeclarationReferenceGenerator._isInExpressionContext(node.parent);\n default:\n return false;\n }\n }\n\n private static _isExternalModuleSymbol(symbol: ts.Symbol): boolean {\n return (\n !!(symbol.flags & ts.SymbolFlags.ValueModule) &&\n symbol.valueDeclaration !== undefined &&\n ts.isSourceFile(symbol.valueDeclaration)\n );\n }\n\n private static _isSameSymbol(left: ts.Symbol | undefined, right: ts.Symbol): boolean {\n return (\n left === right ||\n !!(\n left &&\n left.valueDeclaration &&\n right.valueDeclaration &&\n left.valueDeclaration === right.valueDeclaration\n )\n );\n }\n\n private _getNavigationToSymbol(symbol: ts.Symbol): Navigation {\n const declaration: ts.Declaration | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);\n\n // If it's global or from an external library, then use either Members or Exports. It's not possible for\n // global symbols or external library symbols to be Locals.\n const isGlobal: boolean = !!sourceFile && !ts.isExternalModule(sourceFile);\n const isFromExternalLibrary: boolean =\n !!sourceFile && this._collector.program.isSourceFileFromExternalLibrary(sourceFile);\n if (isGlobal || isFromExternalLibrary) {\n if (\n parent &&\n parent.members &&\n DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)\n ) {\n return Navigation.Members;\n }\n\n return Navigation.Exports;\n }\n\n // Otherwise, this symbol is from the current package. If we've found an associated consumable\n // `CollectorEntity`, then use Exports. We use `consumable` here instead of `exported` because\n // if the symbol is exported from a non-consumable `AstNamespaceImport`, we don't want to use\n // Exports. We should use Locals instead.\n const entity: CollectorEntity | undefined = this._collector.tryGetEntityForSymbol(symbol);\n if (entity?.consumable) {\n return Navigation.Exports;\n }\n\n // If its parent symbol is not a source file, then use either Exports or Members. If the parent symbol\n // is a source file, but it wasn't exported from the package entry point (in the check above), then the\n // symbol is a local, so fall through below.\n if (parent && !DeclarationReferenceGenerator._isExternalModuleSymbol(parent)) {\n if (\n parent.members &&\n DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)\n ) {\n return Navigation.Members;\n }\n\n return Navigation.Exports;\n }\n\n // Otherwise, we have a local symbol, so use a Locals navigation. These are either:\n //\n // 1. Symbols that are exported from a file module but not the package entry point.\n // 2. Symbols that are not exported from their parent module.\n return Navigation.Locals;\n }\n\n private static _getMeaningOfSymbol(symbol: ts.Symbol, meaning: ts.SymbolFlags): Meaning | undefined {\n if (symbol.flags & meaning & ts.SymbolFlags.Class) {\n return Meaning.Class;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Enum) {\n return Meaning.Enum;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Interface) {\n return Meaning.Interface;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.TypeAlias) {\n return Meaning.TypeAlias;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Function) {\n return Meaning.Function;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Variable) {\n return Meaning.Variable;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Module) {\n return Meaning.Namespace;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.ClassMember) {\n return Meaning.Member;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Constructor) {\n return Meaning.Constructor;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.EnumMember) {\n return Meaning.Member;\n }\n if (symbol.flags & meaning & ts.SymbolFlags.Signature) {\n if (symbol.escapedName === ts.InternalSymbolName.Call) {\n return Meaning.CallSignature;\n }\n if (symbol.escapedName === ts.InternalSymbolName.New) {\n return Meaning.ConstructSignature;\n }\n if (symbol.escapedName === ts.InternalSymbolName.Index) {\n return Meaning.IndexSignature;\n }\n }\n if (symbol.flags & meaning & ts.SymbolFlags.TypeParameter) {\n // This should have already been handled in `getDeclarationReferenceOfSymbol`.\n throw new InternalError('Not supported.');\n }\n return undefined;\n }\n\n private _symbolToDeclarationReference(\n symbol: ts.Symbol,\n meaning: ts.SymbolFlags,\n includeModuleSymbols: boolean\n ): DeclarationReference | undefined {\n const declaration: ts.Node | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n\n let followedSymbol: ts.Symbol = symbol;\n if (followedSymbol.flags & ts.SymbolFlags.ExportValue) {\n followedSymbol = this._collector.typeChecker.getExportSymbolOfSymbol(followedSymbol);\n }\n if (followedSymbol.flags & ts.SymbolFlags.Alias) {\n followedSymbol = this._collector.typeChecker.getAliasedSymbol(followedSymbol);\n\n // Without this logic, we end up following the symbol `ns` in `import * as ns from './file'` to\n // the actual file `file.ts`. We don't want to do this, so revert to the original symbol.\n if (followedSymbol.flags & ts.SymbolFlags.ValueModule) {\n followedSymbol = symbol;\n }\n }\n\n if (DeclarationReferenceGenerator._isExternalModuleSymbol(followedSymbol)) {\n if (!includeModuleSymbols) {\n return undefined;\n }\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n }\n\n // Do not generate a declaration reference for a type parameter.\n if (followedSymbol.flags & ts.SymbolFlags.TypeParameter) {\n return undefined;\n }\n\n let parentRef: DeclarationReference | undefined = this._getParentReference(followedSymbol);\n if (!parentRef) {\n return undefined;\n }\n\n let localName: string = followedSymbol.name;\n const entity: CollectorEntity | undefined = this._collector.tryGetEntityForSymbol(followedSymbol);\n if (entity?.nameForEmit) {\n localName = entity.nameForEmit;\n }\n\n if (followedSymbol.escapedName === ts.InternalSymbolName.Constructor) {\n localName = 'constructor';\n } else {\n const wellKnownName: string | undefined = TypeScriptHelpers.tryDecodeWellKnownSymbolName(\n followedSymbol.escapedName\n );\n if (wellKnownName) {\n // TypeScript binds well-known ECMAScript symbols like 'Symbol.iterator' as '__@iterator'.\n // This converts a string like '__@iterator' into the property name '[Symbol.iterator]'.\n localName = wellKnownName;\n } else if (TypeScriptHelpers.isUniqueSymbolName(followedSymbol.escapedName)) {\n for (const decl of followedSymbol.declarations || []) {\n const declName: ts.DeclarationName | undefined = ts.getNameOfDeclaration(decl);\n if (declName && ts.isComputedPropertyName(declName)) {\n const lateName: string | undefined = TypeScriptHelpers.tryGetLateBoundName(declName);\n if (lateName !== undefined) {\n localName = lateName;\n break;\n }\n }\n }\n }\n }\n\n const navigation: Navigation = this._getNavigationToSymbol(followedSymbol);\n\n // If the symbol is a global, ensure the source is global.\n if (sourceFile && !ts.isExternalModule(sourceFile) && parentRef.source !== GlobalSource.instance) {\n parentRef = new DeclarationReference(GlobalSource.instance);\n }\n\n return parentRef\n .addNavigationStep(navigation, localName)\n .withMeaning(DeclarationReferenceGenerator._getMeaningOfSymbol(followedSymbol, meaning));\n }\n\n private _getParentReference(symbol: ts.Symbol): DeclarationReference | undefined {\n const declaration: ts.Node | undefined = TypeScriptHelpers.tryGetADeclaration(symbol);\n const sourceFile: ts.SourceFile | undefined = declaration?.getSourceFile();\n\n // Note that it's possible for a symbol to be exported from an entry point as well as one or more\n // namespaces. In that case, it's not clear what to choose as its parent. Today's logic is neither\n // perfect nor particularly stable to API items being renamed and shuffled around.\n const entity: CollectorEntity | undefined = this._collector.tryGetEntityForSymbol(symbol);\n if (entity) {\n if (entity.exportedFromEntryPoint) {\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n }\n\n const firstExportingConsumableParent: CollectorEntity | undefined =\n entity.getFirstExportingConsumableParent();\n if (\n firstExportingConsumableParent &&\n firstExportingConsumableParent.astEntity instanceof AstNamespaceImport\n ) {\n const parentSymbol: ts.Symbol | undefined = TypeScriptInternals.tryGetSymbolForDeclaration(\n firstExportingConsumableParent.astEntity.declaration,\n this._collector.typeChecker\n );\n if (parentSymbol) {\n return this._symbolToDeclarationReference(\n parentSymbol,\n parentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n }\n }\n\n // Next, try to find a parent symbol via the symbol tree.\n const parentSymbol: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(symbol);\n if (parentSymbol) {\n return this._symbolToDeclarationReference(\n parentSymbol,\n parentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n\n // If that doesn't work, try to find a parent symbol via the node tree. As far as we can tell,\n // this logic is only needed for local symbols within namespaces. For example:\n //\n // ```\n // export namespace n {\n // type SomeType = number;\n // export function someFunction(): SomeType { return 5; }\n // }\n // ```\n //\n // In the example above, `SomeType` doesn't have a parent symbol per the TS internal API above,\n // but its reference still needs to be qualified with the parent reference for `n`.\n const grandParent: ts.Node | undefined = declaration?.parent?.parent;\n if (grandParent && ts.isModuleDeclaration(grandParent)) {\n const grandParentSymbol: ts.Symbol | undefined = TypeScriptInternals.tryGetSymbolForDeclaration(\n grandParent,\n this._collector.typeChecker\n );\n if (grandParentSymbol) {\n return this._symbolToDeclarationReference(\n grandParentSymbol,\n grandParentSymbol.flags,\n /*includeModuleSymbols*/ true\n );\n }\n }\n\n // At this point, we have a local symbol in a module.\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n return new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n } else {\n return new DeclarationReference(GlobalSource.instance);\n }\n }\n\n private _getPackageName(sourceFile: ts.SourceFile): string {\n if (this._collector.program.isSourceFileFromExternalLibrary(sourceFile)) {\n const packageJson: INodePackageJson | undefined =\n this._collector.packageJsonLookup.tryLoadNodePackageJsonFor(sourceFile.fileName);\n\n if (packageJson && packageJson.name) {\n return packageJson.name;\n }\n return DeclarationReferenceGenerator.unknownReference;\n }\n return this._collector.workingPackage.name;\n }\n\n private _sourceFileToModuleSource(sourceFile: ts.SourceFile | undefined): GlobalSource | ModuleSource {\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n const packageName: string = this._getPackageName(sourceFile);\n\n if (this._collector.bundledPackageNames.has(packageName)) {\n // The api-extractor.json config file has a \"bundledPackages\" setting, which causes imports from\n // certain NPM packages to be treated as part of the working project. In this case, we need to\n // substitute the working package name.\n return new ModuleSource(this._collector.workingPackage.name);\n } else {\n return new ModuleSource(packageName);\n }\n }\n return GlobalSource.instance;\n }\n}\n"]}
|
|
@@ -18,12 +18,14 @@
|
|
|
18
18
|
// ("enabled" is required)
|
|
19
19
|
"reportFileName": "<unscopedPackageName>.api.md",
|
|
20
20
|
"reportFolder": "<projectFolder>/etc/",
|
|
21
|
-
"reportTempFolder": "<projectFolder>/temp/"
|
|
21
|
+
"reportTempFolder": "<projectFolder>/temp/",
|
|
22
|
+
"includeForgottenExports": false
|
|
22
23
|
},
|
|
23
24
|
|
|
24
25
|
"docModel": {
|
|
25
26
|
// ("enabled" is required)
|
|
26
|
-
"apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
|
27
|
+
"apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json",
|
|
28
|
+
"includeForgottenExports": false
|
|
27
29
|
},
|
|
28
30
|
|
|
29
31
|
"dtsRollup": {
|
|
@@ -80,12 +80,13 @@
|
|
|
80
80
|
// "testMode": false,
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Specifies how API Extractor sorts members of an enum when generating api.json. By default, the output
|
|
84
|
-
* will be sorted alphabetically, which is "by-name". To keep the ordering in the source code, specify
|
|
83
|
+
* Specifies how API Extractor sorts members of an enum when generating the .api.json file. By default, the output
|
|
84
|
+
* files will be sorted alphabetically, which is "by-name". To keep the ordering in the source code, specify
|
|
85
|
+
* "preserve".
|
|
85
86
|
*
|
|
86
87
|
* DEFAULT VALUE: "by-name"
|
|
87
88
|
*/
|
|
88
|
-
// enumMemberOrder
|
|
89
|
+
// "enumMemberOrder": "by-name",
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
92
|
* Determines how the TypeScript compiler engine will be invoked by API Extractor.
|
|
@@ -175,7 +176,16 @@
|
|
|
175
176
|
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
|
176
177
|
* DEFAULT VALUE: "<projectFolder>/temp/"
|
|
177
178
|
*/
|
|
178
|
-
// "reportTempFolder": "<projectFolder>/temp/"
|
|
179
|
+
// "reportTempFolder": "<projectFolder>/temp/",
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Whether "forgotten exports" should be included in the API report file. Forgotten exports are declarations
|
|
183
|
+
* flagged with `ae-forgotten-export` warnings. See https://api-extractor.com/pages/messages/ae-forgotten-export/ to
|
|
184
|
+
* learn more.
|
|
185
|
+
*
|
|
186
|
+
* DEFAULT VALUE: "false"
|
|
187
|
+
*/
|
|
188
|
+
// "includeForgottenExports": false
|
|
179
189
|
},
|
|
180
190
|
|
|
181
191
|
/**
|
|
@@ -196,7 +206,16 @@
|
|
|
196
206
|
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
|
197
207
|
* DEFAULT VALUE: "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
|
198
208
|
*/
|
|
199
|
-
// "apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
|
209
|
+
// "apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json",
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Whether "forgotten exports" should be included in the doc model file. Forgotten exports are declarations
|
|
213
|
+
* flagged with `ae-forgotten-export` warnings. See https://api-extractor.com/pages/messages/ae-forgotten-export/ to
|
|
214
|
+
* learn more.
|
|
215
|
+
*
|
|
216
|
+
* DEFAULT VALUE: "false"
|
|
217
|
+
*/
|
|
218
|
+
// "includeForgottenExports": false
|
|
200
219
|
},
|
|
201
220
|
|
|
202
221
|
/**
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
|
|
34
34
|
"enumMemberOrder": {
|
|
35
|
-
"description":
|
|
35
|
+
"description": "Specifies how API Extractor sorts the members of an enum when generating the .api.json doc model. \n 'by-name': sort the items according to the enum member name \n 'preserve': keep the original order that items appear in the source code",
|
|
36
36
|
"type": "string",
|
|
37
37
|
"enum": ["by-name", "preserve"],
|
|
38
38
|
"default": "by-name"
|
|
@@ -80,6 +80,11 @@
|
|
|
80
80
|
"reportTempFolder": {
|
|
81
81
|
"description": "Specifies the folder where the temporary report file is written. The file name portion is determined by the \"reportFileName\" setting. After the temporary file is written to disk, it is compared with the file in the \"reportFolder\". If they are different, a production build will fail. The path is resolved relative to the folder of the config file that contains the setting; to change this, prepend a folder token such as \"<projectFolder>\".",
|
|
82
82
|
"type": "string"
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
"includeForgottenExports": {
|
|
86
|
+
"description": "Whether \"forgotten exports\" should be included in the API report file. Forgotten exports are declarations flagged with `ae-forgotten-export` warnings. See https://api-extractor.com/pages/messages/ae-forgotten-export/ to learn more.",
|
|
87
|
+
"type": "boolean"
|
|
83
88
|
}
|
|
84
89
|
},
|
|
85
90
|
"required": ["enabled"],
|
|
@@ -97,6 +102,11 @@
|
|
|
97
102
|
"apiJsonFilePath": {
|
|
98
103
|
"description": "The output path for the doc model file. The file extension should be \".api.json\". The path is resolved relative to the folder of the config file that contains the setting; to change this, prepend a folder token such as \"<projectFolder>\".",
|
|
99
104
|
"type": "string"
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
"includeForgottenExports": {
|
|
108
|
+
"description": "Whether \"forgotten exports\" should be included in the doc model file. Forgotten exports are declarations flagged with `ae-forgotten-export` warnings. See https://api-extractor.com/pages/messages/ae-forgotten-export/ to learn more.",
|
|
109
|
+
"type": "boolean"
|
|
100
110
|
}
|
|
101
111
|
},
|
|
102
112
|
"required": ["enabled"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/api-extractor",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.31.0",
|
|
4
4
|
"description": "Analyze the exported API for a TypeScript library and generate reviews, documentation, and .d.ts rollups",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@microsoft/api-extractor-model": "7.
|
|
35
|
+
"@microsoft/api-extractor-model": "7.24.0",
|
|
36
36
|
"@microsoft/tsdoc": "0.14.1",
|
|
37
37
|
"@microsoft/tsdoc-config": "~0.16.1",
|
|
38
38
|
"@rushstack/node-core-library": "3.51.1",
|
|
@@ -59,6 +59,5 @@
|
|
|
59
59
|
"build": "heft build --clean",
|
|
60
60
|
"_phase:build": "heft build --clean",
|
|
61
61
|
"_phase:test": "heft test --no-build"
|
|
62
|
-
}
|
|
63
|
-
"readme": "# @microsoft/api-extractor\n\n\n\n<br />\n https://api-extractor.com/\n\n<!-- ------------------------------------------------------------------ -->\n<!-- Text below this line should stay in sync with the web site content -->\n<!-- ------------------------------------------------------------------ -->\n\n**API Extractor** helps you build better [TypeScript](https://www.typescriptlang.org/) library packages. Suppose for example that your company has published an NPM package called \"**awesome-widgets**\" that exports many classes and interfaces. As developers start to depend on your library, you may encounter issues such as...\n\n- **Accidental breaks:** People keep reporting that their code won't compile after a supposedly \"minor\" update. To address this, you boldly propose that every **awesome-widgets** pull request must be approved by an experienced developer from your team. But that proves unrealistic -- nobody has time to look at every single PR! What you really need is a way to detect PRs that change API contracts, and flag them for review. That would focus attention in the right place... but how to do that?\n\n- **Missing exports:** Suppose the **awesome-widgets** package exports an API function `AwesomeButton.draw()` that requires a parameter of type `DrawStyle`, but you forgot to export this enum. Things seem fine at first, but when a developer tries to call that function, they discover that there's no way to specify the `DrawStyle`. How to avoid these oversights?\n\n- **Accidental exports:** You meant for your `DrawHelper` class to be kept internal, but one day you realize it's being exported. When you try to remove it, consumers complain that they're using it. How do we avoid this in the future?\n\n- **Alpha/Beta graduation:** You want to release previews of new APIs that are not ready for prime time yet. But if you did a major SemVer bump every time these definitions evolve, the villagers would be after you with torches and pitchforks! A better approach is to designate certain classes/members as **alpha** quality, then promote them to **beta** and finally to **public** as they mature. But how to indicate this to your consumers? (And how to detect scoping mistakes? A **public** function should never return a **beta** result.)\n\n- **\\*.d.ts rollup:** You webpacked your library into a nice **\\*.js** bundle file -- so why ship your typings as a messy tree of **lib/\\*.d.ts** files full of private definitions? Can't we consolidate them into a tidy **\\*.d.ts** rollup file? And if you publish internal/beta/public releases, each release type should get its own **\\*.d.ts** file with appropriate trimming. Developers building a production project don't want to see a bunch of **internal** and **beta** members in their VS Code IntelliSense!\n\n- **Online documentation:** You have faithfully annotated each TypeScript member with nice [TSDoc](https://github.com/microsoft/tsdoc) descriptions. Now that your library has shipped, it's time to set up [a nicely formatted](https://docs.microsoft.com/en-us/javascript/api/sp-http) API reference. What tool to use?\n\n**API Extractor** provides an integrated, professional-quality solution for all these problems. It is invoked at build time by your toolchain and leverages the TypeScript compiler engine to:\n\n- Detect a project's exported API surface\n- Capture the contracts in a concise report designed to facilitate review\n- Warn about common mistakes (e.g. missing exports, inconsistent visibility, etc.)\n- Generate \\*.d.ts rollups with trimming according to release type\n- Output API documentation in a portable format that's easy to integrate with your content pipeline\n\nBest of all, **API Extractor** is free and open source. Join the community and create a pull request!\n\n<!-- ------------------------------------------------------------------ -->\n<!-- Text above this line should stay in sync with the web site content -->\n<!-- ------------------------------------------------------------------ -->\n\n## Getting Started\n\nFor more details and support resources, please visit: https://api-extractor.com/\n\n## Links\n\n- [CHANGELOG.md](\n https://github.com/microsoft/rushstack/blob/main/apps/api-extractor/CHANGELOG.md) - Find\n out what's new in the latest version\n- [API Reference](https://rushstack.io/pages/api/api-extractor/)\n\nAPI Extractor is part of the [Rush Stack](https://rushstack.io/) family of projects.\n"
|
|
62
|
+
}
|
|
64
63
|
}
|