@microsoft/api-extractor 7.28.7 → 7.29.2
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/tsdoc-metadata.json +1 -1
- package/lib/aedoc/PackageDocComment.js +1 -1
- package/lib/aedoc/PackageDocComment.js.map +1 -1
- package/lib/analyzer/PackageMetadataManager.js +1 -1
- package/lib/analyzer/PackageMetadataManager.js.map +1 -1
- package/lib/api/Extractor.js +11 -11
- package/lib/api/Extractor.js.map +1 -1
- package/lib/api/ExtractorMessage.js +6 -6
- package/lib/api/ExtractorMessage.js.map +1 -1
- package/lib/collector/Collector.js +7 -7
- package/lib/collector/Collector.js.map +1 -1
- package/lib/collector/MessageRouter.js +28 -28
- package/lib/collector/MessageRouter.js.map +1 -1
- package/lib/enhancers/DocCommentEnhancer.js +4 -4
- package/lib/enhancers/DocCommentEnhancer.js.map +1 -1
- package/lib/enhancers/ValidationEnhancer.js +5 -5
- package/lib/enhancers/ValidationEnhancer.js.map +1 -1
- package/lib/generators/DeclarationReferenceGenerator.d.ts +1 -0
- package/lib/generators/DeclarationReferenceGenerator.d.ts.map +1 -1
- package/lib/generators/DeclarationReferenceGenerator.js +65 -45
- package/lib/generators/DeclarationReferenceGenerator.js.map +1 -1
- package/lib/generators/ExcerptBuilder.d.ts +11 -0
- package/lib/generators/ExcerptBuilder.d.ts.map +1 -1
- package/lib/generators/ExcerptBuilder.js +88 -43
- package/lib/generators/ExcerptBuilder.js.map +1 -1
- package/package.json +9 -9
|
@@ -86,11 +86,11 @@ class DeclarationReferenceGenerator {
|
|
|
86
86
|
if (parent) {
|
|
87
87
|
if (parent.exports &&
|
|
88
88
|
DeclarationReferenceGenerator._isSameSymbol(parent.exports.get(symbol.escapedName), symbol)) {
|
|
89
|
-
return "." /* Exports */;
|
|
89
|
+
return "." /* Navigation.Exports */;
|
|
90
90
|
}
|
|
91
91
|
if (parent.members &&
|
|
92
92
|
DeclarationReferenceGenerator._isSameSymbol(parent.members.get(symbol.escapedName), symbol)) {
|
|
93
|
-
return "#" /* Members */;
|
|
93
|
+
return "#" /* Navigation.Members */;
|
|
94
94
|
}
|
|
95
95
|
if (parent.globalExports &&
|
|
96
96
|
DeclarationReferenceGenerator._isSameSymbol(parent.globalExports.get(symbol.escapedName), symbol)) {
|
|
@@ -105,27 +105,27 @@ class DeclarationReferenceGenerator {
|
|
|
105
105
|
if (ts.isClassElement(declaration) && ts.isClassLike(declaration.parent)) {
|
|
106
106
|
// class members are an "export" if they have the static modifier.
|
|
107
107
|
return ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Static
|
|
108
|
-
? "." /* Exports */
|
|
109
|
-
: "#" /* Members */;
|
|
108
|
+
? "." /* Navigation.Exports */
|
|
109
|
+
: "#" /* Navigation.Members */;
|
|
110
110
|
}
|
|
111
111
|
if (ts.isTypeElement(declaration) || ts.isObjectLiteralElement(declaration)) {
|
|
112
112
|
// type and object literal element members are just members
|
|
113
|
-
return "#" /* Members */;
|
|
113
|
+
return "#" /* Navigation.Members */;
|
|
114
114
|
}
|
|
115
115
|
if (ts.isEnumMember(declaration)) {
|
|
116
116
|
// enum members are exports
|
|
117
|
-
return "." /* Exports */;
|
|
117
|
+
return "." /* Navigation.Exports */;
|
|
118
118
|
}
|
|
119
119
|
if (ts.isExportSpecifier(declaration) ||
|
|
120
120
|
ts.isExportAssignment(declaration) ||
|
|
121
121
|
ts.isExportSpecifier(declaration) ||
|
|
122
122
|
ts.isExportDeclaration(declaration) ||
|
|
123
123
|
ts.isNamedExports(declaration)) {
|
|
124
|
-
return "." /* Exports */;
|
|
124
|
+
return "." /* Navigation.Exports */;
|
|
125
125
|
}
|
|
126
126
|
// declarations are exports if they have an `export` modifier.
|
|
127
127
|
if (ts.getCombinedModifierFlags(declaration) & ts.ModifierFlags.Export) {
|
|
128
|
-
return "." /* Exports */;
|
|
128
|
+
return "." /* Navigation.Exports */;
|
|
129
129
|
}
|
|
130
130
|
if (ts.isSourceFile(declaration.parent) && !ts.isExternalModule(declaration.parent)) {
|
|
131
131
|
// declarations in a source file are global if the source file is not a module.
|
|
@@ -133,48 +133,48 @@ class DeclarationReferenceGenerator {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
// all other declarations are locals
|
|
136
|
-
return "~" /* Locals */;
|
|
136
|
+
return "~" /* Navigation.Locals */;
|
|
137
137
|
}
|
|
138
138
|
static _getMeaningOfSymbol(symbol, meaning) {
|
|
139
139
|
if (symbol.flags & meaning & ts.SymbolFlags.Class) {
|
|
140
|
-
return "class" /* Class */;
|
|
140
|
+
return "class" /* Meaning.Class */;
|
|
141
141
|
}
|
|
142
142
|
if (symbol.flags & meaning & ts.SymbolFlags.Enum) {
|
|
143
|
-
return "enum" /* Enum */;
|
|
143
|
+
return "enum" /* Meaning.Enum */;
|
|
144
144
|
}
|
|
145
145
|
if (symbol.flags & meaning & ts.SymbolFlags.Interface) {
|
|
146
|
-
return "interface" /* Interface */;
|
|
146
|
+
return "interface" /* Meaning.Interface */;
|
|
147
147
|
}
|
|
148
148
|
if (symbol.flags & meaning & ts.SymbolFlags.TypeAlias) {
|
|
149
|
-
return "type" /* TypeAlias */;
|
|
149
|
+
return "type" /* Meaning.TypeAlias */;
|
|
150
150
|
}
|
|
151
151
|
if (symbol.flags & meaning & ts.SymbolFlags.Function) {
|
|
152
|
-
return "function" /* Function */;
|
|
152
|
+
return "function" /* Meaning.Function */;
|
|
153
153
|
}
|
|
154
154
|
if (symbol.flags & meaning & ts.SymbolFlags.Variable) {
|
|
155
|
-
return "var" /* Variable */;
|
|
155
|
+
return "var" /* Meaning.Variable */;
|
|
156
156
|
}
|
|
157
157
|
if (symbol.flags & meaning & ts.SymbolFlags.Module) {
|
|
158
|
-
return "namespace" /* Namespace */;
|
|
158
|
+
return "namespace" /* Meaning.Namespace */;
|
|
159
159
|
}
|
|
160
160
|
if (symbol.flags & meaning & ts.SymbolFlags.ClassMember) {
|
|
161
|
-
return "member" /* Member */;
|
|
161
|
+
return "member" /* Meaning.Member */;
|
|
162
162
|
}
|
|
163
163
|
if (symbol.flags & meaning & ts.SymbolFlags.Constructor) {
|
|
164
|
-
return "constructor" /* Constructor */;
|
|
164
|
+
return "constructor" /* Meaning.Constructor */;
|
|
165
165
|
}
|
|
166
166
|
if (symbol.flags & meaning & ts.SymbolFlags.EnumMember) {
|
|
167
|
-
return "member" /* Member */;
|
|
167
|
+
return "member" /* Meaning.Member */;
|
|
168
168
|
}
|
|
169
169
|
if (symbol.flags & meaning & ts.SymbolFlags.Signature) {
|
|
170
170
|
if (symbol.escapedName === ts.InternalSymbolName.Call) {
|
|
171
|
-
return "call" /* CallSignature */;
|
|
171
|
+
return "call" /* Meaning.CallSignature */;
|
|
172
172
|
}
|
|
173
173
|
if (symbol.escapedName === ts.InternalSymbolName.New) {
|
|
174
|
-
return "new" /* ConstructSignature */;
|
|
174
|
+
return "new" /* Meaning.ConstructSignature */;
|
|
175
175
|
}
|
|
176
176
|
if (symbol.escapedName === ts.InternalSymbolName.Index) {
|
|
177
|
-
return "index" /* IndexSignature */;
|
|
177
|
+
return "index" /* Meaning.IndexSignature */;
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
if (symbol.flags & meaning & ts.SymbolFlags.TypeParameter) {
|
|
@@ -195,34 +195,16 @@ class DeclarationReferenceGenerator {
|
|
|
195
195
|
if (!includeModuleSymbols) {
|
|
196
196
|
return undefined;
|
|
197
197
|
}
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
followedSymbol.declarations[0].getSourceFile();
|
|
198
|
+
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
199
|
+
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
201
200
|
return new DeclarationReference_1.DeclarationReference(this._sourceFileToModuleSource(sourceFile));
|
|
202
201
|
}
|
|
203
202
|
// Do not generate a declaration reference for a type parameter.
|
|
204
203
|
if (followedSymbol.flags & ts.SymbolFlags.TypeParameter) {
|
|
205
204
|
return undefined;
|
|
206
205
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (parent) {
|
|
210
|
-
parentRef = this._symbolToDeclarationReference(parent, ts.SymbolFlags.Namespace,
|
|
211
|
-
/*includeModuleSymbols*/ true);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
// this may be a local symbol in a module...
|
|
215
|
-
const sourceFile = followedSymbol.declarations &&
|
|
216
|
-
followedSymbol.declarations[0] &&
|
|
217
|
-
followedSymbol.declarations[0].getSourceFile();
|
|
218
|
-
if (sourceFile && ts.isExternalModule(sourceFile)) {
|
|
219
|
-
parentRef = new DeclarationReference_1.DeclarationReference(this._sourceFileToModuleSource(sourceFile));
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
parentRef = new DeclarationReference_1.DeclarationReference(DeclarationReference_1.GlobalSource.instance);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (parentRef === undefined) {
|
|
206
|
+
let parentRef = this._getParentReference(followedSymbol);
|
|
207
|
+
if (!parentRef) {
|
|
226
208
|
return undefined;
|
|
227
209
|
}
|
|
228
210
|
let localName = followedSymbol.name;
|
|
@@ -254,12 +236,50 @@ class DeclarationReferenceGenerator {
|
|
|
254
236
|
if (parentRef.source !== DeclarationReference_1.GlobalSource.instance) {
|
|
255
237
|
parentRef = new DeclarationReference_1.DeclarationReference(DeclarationReference_1.GlobalSource.instance);
|
|
256
238
|
}
|
|
257
|
-
navigation = "." /* Exports */;
|
|
239
|
+
navigation = "." /* Navigation.Exports */;
|
|
258
240
|
}
|
|
259
241
|
return parentRef
|
|
260
242
|
.addNavigationStep(navigation, localName)
|
|
261
243
|
.withMeaning(DeclarationReferenceGenerator._getMeaningOfSymbol(followedSymbol, meaning));
|
|
262
244
|
}
|
|
245
|
+
_getParentReference(symbol) {
|
|
246
|
+
var _a;
|
|
247
|
+
const declaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(symbol);
|
|
248
|
+
// First, try to find a parent symbol via the symbol tree.
|
|
249
|
+
const parentSymbol = TypeScriptInternals_1.TypeScriptInternals.getSymbolParent(symbol);
|
|
250
|
+
if (parentSymbol) {
|
|
251
|
+
return this._symbolToDeclarationReference(parentSymbol, parentSymbol.flags,
|
|
252
|
+
/*includeModuleSymbols*/ true);
|
|
253
|
+
}
|
|
254
|
+
// If that doesn't work, try to find a parent symbol via the node tree. As far as we can tell,
|
|
255
|
+
// this logic is only needed for local symbols within namespaces. For example:
|
|
256
|
+
//
|
|
257
|
+
// ```
|
|
258
|
+
// export namespace n {
|
|
259
|
+
// type SomeType = number;
|
|
260
|
+
// export function someFunction(): SomeType { return 5; }
|
|
261
|
+
// }
|
|
262
|
+
// ```
|
|
263
|
+
//
|
|
264
|
+
// In the example above, `SomeType` doesn't have a parent symbol per the TS internal API above,
|
|
265
|
+
// but its reference still needs to be qualified with the parent reference for `n`.
|
|
266
|
+
const grandParent = (_a = declaration === null || declaration === void 0 ? void 0 : declaration.parent) === null || _a === void 0 ? void 0 : _a.parent;
|
|
267
|
+
if (grandParent && ts.isModuleDeclaration(grandParent)) {
|
|
268
|
+
const grandParentSymbol = TypeScriptInternals_1.TypeScriptInternals.tryGetSymbolForDeclaration(grandParent, this._typeChecker);
|
|
269
|
+
if (grandParentSymbol) {
|
|
270
|
+
return this._symbolToDeclarationReference(grandParentSymbol, grandParentSymbol.flags,
|
|
271
|
+
/*includeModuleSymbols*/ true);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// At this point, we have a local symbol in a module.
|
|
275
|
+
const sourceFile = declaration === null || declaration === void 0 ? void 0 : declaration.getSourceFile();
|
|
276
|
+
if (sourceFile && ts.isExternalModule(sourceFile)) {
|
|
277
|
+
return new DeclarationReference_1.DeclarationReference(this._sourceFileToModuleSource(sourceFile));
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
return new DeclarationReference_1.DeclarationReference(DeclarationReference_1.GlobalSource.instance);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
263
283
|
_getPackageName(sourceFile) {
|
|
264
284
|
if (this._program.isSourceFileFromExternalLibrary(sourceFile)) {
|
|
265
285
|
const packageJson = this._packageJsonLookup.tryLoadNodePackageJsonFor(sourceFile.fileName);
|
|
@@ -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,EA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AgB,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 sourceFile: ts.SourceFile | undefined =\n followedSymbol.declarations &&\n followedSymbol.declarations[0] &&\n followedSymbol.declarations[0].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 const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(followedSymbol);\n let parentRef: DeclarationReference | undefined;\n if (parent) {\n parentRef = this._symbolToDeclarationReference(\n parent,\n ts.SymbolFlags.Namespace,\n /*includeModuleSymbols*/ true\n );\n } else {\n // this may be a local symbol in a module...\n const sourceFile: ts.SourceFile | undefined =\n followedSymbol.declarations &&\n followedSymbol.declarations[0] &&\n followedSymbol.declarations[0].getSourceFile();\n if (sourceFile && ts.isExternalModule(sourceFile)) {\n parentRef = new DeclarationReference(this._sourceFileToModuleSource(sourceFile));\n } else {\n parentRef = new DeclarationReference(GlobalSource.instance);\n }\n }\n\n if (parentRef === undefined) {\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 _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"],"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,CA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AO,6BAA6B,CAAC,gBAAgB,CAAC;SACvD;QACD,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,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,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"]}
|
|
@@ -31,6 +31,17 @@ export declare class ExcerptBuilder {
|
|
|
31
31
|
static createEmptyTokenRange(): IExcerptTokenRange;
|
|
32
32
|
private static _buildSpan;
|
|
33
33
|
private static _appendToken;
|
|
34
|
+
/**
|
|
35
|
+
* Condenses the provided excerpt tokens by merging tokens where possible. Updates the provided token ranges to
|
|
36
|
+
* remain accurate after token merging.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* For example, suppose we have excerpt tokens ["A", "B", "C"] and a token range [0, 2]. If the excerpt tokens
|
|
40
|
+
* are condensed to ["AB", "C"], then the token range would be updated to [0, 1]. Note that merges are only
|
|
41
|
+
* performed if they are compatible with the provided token ranges. In the example above, if our token range was
|
|
42
|
+
* originally [0, 1], we would not be able to merge tokens "A" and "B".
|
|
43
|
+
*/
|
|
44
|
+
private static _condenseTokens;
|
|
34
45
|
private static _isDeclarationName;
|
|
35
46
|
private static _isDeclaration;
|
|
36
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExcerptBuilder.d.ts","sourceRoot":"","sources":["../../src/generators/ExcerptBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAoB,aAAa,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGrG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,SAAS,CAAC;IAC1B;;;OAGG;IACH,UAAU,EAAE,kBAAkB,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"ExcerptBuilder.d.ts","sourceRoot":"","sources":["../../src/generators/ExcerptBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAoB,aAAa,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGrG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,SAAS,CAAC;IAC1B;;;OAGG;IACH,UAAU,EAAE,kBAAkB,CAAC;CAChC;AAiCD,qBAAa,cAAc;IACzB;;;OAGG;WACW,YAAY,CAAC,aAAa,EAAE,aAAa,EAAE,GAAG,IAAI;IAYhE;;;;OAIG;WACW,cAAc,CAC1B,aAAa,EAAE,aAAa,EAAE,EAC9B,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,4BAA4B,EAAE,EAC9C,kBAAkB,EAAE,6BAA6B,GAChD,IAAI;WAmCO,qBAAqB,IAAI,kBAAkB;IAIzD,OAAO,CAAC,MAAM,CAAC,UAAU;IA8EzB,OAAO,CAAC,MAAM,CAAC,YAAY;IAiB3B;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IA8E9B,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAIjC,OAAO,CAAC,MAAM,CAAC,cAAc;CA0B9B"}
|
|
@@ -76,9 +76,9 @@ class ExcerptBuilder {
|
|
|
76
76
|
startingNode: span.node,
|
|
77
77
|
stopBeforeChildKind,
|
|
78
78
|
tokenRangesByNode,
|
|
79
|
-
disableMergingForNextToken: false,
|
|
80
79
|
lastAppendedTokenIsSeparator: false
|
|
81
80
|
});
|
|
81
|
+
ExcerptBuilder._condenseTokens(excerptTokens, [...tokenRangesByNode.values()]);
|
|
82
82
|
}
|
|
83
83
|
static createEmptyTokenRange() {
|
|
84
84
|
return { startIndex: 0, endIndex: 0 };
|
|
@@ -94,7 +94,6 @@ class ExcerptBuilder {
|
|
|
94
94
|
if (capturedTokenRange) {
|
|
95
95
|
// We will assign capturedTokenRange.startIndex to be the index of the next token to be appended
|
|
96
96
|
excerptStartIndex = excerptTokens.length;
|
|
97
|
-
state.disableMergingForNextToken = true;
|
|
98
97
|
}
|
|
99
98
|
if (span.prefix) {
|
|
100
99
|
let canonicalReference = undefined;
|
|
@@ -105,10 +104,10 @@ class ExcerptBuilder {
|
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
if (canonicalReference) {
|
|
108
|
-
ExcerptBuilder._appendToken(excerptTokens, api_extractor_model_1.ExcerptTokenKind.Reference, span.prefix,
|
|
107
|
+
ExcerptBuilder._appendToken(excerptTokens, api_extractor_model_1.ExcerptTokenKind.Reference, span.prefix, canonicalReference);
|
|
109
108
|
}
|
|
110
109
|
else {
|
|
111
|
-
ExcerptBuilder._appendToken(excerptTokens, api_extractor_model_1.ExcerptTokenKind.Content, span.prefix
|
|
110
|
+
ExcerptBuilder._appendToken(excerptTokens, api_extractor_model_1.ExcerptTokenKind.Content, span.prefix);
|
|
112
111
|
}
|
|
113
112
|
state.lastAppendedTokenIsSeparator = false;
|
|
114
113
|
}
|
|
@@ -124,69 +123,115 @@ class ExcerptBuilder {
|
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
if (span.suffix) {
|
|
127
|
-
ExcerptBuilder._appendToken(excerptTokens, api_extractor_model_1.ExcerptTokenKind.Content, span.suffix
|
|
126
|
+
ExcerptBuilder._appendToken(excerptTokens, api_extractor_model_1.ExcerptTokenKind.Content, span.suffix);
|
|
128
127
|
state.lastAppendedTokenIsSeparator = false;
|
|
129
128
|
}
|
|
130
129
|
if (span.separator) {
|
|
131
|
-
ExcerptBuilder._appendToken(excerptTokens, api_extractor_model_1.ExcerptTokenKind.Content, span.separator
|
|
130
|
+
ExcerptBuilder._appendToken(excerptTokens, api_extractor_model_1.ExcerptTokenKind.Content, span.separator);
|
|
132
131
|
state.lastAppendedTokenIsSeparator = true;
|
|
133
132
|
}
|
|
134
133
|
// Are we building a excerpt? If so, set its range
|
|
135
134
|
if (capturedTokenRange) {
|
|
136
135
|
capturedTokenRange.startIndex = excerptStartIndex;
|
|
137
136
|
// We will assign capturedTokenRange.startIndex to be the index after the last token
|
|
138
|
-
// that was appended so far. However, if the last appended token was a separator
|
|
139
|
-
//
|
|
137
|
+
// that was appended so far. However, if the last appended token was a separator, omit
|
|
138
|
+
// it from the range.
|
|
140
139
|
let excerptEndIndex = excerptTokens.length;
|
|
141
|
-
if (state.lastAppendedTokenIsSeparator
|
|
140
|
+
if (state.lastAppendedTokenIsSeparator) {
|
|
142
141
|
excerptEndIndex--;
|
|
143
142
|
}
|
|
144
143
|
capturedTokenRange.endIndex = excerptEndIndex;
|
|
145
|
-
state.disableMergingForNextToken = true;
|
|
146
144
|
}
|
|
147
145
|
return true;
|
|
148
146
|
}
|
|
149
|
-
static _appendToken(excerptTokens, excerptTokenKind, text,
|
|
147
|
+
static _appendToken(excerptTokens, excerptTokenKind, text, canonicalReference) {
|
|
150
148
|
if (text.length === 0) {
|
|
151
149
|
return;
|
|
152
150
|
}
|
|
153
|
-
if (excerptTokenKind !== api_extractor_model_1.ExcerptTokenKind.Content) {
|
|
154
|
-
if (excerptTokenKind === api_extractor_model_1.ExcerptTokenKind.Reference &&
|
|
155
|
-
excerptTokens.length > 1 &&
|
|
156
|
-
!state.disableMergingForNextToken) {
|
|
157
|
-
// If the previous two tokens were a Reference and a '.', then concatenate
|
|
158
|
-
// all three tokens as a qualified name Reference.
|
|
159
|
-
const previousTokenM1 = excerptTokens[excerptTokens.length - 1];
|
|
160
|
-
const previousTokenM2 = excerptTokens[excerptTokens.length - 2];
|
|
161
|
-
if (previousTokenM1.kind === api_extractor_model_1.ExcerptTokenKind.Content &&
|
|
162
|
-
previousTokenM1.text.trim() === '.' &&
|
|
163
|
-
previousTokenM2.kind === api_extractor_model_1.ExcerptTokenKind.Reference) {
|
|
164
|
-
previousTokenM2.text += '.' + text;
|
|
165
|
-
if (canonicalReference !== undefined) {
|
|
166
|
-
previousTokenM2.canonicalReference = canonicalReference.toString();
|
|
167
|
-
}
|
|
168
|
-
excerptTokens.pop(); // remove previousTokenM1;
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
// If someone referenced this index, then we need to start a new token
|
|
175
|
-
if (excerptTokens.length > 0 && !state.disableMergingForNextToken) {
|
|
176
|
-
// Otherwise, can we merge with the previous token?
|
|
177
|
-
const previousToken = excerptTokens[excerptTokens.length - 1];
|
|
178
|
-
if (previousToken.kind === excerptTokenKind) {
|
|
179
|
-
previousToken.text += text;
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
151
|
const excerptToken = { kind: excerptTokenKind, text: text };
|
|
185
152
|
if (canonicalReference !== undefined) {
|
|
186
153
|
excerptToken.canonicalReference = canonicalReference.toString();
|
|
187
154
|
}
|
|
188
155
|
excerptTokens.push(excerptToken);
|
|
189
|
-
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Condenses the provided excerpt tokens by merging tokens where possible. Updates the provided token ranges to
|
|
159
|
+
* remain accurate after token merging.
|
|
160
|
+
*
|
|
161
|
+
* @remarks
|
|
162
|
+
* For example, suppose we have excerpt tokens ["A", "B", "C"] and a token range [0, 2]. If the excerpt tokens
|
|
163
|
+
* are condensed to ["AB", "C"], then the token range would be updated to [0, 1]. Note that merges are only
|
|
164
|
+
* performed if they are compatible with the provided token ranges. In the example above, if our token range was
|
|
165
|
+
* originally [0, 1], we would not be able to merge tokens "A" and "B".
|
|
166
|
+
*/
|
|
167
|
+
static _condenseTokens(excerptTokens, tokenRanges) {
|
|
168
|
+
// This set is used to quickly lookup a start or end index.
|
|
169
|
+
const startOrEndIndices = new Set();
|
|
170
|
+
for (const tokenRange of tokenRanges) {
|
|
171
|
+
startOrEndIndices.add(tokenRange.startIndex);
|
|
172
|
+
startOrEndIndices.add(tokenRange.endIndex);
|
|
173
|
+
}
|
|
174
|
+
for (let currentIndex = 1; currentIndex < excerptTokens.length; ++currentIndex) {
|
|
175
|
+
while (currentIndex < excerptTokens.length) {
|
|
176
|
+
const prevPrevToken = excerptTokens[currentIndex - 2]; // May be undefined
|
|
177
|
+
const prevToken = excerptTokens[currentIndex - 1];
|
|
178
|
+
const currentToken = excerptTokens[currentIndex];
|
|
179
|
+
// The number of excerpt tokens that are merged in this iteration. We need this to determine
|
|
180
|
+
// how to update the start and end indices of our token ranges.
|
|
181
|
+
let mergeCount;
|
|
182
|
+
// There are two types of merges that can occur. We only perform these merges if they are
|
|
183
|
+
// compatible with all of our token ranges.
|
|
184
|
+
if (prevPrevToken &&
|
|
185
|
+
prevPrevToken.kind === api_extractor_model_1.ExcerptTokenKind.Reference &&
|
|
186
|
+
prevToken.kind === api_extractor_model_1.ExcerptTokenKind.Content &&
|
|
187
|
+
prevToken.text.trim() === '.' &&
|
|
188
|
+
currentToken.kind === api_extractor_model_1.ExcerptTokenKind.Reference &&
|
|
189
|
+
!startOrEndIndices.has(currentIndex) &&
|
|
190
|
+
!startOrEndIndices.has(currentIndex - 1)) {
|
|
191
|
+
// If the current token is a reference token, the previous token is a ".", and the previous-
|
|
192
|
+
// previous token is a reference token, then merge all three tokens into a reference token.
|
|
193
|
+
//
|
|
194
|
+
// For example: Given ["MyNamespace" (R), ".", "MyClass" (R)], tokens "." and "MyClass" might
|
|
195
|
+
// be merged into "MyNamespace". The condensed token would be ["MyNamespace.MyClass" (R)].
|
|
196
|
+
prevPrevToken.text += prevToken.text + currentToken.text;
|
|
197
|
+
prevPrevToken.canonicalReference = currentToken.canonicalReference;
|
|
198
|
+
mergeCount = 2;
|
|
199
|
+
currentIndex--;
|
|
200
|
+
}
|
|
201
|
+
else if (
|
|
202
|
+
// If the current and previous tokens are both content tokens, then merge the tokens into a
|
|
203
|
+
// single content token. For example: Given ["export ", "declare class"], these tokens
|
|
204
|
+
// might be merged into "export declare class".
|
|
205
|
+
prevToken.kind === api_extractor_model_1.ExcerptTokenKind.Content &&
|
|
206
|
+
prevToken.kind === currentToken.kind &&
|
|
207
|
+
!startOrEndIndices.has(currentIndex)) {
|
|
208
|
+
prevToken.text += currentToken.text;
|
|
209
|
+
mergeCount = 1;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
// Otherwise, no merging can occur here. Continue to the next index.
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
// Remove the now redundant excerpt token(s), as they were merged into a previous token.
|
|
216
|
+
excerptTokens.splice(currentIndex, mergeCount);
|
|
217
|
+
// Update the start and end indices for all token ranges based upon how many excerpt
|
|
218
|
+
// tokens were merged and in what positions.
|
|
219
|
+
for (const tokenRange of tokenRanges) {
|
|
220
|
+
if (tokenRange.startIndex > currentIndex) {
|
|
221
|
+
tokenRange.startIndex -= mergeCount;
|
|
222
|
+
}
|
|
223
|
+
if (tokenRange.endIndex > currentIndex) {
|
|
224
|
+
tokenRange.endIndex -= mergeCount;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// Clear and repopulate our set with the updated indices.
|
|
228
|
+
startOrEndIndices.clear();
|
|
229
|
+
for (const tokenRange of tokenRanges) {
|
|
230
|
+
startOrEndIndices.add(tokenRange.startIndex);
|
|
231
|
+
startOrEndIndices.add(tokenRange.endIndex);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
190
235
|
}
|
|
191
236
|
static _isDeclarationName(name) {
|
|
192
237
|
return ExcerptBuilder._isDeclaration(name.parent) && name.parent.name === name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExcerptBuilder.js","sourceRoot":"","sources":["../../src/generators/ExcerptBuilder.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+CAAiC;AAEjC,wEAAqG;AAErG,2CAAwC;AAyDxC,MAAa,cAAc;IACzB;;;OAG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AC;YACnC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;YACrC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;YACrC,KAAK,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;YACnC,KAAK,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC;YACvC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;YACrC,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;YAC/B,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;YAC/B,KAAK,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC;YACxC,KAAK,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC;YACxC,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;YACjC,KAAK,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAC9B,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc;gBAC/B,OAAO,IAAI,CAAC;YACd;gBACE,OAAO,KAAK,CAAC;SAChB;IACH,CAAC;CACF;AAxOD,wCAwOC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as ts from 'typescript';\nimport { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';\nimport { ExcerptTokenKind, IExcerptToken, IExcerptTokenRange } from '@microsoft/api-extractor-model';\n\nimport { Span } from '../analyzer/Span';\nimport { DeclarationReferenceGenerator } from './DeclarationReferenceGenerator';\nimport { AstDeclaration } from '../analyzer/AstDeclaration';\n\n/**\n * Used to provide ExcerptBuilder with a list of nodes whose token range we want to capture.\n */\nexport interface IExcerptBuilderNodeToCapture {\n /**\n * The node to capture\n */\n node: ts.Node | undefined;\n /**\n * The token range whose startIndex/endIndex will be overwritten with the indexes for the\n * tokens corresponding to IExcerptBuilderNodeToCapture.node\n */\n tokenRange: IExcerptTokenRange;\n}\n\n/**\n * Internal state for ExcerptBuilder\n */\ninterface IBuildSpanState {\n referenceGenerator: DeclarationReferenceGenerator;\n\n /**\n * The AST node that we will traverse to extract tokens\n */\n startingNode: ts.Node;\n\n /**\n * Normally, the excerpt will include all child nodes for `startingNode`; whereas if `childKindToStopBefore`\n * is specified, then the node traversal will stop before (i.e. excluding) the first immediate child\n * of `startingNode` with the specified syntax kind.\n *\n * @remarks\n * For example, suppose the signature is `interface X: Y { z: string }`. The token `{` has syntax kind\n * `ts.SyntaxKind.FirstPunctuation`, so we can specify that to truncate the excerpt to `interface X: Y`.\n */\n stopBeforeChildKind: ts.SyntaxKind | undefined;\n\n tokenRangesByNode: Map<ts.Node, IExcerptTokenRange>;\n\n /**\n * Normally adjacent tokens of the same kind get merged, to avoid creating lots of unnecessary extra tokens.\n * However when an captured excerpt needs to start/end at a specific character, we temporarily disable merging by\n * setting this flag. After the new token is added, this flag is cleared.\n */\n disableMergingForNextToken: boolean;\n\n /**\n * Tracks whether the last appended token was a separator. If so, and we're in the middle of\n * capturing a token range, then omit the separator from the range.\n */\n lastAppendedTokenIsSeparator: boolean;\n}\n\nexport class ExcerptBuilder {\n /**\n * Appends a blank line to the `excerptTokens` list.\n * @param excerptTokens - The target token list to append to\n */\n public static addBlankLine(excerptTokens: IExcerptToken[]): void {\n let newlines: string = '\\n\\n';\n // If the existing text already ended with a newline, then only append one newline\n if (excerptTokens.length > 0) {\n const previousText: string = excerptTokens[excerptTokens.length - 1].text;\n if (/\\n$/.test(previousText)) {\n newlines = '\\n';\n }\n }\n excerptTokens.push({ kind: ExcerptTokenKind.Content, text: newlines });\n }\n\n /**\n * Appends the signature for the specified `AstDeclaration` to the `excerptTokens` list.\n * @param excerptTokens - The target token list to append to\n * @param nodesToCapture - A list of child nodes whose token ranges we want to capture\n */\n public static addDeclaration(\n excerptTokens: IExcerptToken[],\n astDeclaration: AstDeclaration,\n nodesToCapture: IExcerptBuilderNodeToCapture[],\n referenceGenerator: DeclarationReferenceGenerator\n ): void {\n let stopBeforeChildKind: ts.SyntaxKind | undefined = undefined;\n\n switch (astDeclaration.declaration.kind) {\n case ts.SyntaxKind.ClassDeclaration:\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.InterfaceDeclaration:\n // FirstPunctuation = \"{\"\n stopBeforeChildKind = ts.SyntaxKind.FirstPunctuation;\n break;\n case ts.SyntaxKind.ModuleDeclaration:\n // ModuleBlock = the \"{ ... }\" block\n stopBeforeChildKind = ts.SyntaxKind.ModuleBlock;\n break;\n }\n\n const span: Span = new Span(astDeclaration.declaration);\n\n const tokenRangesByNode: Map<ts.Node, IExcerptTokenRange> = new Map<ts.Node, IExcerptTokenRange>();\n for (const excerpt of nodesToCapture || []) {\n if (excerpt.node) {\n tokenRangesByNode.set(excerpt.node, excerpt.tokenRange);\n }\n }\n\n ExcerptBuilder._buildSpan(excerptTokens, span, {\n referenceGenerator: referenceGenerator,\n startingNode: span.node,\n stopBeforeChildKind,\n tokenRangesByNode,\n disableMergingForNextToken: false,\n lastAppendedTokenIsSeparator: false\n });\n }\n\n public static createEmptyTokenRange(): IExcerptTokenRange {\n return { startIndex: 0, endIndex: 0 };\n }\n\n private static _buildSpan(excerptTokens: IExcerptToken[], span: Span, state: IBuildSpanState): boolean {\n if (span.kind === ts.SyntaxKind.JSDocComment) {\n // Discard any comments\n return true;\n }\n\n // Can this node start a excerpt?\n const capturedTokenRange: IExcerptTokenRange | undefined = state.tokenRangesByNode.get(span.node);\n let excerptStartIndex: number = 0;\n\n if (capturedTokenRange) {\n // We will assign capturedTokenRange.startIndex to be the index of the next token to be appended\n excerptStartIndex = excerptTokens.length;\n state.disableMergingForNextToken = true;\n }\n\n if (span.prefix) {\n let canonicalReference: DeclarationReference | undefined = undefined;\n\n if (span.kind === ts.SyntaxKind.Identifier) {\n const name: ts.Identifier = span.node as ts.Identifier;\n if (!ExcerptBuilder._isDeclarationName(name)) {\n canonicalReference = state.referenceGenerator.getDeclarationReferenceForIdentifier(name);\n }\n }\n\n if (canonicalReference) {\n ExcerptBuilder._appendToken(\n excerptTokens,\n ExcerptTokenKind.Reference,\n span.prefix,\n state,\n canonicalReference\n );\n } else {\n ExcerptBuilder._appendToken(excerptTokens, ExcerptTokenKind.Content, span.prefix, state);\n }\n state.lastAppendedTokenIsSeparator = false;\n }\n\n for (const child of span.children) {\n if (span.node === state.startingNode) {\n if (state.stopBeforeChildKind && child.kind === state.stopBeforeChildKind) {\n // We reached a child whose kind is stopBeforeChildKind, so stop traversing\n return false;\n }\n }\n\n if (!this._buildSpan(excerptTokens, child, state)) {\n return false;\n }\n }\n\n if (span.suffix) {\n ExcerptBuilder._appendToken(excerptTokens, ExcerptTokenKind.Content, span.suffix, state);\n state.lastAppendedTokenIsSeparator = false;\n }\n if (span.separator) {\n ExcerptBuilder._appendToken(excerptTokens, ExcerptTokenKind.Content, span.separator, state);\n state.lastAppendedTokenIsSeparator = true;\n }\n\n // Are we building a excerpt? If so, set its range\n if (capturedTokenRange) {\n capturedTokenRange.startIndex = excerptStartIndex;\n\n // We will assign capturedTokenRange.startIndex to be the index after the last token\n // that was appended so far. However, if the last appended token was a separator and\n // there is no additional spaces, omit it from the range.\n let excerptEndIndex: number = excerptTokens.length;\n if (state.lastAppendedTokenIsSeparator && excerptEndIndex > excerptStartIndex + 1) {\n excerptEndIndex--;\n }\n\n capturedTokenRange.endIndex = excerptEndIndex;\n\n state.disableMergingForNextToken = true;\n }\n\n return true;\n }\n\n private static _appendToken(\n excerptTokens: IExcerptToken[],\n excerptTokenKind: ExcerptTokenKind,\n text: string,\n state: IBuildSpanState,\n canonicalReference?: DeclarationReference\n ): void {\n if (text.length === 0) {\n return;\n }\n\n if (excerptTokenKind !== ExcerptTokenKind.Content) {\n if (\n excerptTokenKind === ExcerptTokenKind.Reference &&\n excerptTokens.length > 1 &&\n !state.disableMergingForNextToken\n ) {\n // If the previous two tokens were a Reference and a '.', then concatenate\n // all three tokens as a qualified name Reference.\n const previousTokenM1: IExcerptToken = excerptTokens[excerptTokens.length - 1];\n const previousTokenM2: IExcerptToken = excerptTokens[excerptTokens.length - 2];\n if (\n previousTokenM1.kind === ExcerptTokenKind.Content &&\n previousTokenM1.text.trim() === '.' &&\n previousTokenM2.kind === ExcerptTokenKind.Reference\n ) {\n previousTokenM2.text += '.' + text;\n if (canonicalReference !== undefined) {\n previousTokenM2.canonicalReference = canonicalReference.toString();\n }\n excerptTokens.pop(); // remove previousTokenM1;\n return;\n }\n }\n } else {\n // If someone referenced this index, then we need to start a new token\n if (excerptTokens.length > 0 && !state.disableMergingForNextToken) {\n // Otherwise, can we merge with the previous token?\n const previousToken: IExcerptToken = excerptTokens[excerptTokens.length - 1];\n if (previousToken.kind === excerptTokenKind) {\n previousToken.text += text;\n return;\n }\n }\n }\n\n const excerptToken: IExcerptToken = { kind: excerptTokenKind, text: text };\n if (canonicalReference !== undefined) {\n excerptToken.canonicalReference = canonicalReference.toString();\n }\n excerptTokens.push(excerptToken);\n state.disableMergingForNextToken = false;\n }\n\n private static _isDeclarationName(name: ts.Identifier): boolean {\n return ExcerptBuilder._isDeclaration(name.parent) && name.parent.name === name;\n }\n\n private static _isDeclaration(node: ts.Node): node is ts.NamedDeclaration {\n switch (node.kind) {\n case ts.SyntaxKind.FunctionDeclaration:\n case ts.SyntaxKind.FunctionExpression:\n case ts.SyntaxKind.VariableDeclaration:\n case ts.SyntaxKind.Parameter:\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.ClassDeclaration:\n case ts.SyntaxKind.ClassExpression:\n case ts.SyntaxKind.ModuleDeclaration:\n case ts.SyntaxKind.MethodDeclaration:\n case ts.SyntaxKind.MethodSignature:\n case ts.SyntaxKind.PropertyDeclaration:\n case ts.SyntaxKind.PropertySignature:\n case ts.SyntaxKind.GetAccessor:\n case ts.SyntaxKind.SetAccessor:\n case ts.SyntaxKind.InterfaceDeclaration:\n case ts.SyntaxKind.TypeAliasDeclaration:\n case ts.SyntaxKind.TypeParameter:\n case ts.SyntaxKind.EnumMember:\n case ts.SyntaxKind.BindingElement:\n return true;\n default:\n return false;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExcerptBuilder.js","sourceRoot":"","sources":["../../src/generators/ExcerptBuilder.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+CAAiC;AAEjC,wEAAqG;AAErG,2CAAwC;AAkDxC,MAAa,cAAc;IACzB;;;OAGG;IACI,MAAM,CAAC,YAAY,CAAC,aAA8B;QACvD,IAAI,QAAQ,GAAW,MAAM,CAAC;QAC9B,kFAAkF;QAClF,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,MAAM,YAAY,GAAW,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;YAC1E,IAAI,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE;gBAC5B,QAAQ,GAAG,IAAI,CAAC;aACjB;SACF;QACD,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,sCAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAC1B,aAA8B,EAC9B,cAA8B,EAC9B,cAA8C,EAC9C,kBAAiD;QAEjD,IAAI,mBAAmB,GAA8B,SAAS,CAAC;QAE/D,QAAQ,cAAc,CAAC,WAAW,CAAC,IAAI,EAAE;YACvC,KAAK,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC;YACpC,KAAK,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;YACnC,KAAK,EAAE,CAAC,UAAU,CAAC,oBAAoB;gBACrC,yBAAyB;gBACzB,mBAAmB,GAAG,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC;gBACrD,MAAM;YACR,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB;gBAClC,oCAAoC;gBACpC,mBAAmB,GAAG,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AAE,CAAC,UAAU,CAAC,eAAe,CAAC;YACnC,KAAK,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC;YACpC,KAAK,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;YACnC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;YACrC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;YACrC,KAAK,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;YACnC,KAAK,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC;YACvC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;YACrC,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;YAC/B,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;YAC/B,KAAK,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC;YACxC,KAAK,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC;YACxC,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;YACjC,KAAK,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAC9B,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc;gBAC/B,OAAO,IAAI,CAAC;YACd;gBACE,OAAO,KAAK,CAAC;SAChB;IACH,CAAC;CACF;AAvRD,wCAuRC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as ts from 'typescript';\nimport { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';\nimport { ExcerptTokenKind, IExcerptToken, IExcerptTokenRange } from '@microsoft/api-extractor-model';\n\nimport { Span } from '../analyzer/Span';\nimport { DeclarationReferenceGenerator } from './DeclarationReferenceGenerator';\nimport { AstDeclaration } from '../analyzer/AstDeclaration';\n\n/**\n * Used to provide ExcerptBuilder with a list of nodes whose token range we want to capture.\n */\nexport interface IExcerptBuilderNodeToCapture {\n /**\n * The node to capture\n */\n node: ts.Node | undefined;\n /**\n * The token range whose startIndex/endIndex will be overwritten with the indexes for the\n * tokens corresponding to IExcerptBuilderNodeToCapture.node\n */\n tokenRange: IExcerptTokenRange;\n}\n\n/**\n * Internal state for ExcerptBuilder\n */\ninterface IBuildSpanState {\n referenceGenerator: DeclarationReferenceGenerator;\n\n /**\n * The AST node that we will traverse to extract tokens\n */\n startingNode: ts.Node;\n\n /**\n * Normally, the excerpt will include all child nodes for `startingNode`; whereas if `childKindToStopBefore`\n * is specified, then the node traversal will stop before (i.e. excluding) the first immediate child\n * of `startingNode` with the specified syntax kind.\n *\n * @remarks\n * For example, suppose the signature is `interface X: Y { z: string }`. The token `{` has syntax kind\n * `ts.SyntaxKind.FirstPunctuation`, so we can specify that to truncate the excerpt to `interface X: Y`.\n */\n stopBeforeChildKind: ts.SyntaxKind | undefined;\n\n tokenRangesByNode: Map<ts.Node, IExcerptTokenRange>;\n\n /**\n * Tracks whether the last appended token was a separator. If so, and we're in the middle of\n * capturing a token range, then omit the separator from the range.\n */\n lastAppendedTokenIsSeparator: boolean;\n}\n\nexport class ExcerptBuilder {\n /**\n * Appends a blank line to the `excerptTokens` list.\n * @param excerptTokens - The target token list to append to\n */\n public static addBlankLine(excerptTokens: IExcerptToken[]): void {\n let newlines: string = '\\n\\n';\n // If the existing text already ended with a newline, then only append one newline\n if (excerptTokens.length > 0) {\n const previousText: string = excerptTokens[excerptTokens.length - 1].text;\n if (/\\n$/.test(previousText)) {\n newlines = '\\n';\n }\n }\n excerptTokens.push({ kind: ExcerptTokenKind.Content, text: newlines });\n }\n\n /**\n * Appends the signature for the specified `AstDeclaration` to the `excerptTokens` list.\n * @param excerptTokens - The target token list to append to\n * @param nodesToCapture - A list of child nodes whose token ranges we want to capture\n */\n public static addDeclaration(\n excerptTokens: IExcerptToken[],\n astDeclaration: AstDeclaration,\n nodesToCapture: IExcerptBuilderNodeToCapture[],\n referenceGenerator: DeclarationReferenceGenerator\n ): void {\n let stopBeforeChildKind: ts.SyntaxKind | undefined = undefined;\n\n switch (astDeclaration.declaration.kind) {\n case ts.SyntaxKind.ClassDeclaration:\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.InterfaceDeclaration:\n // FirstPunctuation = \"{\"\n stopBeforeChildKind = ts.SyntaxKind.FirstPunctuation;\n break;\n case ts.SyntaxKind.ModuleDeclaration:\n // ModuleBlock = the \"{ ... }\" block\n stopBeforeChildKind = ts.SyntaxKind.ModuleBlock;\n break;\n }\n\n const span: Span = new Span(astDeclaration.declaration);\n\n const tokenRangesByNode: Map<ts.Node, IExcerptTokenRange> = new Map<ts.Node, IExcerptTokenRange>();\n for (const excerpt of nodesToCapture || []) {\n if (excerpt.node) {\n tokenRangesByNode.set(excerpt.node, excerpt.tokenRange);\n }\n }\n\n ExcerptBuilder._buildSpan(excerptTokens, span, {\n referenceGenerator: referenceGenerator,\n startingNode: span.node,\n stopBeforeChildKind,\n tokenRangesByNode,\n lastAppendedTokenIsSeparator: false\n });\n ExcerptBuilder._condenseTokens(excerptTokens, [...tokenRangesByNode.values()]);\n }\n\n public static createEmptyTokenRange(): IExcerptTokenRange {\n return { startIndex: 0, endIndex: 0 };\n }\n\n private static _buildSpan(excerptTokens: IExcerptToken[], span: Span, state: IBuildSpanState): boolean {\n if (span.kind === ts.SyntaxKind.JSDocComment) {\n // Discard any comments\n return true;\n }\n\n // Can this node start a excerpt?\n const capturedTokenRange: IExcerptTokenRange | undefined = state.tokenRangesByNode.get(span.node);\n let excerptStartIndex: number = 0;\n\n if (capturedTokenRange) {\n // We will assign capturedTokenRange.startIndex to be the index of the next token to be appended\n excerptStartIndex = excerptTokens.length;\n }\n\n if (span.prefix) {\n let canonicalReference: DeclarationReference | undefined = undefined;\n\n if (span.kind === ts.SyntaxKind.Identifier) {\n const name: ts.Identifier = span.node as ts.Identifier;\n if (!ExcerptBuilder._isDeclarationName(name)) {\n canonicalReference = state.referenceGenerator.getDeclarationReferenceForIdentifier(name);\n }\n }\n\n if (canonicalReference) {\n ExcerptBuilder._appendToken(\n excerptTokens,\n ExcerptTokenKind.Reference,\n span.prefix,\n canonicalReference\n );\n } else {\n ExcerptBuilder._appendToken(excerptTokens, ExcerptTokenKind.Content, span.prefix);\n }\n state.lastAppendedTokenIsSeparator = false;\n }\n\n for (const child of span.children) {\n if (span.node === state.startingNode) {\n if (state.stopBeforeChildKind && child.kind === state.stopBeforeChildKind) {\n // We reached a child whose kind is stopBeforeChildKind, so stop traversing\n return false;\n }\n }\n\n if (!this._buildSpan(excerptTokens, child, state)) {\n return false;\n }\n }\n\n if (span.suffix) {\n ExcerptBuilder._appendToken(excerptTokens, ExcerptTokenKind.Content, span.suffix);\n state.lastAppendedTokenIsSeparator = false;\n }\n if (span.separator) {\n ExcerptBuilder._appendToken(excerptTokens, ExcerptTokenKind.Content, span.separator);\n state.lastAppendedTokenIsSeparator = true;\n }\n\n // Are we building a excerpt? If so, set its range\n if (capturedTokenRange) {\n capturedTokenRange.startIndex = excerptStartIndex;\n\n // We will assign capturedTokenRange.startIndex to be the index after the last token\n // that was appended so far. However, if the last appended token was a separator, omit\n // it from the range.\n let excerptEndIndex: number = excerptTokens.length;\n if (state.lastAppendedTokenIsSeparator) {\n excerptEndIndex--;\n }\n\n capturedTokenRange.endIndex = excerptEndIndex;\n }\n\n return true;\n }\n\n private static _appendToken(\n excerptTokens: IExcerptToken[],\n excerptTokenKind: ExcerptTokenKind,\n text: string,\n canonicalReference?: DeclarationReference\n ): void {\n if (text.length === 0) {\n return;\n }\n\n const excerptToken: IExcerptToken = { kind: excerptTokenKind, text: text };\n if (canonicalReference !== undefined) {\n excerptToken.canonicalReference = canonicalReference.toString();\n }\n excerptTokens.push(excerptToken);\n }\n\n /**\n * Condenses the provided excerpt tokens by merging tokens where possible. Updates the provided token ranges to\n * remain accurate after token merging.\n *\n * @remarks\n * For example, suppose we have excerpt tokens [\"A\", \"B\", \"C\"] and a token range [0, 2]. If the excerpt tokens\n * are condensed to [\"AB\", \"C\"], then the token range would be updated to [0, 1]. Note that merges are only\n * performed if they are compatible with the provided token ranges. In the example above, if our token range was\n * originally [0, 1], we would not be able to merge tokens \"A\" and \"B\".\n */\n private static _condenseTokens(excerptTokens: IExcerptToken[], tokenRanges: IExcerptTokenRange[]): void {\n // This set is used to quickly lookup a start or end index.\n const startOrEndIndices: Set<number> = new Set();\n for (const tokenRange of tokenRanges) {\n startOrEndIndices.add(tokenRange.startIndex);\n startOrEndIndices.add(tokenRange.endIndex);\n }\n\n for (let currentIndex: number = 1; currentIndex < excerptTokens.length; ++currentIndex) {\n while (currentIndex < excerptTokens.length) {\n const prevPrevToken: IExcerptToken = excerptTokens[currentIndex - 2]; // May be undefined\n const prevToken: IExcerptToken = excerptTokens[currentIndex - 1];\n const currentToken: IExcerptToken = excerptTokens[currentIndex];\n\n // The number of excerpt tokens that are merged in this iteration. We need this to determine\n // how to update the start and end indices of our token ranges.\n let mergeCount: number;\n\n // There are two types of merges that can occur. We only perform these merges if they are\n // compatible with all of our token ranges.\n if (\n prevPrevToken &&\n prevPrevToken.kind === ExcerptTokenKind.Reference &&\n prevToken.kind === ExcerptTokenKind.Content &&\n prevToken.text.trim() === '.' &&\n currentToken.kind === ExcerptTokenKind.Reference &&\n !startOrEndIndices.has(currentIndex) &&\n !startOrEndIndices.has(currentIndex - 1)\n ) {\n // If the current token is a reference token, the previous token is a \".\", and the previous-\n // previous token is a reference token, then merge all three tokens into a reference token.\n //\n // For example: Given [\"MyNamespace\" (R), \".\", \"MyClass\" (R)], tokens \".\" and \"MyClass\" might\n // be merged into \"MyNamespace\". The condensed token would be [\"MyNamespace.MyClass\" (R)].\n prevPrevToken.text += prevToken.text + currentToken.text;\n prevPrevToken.canonicalReference = currentToken.canonicalReference;\n mergeCount = 2;\n currentIndex--;\n } else if (\n // If the current and previous tokens are both content tokens, then merge the tokens into a\n // single content token. For example: Given [\"export \", \"declare class\"], these tokens\n // might be merged into \"export declare class\".\n prevToken.kind === ExcerptTokenKind.Content &&\n prevToken.kind === currentToken.kind &&\n !startOrEndIndices.has(currentIndex)\n ) {\n prevToken.text += currentToken.text;\n mergeCount = 1;\n } else {\n // Otherwise, no merging can occur here. Continue to the next index.\n break;\n }\n\n // Remove the now redundant excerpt token(s), as they were merged into a previous token.\n excerptTokens.splice(currentIndex, mergeCount);\n\n // Update the start and end indices for all token ranges based upon how many excerpt\n // tokens were merged and in what positions.\n for (const tokenRange of tokenRanges) {\n if (tokenRange.startIndex > currentIndex) {\n tokenRange.startIndex -= mergeCount;\n }\n\n if (tokenRange.endIndex > currentIndex) {\n tokenRange.endIndex -= mergeCount;\n }\n }\n\n // Clear and repopulate our set with the updated indices.\n startOrEndIndices.clear();\n for (const tokenRange of tokenRanges) {\n startOrEndIndices.add(tokenRange.startIndex);\n startOrEndIndices.add(tokenRange.endIndex);\n }\n }\n }\n }\n\n private static _isDeclarationName(name: ts.Identifier): boolean {\n return ExcerptBuilder._isDeclaration(name.parent) && name.parent.name === name;\n }\n\n private static _isDeclaration(node: ts.Node): node is ts.NamedDeclaration {\n switch (node.kind) {\n case ts.SyntaxKind.FunctionDeclaration:\n case ts.SyntaxKind.FunctionExpression:\n case ts.SyntaxKind.VariableDeclaration:\n case ts.SyntaxKind.Parameter:\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.ClassDeclaration:\n case ts.SyntaxKind.ClassExpression:\n case ts.SyntaxKind.ModuleDeclaration:\n case ts.SyntaxKind.MethodDeclaration:\n case ts.SyntaxKind.MethodSignature:\n case ts.SyntaxKind.PropertyDeclaration:\n case ts.SyntaxKind.PropertySignature:\n case ts.SyntaxKind.GetAccessor:\n case ts.SyntaxKind.SetAccessor:\n case ts.SyntaxKind.InterfaceDeclaration:\n case ts.SyntaxKind.TypeAliasDeclaration:\n case ts.SyntaxKind.TypeParameter:\n case ts.SyntaxKind.EnumMember:\n case ts.SyntaxKind.BindingElement:\n return true;\n default:\n return false;\n }\n }\n}\n"]}
|