Commit 956c501c authored by DatHV's avatar DatHV
Browse files

update build x-app-sdk

parent 9bb8aadd
{"version":3,"file":"AstModule.d.ts","sourceRoot":"","sources":["../../src/analyzer/AstModule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IAC3C,QAAQ,CAAC,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACvD,QAAQ,CAAC,2BAA2B,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;CACtD;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;IAC1B,YAAY,EAAE,EAAE,CAAC,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB;;;OAGG;IACH,SAAgB,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;IAE1C;;;OAGG;IACH,SAAgB,YAAY,EAAE,EAAE,CAAC,MAAM,CAAC;IAExC;;;OAGG;IACH,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IAEvD;;OAEG;IACH,SAAgB,mBAAmB,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IAEpD;;OAEG;IACH,SAAgB,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE/D;;OAEG;IACI,mBAAmB,EAAE,oBAAoB,GAAG,SAAS,CAAC;gBAE1C,OAAO,EAAE,iBAAiB;IAa7C;;OAEG;IACH,IAAW,UAAU,IAAI,OAAO,CAE/B;CACF"}
\ No newline at end of file
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AstModule = void 0;
/**
* An internal data structure that represents a source file that is analyzed by AstSymbolTable.
*/
class AstModule {
constructor(options) {
this.sourceFile = options.sourceFile;
this.moduleSymbol = options.moduleSymbol;
this.externalModulePath = options.externalModulePath;
this.starExportedModules = new Set();
this.cachedExportedEntities = new Map();
this.astModuleExportInfo = undefined;
}
/**
* If false, then this source file is part of the working package being processed by the `Collector`.
*/
get isExternal() {
return this.externalModulePath !== undefined;
}
}
exports.AstModule = AstModule;
//# sourceMappingURL=AstModule.js.map
\ No newline at end of file
{"version":3,"file":"AstModule.js","sourceRoot":"","sources":["../../src/analyzer/AstModule.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AA+B3D;;GAEG;AACH,MAAa,SAAS;IAkCpB,YAAmB,OAA0B;QAC3C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QAEzC,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QAErD,IAAI,CAAC,mBAAmB,GAAG,IAAI,GAAG,EAAa,CAAC;QAEhD,IAAI,CAAC,sBAAsB,GAAG,IAAI,GAAG,EAAqB,CAAC;QAE3D,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,kBAAkB,KAAK,SAAS,CAAC;IAC/C,CAAC;CACF;AArDD,8BAqDC","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 type * as ts from 'typescript';\n\nimport type { AstSymbol } from './AstSymbol';\nimport type { AstEntity } from './AstEntity';\n\n/**\n * Represents information collected by {@link AstSymbolTable.fetchAstModuleExportInfo}\n */\nexport interface IAstModuleExportInfo {\n readonly visitedAstModules: Set<AstModule>;\n readonly exportedLocalEntities: Map<string, AstEntity>;\n readonly starExportedExternalModules: Set<AstModule>;\n}\n\n/**\n * Constructor parameters for AstModule\n *\n * @privateRemarks\n * Our naming convention is to use I____Parameters for constructor options and\n * I____Options for general function options. However the word \"parameters\" is\n * confusingly similar to the terminology for function parameters modeled by API Extractor,\n * so we use I____Options for both cases in this code base.\n */\nexport interface IAstModuleOptions {\n sourceFile: ts.SourceFile;\n moduleSymbol: ts.Symbol;\n externalModulePath: string | undefined;\n}\n\n/**\n * An internal data structure that represents a source file that is analyzed by AstSymbolTable.\n */\nexport class AstModule {\n /**\n * The source file that declares this TypeScript module. In most cases, the source file's\n * top-level exports constitute the module.\n */\n public readonly sourceFile: ts.SourceFile;\n\n /**\n * The symbol for the module. Typically this corresponds to ts.SourceFile itself, however\n * in some cases the ts.SourceFile may contain multiple modules declared using the `module` keyword.\n */\n public readonly moduleSymbol: ts.Symbol;\n\n /**\n * Example: \"@rushstack/node-core-library/lib/FileSystem\"\n * but never: \"./FileSystem\"\n */\n public readonly externalModulePath: string | undefined;\n\n /**\n * A list of other `AstModule` objects that appear in `export * from \"___\";` statements.\n */\n public readonly starExportedModules: Set<AstModule>;\n\n /**\n * A partial map of entities exported by this module. The key is the exported name.\n */\n public readonly cachedExportedEntities: Map<string, AstEntity>; // exportName --> entity\n\n /**\n * Additional state calculated by `AstSymbolTable.fetchWorkingPackageModule()`.\n */\n public astModuleExportInfo: IAstModuleExportInfo | undefined;\n\n public constructor(options: IAstModuleOptions) {\n this.sourceFile = options.sourceFile;\n this.moduleSymbol = options.moduleSymbol;\n\n this.externalModulePath = options.externalModulePath;\n\n this.starExportedModules = new Set<AstModule>();\n\n this.cachedExportedEntities = new Map<string, AstSymbol>();\n\n this.astModuleExportInfo = undefined;\n }\n\n /**\n * If false, then this source file is part of the working package being processed by the `Collector`.\n */\n public get isExternal(): boolean {\n return this.externalModulePath !== undefined;\n }\n}\n"]}
\ No newline at end of file
import { AstNamespaceImport, type IAstNamespaceImportOptions } from './AstNamespaceImport';
export interface IAstNamespaceExportOptions extends IAstNamespaceImportOptions {
}
/**
* `AstNamespaceExport` represents a namespace that is created implicitly and exported by a statement
* such as `export * as example from "./file";`
*
* @remarks
*
* A typical input looks like this:
* ```ts
* // Suppose that example.ts exports two functions f1() and f2().
* export * as example from "./file";
* ```
*
* API Extractor's .d.ts rollup will transform it into an explicit namespace, like this:
* ```ts
* declare f1(): void;
* declare f2(): void;
*
* export declare namespace example {
* export {
* f1,
* f2
* }
* }
* ```
*
* The current implementation does not attempt to relocate f1()/f2() to be inside the `namespace`
* because other type signatures may reference them directly (without using the namespace qualifier).
* The AstNamespaceExports behaves the same as AstNamespaceImport, it just also has the inline export for the craeted namespace.
*/
export declare class AstNamespaceExport extends AstNamespaceImport {
constructor(options: IAstNamespaceExportOptions);
}
//# sourceMappingURL=AstNamespaceExport.d.ts.map
\ No newline at end of file
{"version":3,"file":"AstNamespaceExport.d.ts","sourceRoot":"","sources":["../../src/analyzer/AstNamespaceExport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,KAAK,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAE3F,MAAM,WAAW,0BAA2B,SAAQ,0BAA0B;CAAG;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,qBAAa,kBAAmB,SAAQ,kBAAkB;gBACrC,OAAO,EAAE,0BAA0B;CAGvD"}
\ No newline at end of file
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AstNamespaceExport = void 0;
const AstNamespaceImport_1 = require("./AstNamespaceImport");
/**
* `AstNamespaceExport` represents a namespace that is created implicitly and exported by a statement
* such as `export * as example from "./file";`
*
* @remarks
*
* A typical input looks like this:
* ```ts
* // Suppose that example.ts exports two functions f1() and f2().
* export * as example from "./file";
* ```
*
* API Extractor's .d.ts rollup will transform it into an explicit namespace, like this:
* ```ts
* declare f1(): void;
* declare f2(): void;
*
* export declare namespace example {
* export {
* f1,
* f2
* }
* }
* ```
*
* The current implementation does not attempt to relocate f1()/f2() to be inside the `namespace`
* because other type signatures may reference them directly (without using the namespace qualifier).
* The AstNamespaceExports behaves the same as AstNamespaceImport, it just also has the inline export for the craeted namespace.
*/
class AstNamespaceExport extends AstNamespaceImport_1.AstNamespaceImport {
constructor(options) {
super(options);
}
}
exports.AstNamespaceExport = AstNamespaceExport;
//# sourceMappingURL=AstNamespaceExport.js.map
\ No newline at end of file
{"version":3,"file":"AstNamespaceExport.js","sourceRoot":"","sources":["../../src/analyzer/AstNamespaceExport.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,6DAA2F;AAI3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,MAAa,kBAAmB,SAAQ,uCAAkB;IACxD,YAAmB,OAAmC;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,gDAIC","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 { AstNamespaceImport, type IAstNamespaceImportOptions } from './AstNamespaceImport';\n\nexport interface IAstNamespaceExportOptions extends IAstNamespaceImportOptions {}\n\n/**\n * `AstNamespaceExport` represents a namespace that is created implicitly and exported by a statement\n * such as `export * as example from \"./file\";`\n *\n * @remarks\n *\n * A typical input looks like this:\n * ```ts\n * // Suppose that example.ts exports two functions f1() and f2().\n * export * as example from \"./file\";\n * ```\n *\n * API Extractor's .d.ts rollup will transform it into an explicit namespace, like this:\n * ```ts\n * declare f1(): void;\n * declare f2(): void;\n *\n * export declare namespace example {\n * export {\n * f1,\n * f2\n * }\n * }\n * ```\n *\n * The current implementation does not attempt to relocate f1()/f2() to be inside the `namespace`\n * because other type signatures may reference them directly (without using the namespace qualifier).\n * The AstNamespaceExports behaves the same as AstNamespaceImport, it just also has the inline export for the craeted namespace.\n */\n\nexport class AstNamespaceExport extends AstNamespaceImport {\n public constructor(options: IAstNamespaceExportOptions) {\n super(options);\n }\n}\n"]}
\ No newline at end of file
import type * as ts from 'typescript';
import type { AstModule, IAstModuleExportInfo } from './AstModule';
import { AstSyntheticEntity } from './AstEntity';
import type { Collector } from '../collector/Collector';
export interface IAstNamespaceImportOptions {
readonly astModule: AstModule;
readonly namespaceName: string;
readonly declaration: ts.Declaration;
readonly symbol: ts.Symbol;
}
/**
* `AstNamespaceImport` represents a namespace that is created implicitly by a statement
* such as `import * as example from "./file";`
*
* @remarks
*
* A typical input looks like this:
* ```ts
* // Suppose that example.ts exports two functions f1() and f2().
* import * as example from "./file";
* export { example };
* ```
*
* API Extractor's .d.ts rollup will transform it into an explicit namespace, like this:
* ```ts
* declare f1(): void;
* declare f2(): void;
*
* declare namespace example {
* export {
* f1,
* f2
* }
* }
* ```
*
* The current implementation does not attempt to relocate f1()/f2() to be inside the `namespace`
* because other type signatures may reference them directly (without using the namespace qualifier).
* The `declare namespace example` is a synthetic construct represented by `AstNamespaceImport`.
*/
export declare class AstNamespaceImport extends AstSyntheticEntity {
/**
* Returns true if the AstSymbolTable.analyze() was called for this object.
* See that function for details.
*/
analyzed: boolean;
/**
* For example, if the original statement was `import * as example from "./file";`
* then `astModule` refers to the `./file.d.ts` file.
*/
readonly astModule: AstModule;
/**
* For example, if the original statement was `import * as example from "./file";`
* then `namespaceName` would be `example`.
*/
readonly namespaceName: string;
/**
* The original `ts.SyntaxKind.NamespaceImport` which can be used as a location for error messages.
*/
readonly declaration: ts.Declaration;
/**
* The original `ts.SymbolFlags.Namespace` symbol.
*/
readonly symbol: ts.Symbol;
constructor(options: IAstNamespaceImportOptions);
/** {@inheritdoc} */
get localName(): string;
fetchAstModuleExportInfo(collector: Collector): IAstModuleExportInfo;
}
//# sourceMappingURL=AstNamespaceImport.d.ts.map
\ No newline at end of file
{"version":3,"file":"AstNamespaceImport.d.ts","sourceRoot":"","sources":["../../src/analyzer/AstNamespaceImport.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,kBAAmB,SAAQ,kBAAkB;IACxD;;;OAGG;IACI,QAAQ,EAAE,OAAO,CAAS;IAEjC;;;OAGG;IACH,SAAgB,SAAS,EAAE,SAAS,CAAC;IAErC;;;OAGG;IACH,SAAgB,aAAa,EAAE,MAAM,CAAC;IAEtC;;OAEG;IACH,SAAgB,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC;IAE5C;;OAEG;IACH,SAAgB,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;gBAEf,OAAO,EAAE,0BAA0B;IAQtD,oBAAoB;IACpB,IAAW,SAAS,IAAI,MAAM,CAG7B;IAEM,wBAAwB,CAAC,SAAS,EAAE,SAAS,GAAG,oBAAoB;CAM5E"}
\ No newline at end of file
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AstNamespaceImport = void 0;
const AstEntity_1 = require("./AstEntity");
/**
* `AstNamespaceImport` represents a namespace that is created implicitly by a statement
* such as `import * as example from "./file";`
*
* @remarks
*
* A typical input looks like this:
* ```ts
* // Suppose that example.ts exports two functions f1() and f2().
* import * as example from "./file";
* export { example };
* ```
*
* API Extractor's .d.ts rollup will transform it into an explicit namespace, like this:
* ```ts
* declare f1(): void;
* declare f2(): void;
*
* declare namespace example {
* export {
* f1,
* f2
* }
* }
* ```
*
* The current implementation does not attempt to relocate f1()/f2() to be inside the `namespace`
* because other type signatures may reference them directly (without using the namespace qualifier).
* The `declare namespace example` is a synthetic construct represented by `AstNamespaceImport`.
*/
class AstNamespaceImport extends AstEntity_1.AstSyntheticEntity {
constructor(options) {
super();
/**
* Returns true if the AstSymbolTable.analyze() was called for this object.
* See that function for details.
*/
this.analyzed = false;
this.astModule = options.astModule;
this.namespaceName = options.namespaceName;
this.declaration = options.declaration;
this.symbol = options.symbol;
}
/** {@inheritdoc} */
get localName() {
// abstract
return this.namespaceName;
}
fetchAstModuleExportInfo(collector) {
const astModuleExportInfo = collector.astSymbolTable.fetchAstModuleExportInfo(this.astModule);
return astModuleExportInfo;
}
}
exports.AstNamespaceImport = AstNamespaceImport;
//# sourceMappingURL=AstNamespaceImport.js.map
\ No newline at end of file
{"version":3,"file":"AstNamespaceImport.js","sourceRoot":"","sources":["../../src/analyzer/AstNamespaceImport.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAK3D,2CAAiD;AAUjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAa,kBAAmB,SAAQ,8BAAkB;IA6BxD,YAAmB,OAAmC;QACpD,KAAK,EAAE,CAAC;QA7BV;;;WAGG;QACI,aAAQ,GAAY,KAAK,CAAC;QA0B/B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,oBAAoB;IACpB,IAAW,SAAS;QAClB,WAAW;QACX,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAEM,wBAAwB,CAAC,SAAoB;QAClD,MAAM,mBAAmB,GAAyB,SAAS,CAAC,cAAc,CAAC,wBAAwB,CACjG,IAAI,CAAC,SAAS,CACf,CAAC;QACF,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CACF;AAjDD,gDAiDC","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 type * as ts from 'typescript';\n\nimport type { AstModule, IAstModuleExportInfo } from './AstModule';\nimport { AstSyntheticEntity } from './AstEntity';\nimport type { Collector } from '../collector/Collector';\n\nexport interface IAstNamespaceImportOptions {\n readonly astModule: AstModule;\n readonly namespaceName: string;\n readonly declaration: ts.Declaration;\n readonly symbol: ts.Symbol;\n}\n\n/**\n * `AstNamespaceImport` represents a namespace that is created implicitly by a statement\n * such as `import * as example from \"./file\";`\n *\n * @remarks\n *\n * A typical input looks like this:\n * ```ts\n * // Suppose that example.ts exports two functions f1() and f2().\n * import * as example from \"./file\";\n * export { example };\n * ```\n *\n * API Extractor's .d.ts rollup will transform it into an explicit namespace, like this:\n * ```ts\n * declare f1(): void;\n * declare f2(): void;\n *\n * declare namespace example {\n * export {\n * f1,\n * f2\n * }\n * }\n * ```\n *\n * The current implementation does not attempt to relocate f1()/f2() to be inside the `namespace`\n * because other type signatures may reference them directly (without using the namespace qualifier).\n * The `declare namespace example` is a synthetic construct represented by `AstNamespaceImport`.\n */\nexport class AstNamespaceImport extends AstSyntheticEntity {\n /**\n * Returns true if the AstSymbolTable.analyze() was called for this object.\n * See that function for details.\n */\n public analyzed: boolean = false;\n\n /**\n * For example, if the original statement was `import * as example from \"./file\";`\n * then `astModule` refers to the `./file.d.ts` file.\n */\n public readonly astModule: AstModule;\n\n /**\n * For example, if the original statement was `import * as example from \"./file\";`\n * then `namespaceName` would be `example`.\n */\n public readonly namespaceName: string;\n\n /**\n * The original `ts.SyntaxKind.NamespaceImport` which can be used as a location for error messages.\n */\n public readonly declaration: ts.Declaration;\n\n /**\n * The original `ts.SymbolFlags.Namespace` symbol.\n */\n public readonly symbol: ts.Symbol;\n\n public constructor(options: IAstNamespaceImportOptions) {\n super();\n this.astModule = options.astModule;\n this.namespaceName = options.namespaceName;\n this.declaration = options.declaration;\n this.symbol = options.symbol;\n }\n\n /** {@inheritdoc} */\n public get localName(): string {\n // abstract\n return this.namespaceName;\n }\n\n public fetchAstModuleExportInfo(collector: Collector): IAstModuleExportInfo {\n const astModuleExportInfo: IAstModuleExportInfo = collector.astSymbolTable.fetchAstModuleExportInfo(\n this.astModule\n );\n return astModuleExportInfo;\n }\n}\n"]}
\ No newline at end of file
import * as tsdoc from '@microsoft/tsdoc';
import type { AstDeclaration } from './AstDeclaration';
import type { Collector } from '../collector/Collector';
/**
* Used by `AstReferenceResolver` to report a failed resolution.
*
* @privateRemarks
* This class is similar to an `Error` object, but the intent of `ResolverFailure` is to describe
* why a reference could not be resolved. This information could be used to throw an actual `Error` object,
* but normally it is handed off to the `MessageRouter` instead.
*/
export declare class ResolverFailure {
/**
* Details about why the failure occurred.
*/
readonly reason: string;
constructor(reason: string);
}
/**
* This resolves a TSDoc declaration reference by walking the `AstSymbolTable` compiler state.
*
* @remarks
*
* This class is analogous to `ModelReferenceResolver` from the `@microsoft/api-extractor-model` project,
* which resolves declaration references by walking the hierarchy loaded from an .api.json file.
*/
export declare class AstReferenceResolver {
private readonly _collector;
private readonly _astSymbolTable;
private readonly _workingPackage;
constructor(collector: Collector);
resolve(declarationReference: tsdoc.DocDeclarationReference): AstDeclaration | ResolverFailure;
private _getMemberReferenceIdentifier;
private _selectDeclaration;
private _selectUsingSystemSelector;
private _selectUsingIndexSelector;
/**
* This resolves an ambiguous match in the case where the extra matches are all ancillary declarations,
* except for one match that is the main declaration.
*/
private _tryDisambiguateAncillaryMatches;
}
//# sourceMappingURL=AstReferenceResolver.d.ts.map
\ No newline at end of file
{"version":3,"file":"AstReferenceResolver.d.ts","sourceRoot":"","sources":["../../src/analyzer/AstReferenceResolver.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAI1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAIxD;;;;;;;GAOG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IACH,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM;CAGlC;AAED;;;;;;;GAOG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAiB;gBAE9B,SAAS,EAAE,SAAS;IAMhC,OAAO,CAAC,oBAAoB,EAAE,KAAK,CAAC,uBAAuB,GAAG,cAAc,GAAG,eAAe;IAoFrG,OAAO,CAAC,6BAA6B;IAUrC,OAAO,CAAC,kBAAkB;IAoC1B,OAAO,CAAC,0BAA0B;IA2DlC,OAAO,CAAC,yBAAyB;IAqCjC;;;OAGG;IACH,OAAO,CAAC,gCAAgC;CAgBzC"}
\ No newline at end of file
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AstReferenceResolver = exports.ResolverFailure = void 0;
const ts = __importStar(require("typescript"));
const tsdoc = __importStar(require("@microsoft/tsdoc"));
const AstSymbol_1 = require("./AstSymbol");
/**
* Used by `AstReferenceResolver` to report a failed resolution.
*
* @privateRemarks
* This class is similar to an `Error` object, but the intent of `ResolverFailure` is to describe
* why a reference could not be resolved. This information could be used to throw an actual `Error` object,
* but normally it is handed off to the `MessageRouter` instead.
*/
class ResolverFailure {
constructor(reason) {
this.reason = reason;
}
}
exports.ResolverFailure = ResolverFailure;
/**
* This resolves a TSDoc declaration reference by walking the `AstSymbolTable` compiler state.
*
* @remarks
*
* This class is analogous to `ModelReferenceResolver` from the `@microsoft/api-extractor-model` project,
* which resolves declaration references by walking the hierarchy loaded from an .api.json file.
*/
class AstReferenceResolver {
constructor(collector) {
this._collector = collector;
this._astSymbolTable = collector.astSymbolTable;
this._workingPackage = collector.workingPackage;
}
resolve(declarationReference) {
// Is it referring to the working package?
if (declarationReference.packageName !== undefined &&
declarationReference.packageName !== this._workingPackage.name) {
return new ResolverFailure('External package references are not supported');
}
// Is it a path-based import?
if (declarationReference.importPath) {
return new ResolverFailure('Import paths are not supported');
}
const astModule = this._astSymbolTable.fetchAstModuleFromWorkingPackage(this._workingPackage.entryPointSourceFile);
if (declarationReference.memberReferences.length === 0) {
return new ResolverFailure('Package references are not supported');
}
const rootMemberReference = declarationReference.memberReferences[0];
const exportName = this._getMemberReferenceIdentifier(rootMemberReference);
if (exportName instanceof ResolverFailure) {
return exportName;
}
const rootAstEntity = this._astSymbolTable.tryGetExportOfAstModule(exportName, astModule);
if (rootAstEntity === undefined) {
return new ResolverFailure(`The package "${this._workingPackage.name}" does not have an export "${exportName}"`);
}
if (!(rootAstEntity instanceof AstSymbol_1.AstSymbol)) {
return new ResolverFailure('This type of declaration is not supported yet by the resolver');
}
let currentDeclaration = this._selectDeclaration(rootAstEntity.astDeclarations, rootMemberReference, rootAstEntity.localName);
if (currentDeclaration instanceof ResolverFailure) {
return currentDeclaration;
}
for (let index = 1; index < declarationReference.memberReferences.length; ++index) {
const memberReference = declarationReference.memberReferences[index];
const memberName = this._getMemberReferenceIdentifier(memberReference);
if (memberName instanceof ResolverFailure) {
return memberName;
}
const matchingChildren = currentDeclaration.findChildrenWithName(memberName);
if (matchingChildren.length === 0) {
return new ResolverFailure(`No member was found with name "${memberName}"`);
}
const selectedDeclaration = this._selectDeclaration(matchingChildren, memberReference, memberName);
if (selectedDeclaration instanceof ResolverFailure) {
return selectedDeclaration;
}
currentDeclaration = selectedDeclaration;
}
return currentDeclaration;
}
_getMemberReferenceIdentifier(memberReference) {
if (memberReference.memberSymbol !== undefined) {
return new ResolverFailure('ECMAScript symbol selectors are not supported');
}
if (memberReference.memberIdentifier === undefined) {
return new ResolverFailure('The member identifier is missing in the root member reference');
}
return memberReference.memberIdentifier.identifier;
}
_selectDeclaration(astDeclarations, memberReference, astSymbolName) {
const memberSelector = memberReference.selector;
if (memberSelector === undefined) {
if (astDeclarations.length === 1) {
return astDeclarations[0];
}
else {
// If we found multiple matches, but the extra ones are all ancillary declarations,
// then return the main declaration.
const nonAncillaryMatch = this._tryDisambiguateAncillaryMatches(astDeclarations);
if (nonAncillaryMatch) {
return nonAncillaryMatch;
}
return new ResolverFailure(`The reference is ambiguous because "${astSymbolName}"` +
` has more than one declaration; you need to add a TSDoc member reference selector`);
}
}
switch (memberSelector.selectorKind) {
case tsdoc.SelectorKind.System:
return this._selectUsingSystemSelector(astDeclarations, memberSelector, astSymbolName);
case tsdoc.SelectorKind.Index:
return this._selectUsingIndexSelector(astDeclarations, memberSelector, astSymbolName);
}
return new ResolverFailure(`The selector "${memberSelector.selector}" is not a supported selector type`);
}
_selectUsingSystemSelector(astDeclarations, memberSelector, astSymbolName) {
const selectorName = memberSelector.selector;
let selectorSyntaxKind;
switch (selectorName) {
case 'class':
selectorSyntaxKind = ts.SyntaxKind.ClassDeclaration;
break;
case 'enum':
selectorSyntaxKind = ts.SyntaxKind.EnumDeclaration;
break;
case 'function':
selectorSyntaxKind = ts.SyntaxKind.FunctionDeclaration;
break;
case 'interface':
selectorSyntaxKind = ts.SyntaxKind.InterfaceDeclaration;
break;
case 'namespace':
selectorSyntaxKind = ts.SyntaxKind.ModuleDeclaration;
break;
case 'type':
selectorSyntaxKind = ts.SyntaxKind.TypeAliasDeclaration;
break;
case 'variable':
selectorSyntaxKind = ts.SyntaxKind.VariableDeclaration;
break;
default:
return new ResolverFailure(`Unsupported system selector "${selectorName}"`);
}
const matches = astDeclarations.filter((x) => x.declaration.kind === selectorSyntaxKind);
if (matches.length === 0) {
return new ResolverFailure(`A declaration for "${astSymbolName}" was not found that matches the` +
` TSDoc selector "${selectorName}"`);
}
if (matches.length > 1) {
// If we found multiple matches, but the extra ones are all ancillary declarations,
// then return the main declaration.
const nonAncillaryMatch = this._tryDisambiguateAncillaryMatches(matches);
if (nonAncillaryMatch) {
return nonAncillaryMatch;
}
return new ResolverFailure(`More than one declaration "${astSymbolName}" matches the TSDoc selector "${selectorName}"`);
}
return matches[0];
}
_selectUsingIndexSelector(astDeclarations, memberSelector, astSymbolName) {
const selectorOverloadIndex = parseInt(memberSelector.selector, 10);
const matches = [];
for (const astDeclaration of astDeclarations) {
const overloadIndex = this._collector.getOverloadIndex(astDeclaration);
if (overloadIndex === selectorOverloadIndex) {
matches.push(astDeclaration);
}
}
if (matches.length === 0) {
return new ResolverFailure(`An overload for "${astSymbolName}" was not found that matches the` +
` TSDoc selector ":${selectorOverloadIndex}"`);
}
if (matches.length > 1) {
// If we found multiple matches, but the extra ones are all ancillary declarations,
// then return the main declaration.
const nonAncillaryMatch = this._tryDisambiguateAncillaryMatches(matches);
if (nonAncillaryMatch) {
return nonAncillaryMatch;
}
return new ResolverFailure(`More than one declaration for "${astSymbolName}" matches the` +
` TSDoc selector ":${selectorOverloadIndex}"`);
}
return matches[0];
}
/**
* This resolves an ambiguous match in the case where the extra matches are all ancillary declarations,
* except for one match that is the main declaration.
*/
_tryDisambiguateAncillaryMatches(matches) {
let result = undefined;
for (const match of matches) {
const declarationMetadata = this._collector.fetchDeclarationMetadata(match);
if (!declarationMetadata.isAncillary) {
if (result) {
return undefined; // more than one match
}
result = match;
}
}
return result;
}
}
exports.AstReferenceResolver = AstReferenceResolver;
//# sourceMappingURL=AstReferenceResolver.js.map
\ No newline at end of file
{"version":3,"file":"AstReferenceResolver.js","sourceRoot":"","sources":["../../src/analyzer/AstReferenceResolver.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+CAAiC;AAEjC,wDAA0C;AAS1C,2CAAwC;AAExC;;;;;;;GAOG;AACH,MAAa,eAAe;IAM1B,YAAmB,MAAc;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AATD,0CASC;AAED;;;;;;;GAOG;AACH,MAAa,oBAAoB;IAK/B,YAAmB,SAAoB;QACrC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC,cAAc,CAAC;IAClD,CAAC;IAEM,OAAO,CAAC,oBAAmD;QAChE,0CAA0C;QAC1C,IACE,oBAAoB,CAAC,WAAW,KAAK,SA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AC;gBACrC,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO,SAAS,CAAC,CAAC,sBAAsB;gBAC1C,CAAC;gBACD,MAAM,GAAG,KAAK,CAAC;YACjB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAjQD,oDAiQC","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';\n\nimport * as tsdoc from '@microsoft/tsdoc';\n\nimport type { AstSymbolTable } from './AstSymbolTable';\nimport type { AstEntity } from './AstEntity';\nimport type { AstDeclaration } from './AstDeclaration';\nimport type { WorkingPackage } from '../collector/WorkingPackage';\nimport type { AstModule } from './AstModule';\nimport type { Collector } from '../collector/Collector';\nimport type { DeclarationMetadata } from '../collector/DeclarationMetadata';\nimport { AstSymbol } from './AstSymbol';\n\n/**\n * Used by `AstReferenceResolver` to report a failed resolution.\n *\n * @privateRemarks\n * This class is similar to an `Error` object, but the intent of `ResolverFailure` is to describe\n * why a reference could not be resolved. This information could be used to throw an actual `Error` object,\n * but normally it is handed off to the `MessageRouter` instead.\n */\nexport class ResolverFailure {\n /**\n * Details about why the failure occurred.\n */\n public readonly reason: string;\n\n public constructor(reason: string) {\n this.reason = reason;\n }\n}\n\n/**\n * This resolves a TSDoc declaration reference by walking the `AstSymbolTable` compiler state.\n *\n * @remarks\n *\n * This class is analogous to `ModelReferenceResolver` from the `@microsoft/api-extractor-model` project,\n * which resolves declaration references by walking the hierarchy loaded from an .api.json file.\n */\nexport class AstReferenceResolver {\n private readonly _collector: Collector;\n private readonly _astSymbolTable: AstSymbolTable;\n private readonly _workingPackage: WorkingPackage;\n\n public constructor(collector: Collector) {\n this._collector = collector;\n this._astSymbolTable = collector.astSymbolTable;\n this._workingPackage = collector.workingPackage;\n }\n\n public resolve(declarationReference: tsdoc.DocDeclarationReference): AstDeclaration | ResolverFailure {\n // Is it referring to the working package?\n if (\n declarationReference.packageName !== undefined &&\n declarationReference.packageName !== this._workingPackage.name\n ) {\n return new ResolverFailure('External package references are not supported');\n }\n\n // Is it a path-based import?\n if (declarationReference.importPath) {\n return new ResolverFailure('Import paths are not supported');\n }\n\n const astModule: AstModule = this._astSymbolTable.fetchAstModuleFromWorkingPackage(\n this._workingPackage.entryPointSourceFile\n );\n\n if (declarationReference.memberReferences.length === 0) {\n return new ResolverFailure('Package references are not supported');\n }\n\n const rootMemberReference: tsdoc.DocMemberReference = declarationReference.memberReferences[0];\n\n const exportName: string | ResolverFailure = this._getMemberReferenceIdentifier(rootMemberReference);\n if (exportName instanceof ResolverFailure) {\n return exportName;\n }\n\n const rootAstEntity: AstEntity | undefined = this._astSymbolTable.tryGetExportOfAstModule(\n exportName,\n astModule\n );\n\n if (rootAstEntity === undefined) {\n return new ResolverFailure(\n `The package \"${this._workingPackage.name}\" does not have an export \"${exportName}\"`\n );\n }\n\n if (!(rootAstEntity instanceof AstSymbol)) {\n return new ResolverFailure('This type of declaration is not supported yet by the resolver');\n }\n\n let currentDeclaration: AstDeclaration | ResolverFailure = this._selectDeclaration(\n rootAstEntity.astDeclarations,\n rootMemberReference,\n rootAstEntity.localName\n );\n\n if (currentDeclaration instanceof ResolverFailure) {\n return currentDeclaration;\n }\n\n for (let index: number = 1; index < declarationReference.memberReferences.length; ++index) {\n const memberReference: tsdoc.DocMemberReference = declarationReference.memberReferences[index];\n\n const memberName: string | ResolverFailure = this._getMemberReferenceIdentifier(memberReference);\n if (memberName instanceof ResolverFailure) {\n return memberName;\n }\n\n const matchingChildren: ReadonlyArray<AstDeclaration> =\n currentDeclaration.findChildrenWithName(memberName);\n if (matchingChildren.length === 0) {\n return new ResolverFailure(`No member was found with name \"${memberName}\"`);\n }\n\n const selectedDeclaration: AstDeclaration | ResolverFailure = this._selectDeclaration(\n matchingChildren,\n memberReference,\n memberName\n );\n\n if (selectedDeclaration instanceof ResolverFailure) {\n return selectedDeclaration;\n }\n\n currentDeclaration = selectedDeclaration;\n }\n\n return currentDeclaration;\n }\n\n private _getMemberReferenceIdentifier(memberReference: tsdoc.DocMemberReference): string | ResolverFailure {\n if (memberReference.memberSymbol !== undefined) {\n return new ResolverFailure('ECMAScript symbol selectors are not supported');\n }\n if (memberReference.memberIdentifier === undefined) {\n return new ResolverFailure('The member identifier is missing in the root member reference');\n }\n return memberReference.memberIdentifier.identifier;\n }\n\n private _selectDeclaration(\n astDeclarations: ReadonlyArray<AstDeclaration>,\n memberReference: tsdoc.DocMemberReference,\n astSymbolName: string\n ): AstDeclaration | ResolverFailure {\n const memberSelector: tsdoc.DocMemberSelector | undefined = memberReference.selector;\n\n if (memberSelector === undefined) {\n if (astDeclarations.length === 1) {\n return astDeclarations[0];\n } else {\n // If we found multiple matches, but the extra ones are all ancillary declarations,\n // then return the main declaration.\n const nonAncillaryMatch: AstDeclaration | undefined =\n this._tryDisambiguateAncillaryMatches(astDeclarations);\n if (nonAncillaryMatch) {\n return nonAncillaryMatch;\n }\n\n return new ResolverFailure(\n `The reference is ambiguous because \"${astSymbolName}\"` +\n ` has more than one declaration; you need to add a TSDoc member reference selector`\n );\n }\n }\n\n switch (memberSelector.selectorKind) {\n case tsdoc.SelectorKind.System:\n return this._selectUsingSystemSelector(astDeclarations, memberSelector, astSymbolName);\n case tsdoc.SelectorKind.Index:\n return this._selectUsingIndexSelector(astDeclarations, memberSelector, astSymbolName);\n }\n\n return new ResolverFailure(`The selector \"${memberSelector.selector}\" is not a supported selector type`);\n }\n\n private _selectUsingSystemSelector(\n astDeclarations: ReadonlyArray<AstDeclaration>,\n memberSelector: tsdoc.DocMemberSelector,\n astSymbolName: string\n ): AstDeclaration | ResolverFailure {\n const selectorName: string = memberSelector.selector;\n\n let selectorSyntaxKind: ts.SyntaxKind;\n\n switch (selectorName) {\n case 'class':\n selectorSyntaxKind = ts.SyntaxKind.ClassDeclaration;\n break;\n case 'enum':\n selectorSyntaxKind = ts.SyntaxKind.EnumDeclaration;\n break;\n case 'function':\n selectorSyntaxKind = ts.SyntaxKind.FunctionDeclaration;\n break;\n case 'interface':\n selectorSyntaxKind = ts.SyntaxKind.InterfaceDeclaration;\n break;\n case 'namespace':\n selectorSyntaxKind = ts.SyntaxKind.ModuleDeclaration;\n break;\n case 'type':\n selectorSyntaxKind = ts.SyntaxKind.TypeAliasDeclaration;\n break;\n case 'variable':\n selectorSyntaxKind = ts.SyntaxKind.VariableDeclaration;\n break;\n default:\n return new ResolverFailure(`Unsupported system selector \"${selectorName}\"`);\n }\n\n const matches: AstDeclaration[] = astDeclarations.filter(\n (x) => x.declaration.kind === selectorSyntaxKind\n );\n if (matches.length === 0) {\n return new ResolverFailure(\n `A declaration for \"${astSymbolName}\" was not found that matches the` +\n ` TSDoc selector \"${selectorName}\"`\n );\n }\n if (matches.length > 1) {\n // If we found multiple matches, but the extra ones are all ancillary declarations,\n // then return the main declaration.\n const nonAncillaryMatch: AstDeclaration | undefined = this._tryDisambiguateAncillaryMatches(matches);\n if (nonAncillaryMatch) {\n return nonAncillaryMatch;\n }\n\n return new ResolverFailure(\n `More than one declaration \"${astSymbolName}\" matches the TSDoc selector \"${selectorName}\"`\n );\n }\n return matches[0];\n }\n\n private _selectUsingIndexSelector(\n astDeclarations: ReadonlyArray<AstDeclaration>,\n memberSelector: tsdoc.DocMemberSelector,\n astSymbolName: string\n ): AstDeclaration | ResolverFailure {\n const selectorOverloadIndex: number = parseInt(memberSelector.selector, 10);\n\n const matches: AstDeclaration[] = [];\n for (const astDeclaration of astDeclarations) {\n const overloadIndex: number = this._collector.getOverloadIndex(astDeclaration);\n if (overloadIndex === selectorOverloadIndex) {\n matches.push(astDeclaration);\n }\n }\n\n if (matches.length === 0) {\n return new ResolverFailure(\n `An overload for \"${astSymbolName}\" was not found that matches the` +\n ` TSDoc selector \":${selectorOverloadIndex}\"`\n );\n }\n if (matches.length > 1) {\n // If we found multiple matches, but the extra ones are all ancillary declarations,\n // then return the main declaration.\n const nonAncillaryMatch: AstDeclaration | undefined = this._tryDisambiguateAncillaryMatches(matches);\n if (nonAncillaryMatch) {\n return nonAncillaryMatch;\n }\n\n return new ResolverFailure(\n `More than one declaration for \"${astSymbolName}\" matches the` +\n ` TSDoc selector \":${selectorOverloadIndex}\"`\n );\n }\n return matches[0];\n }\n\n /**\n * This resolves an ambiguous match in the case where the extra matches are all ancillary declarations,\n * except for one match that is the main declaration.\n */\n private _tryDisambiguateAncillaryMatches(\n matches: ReadonlyArray<AstDeclaration>\n ): AstDeclaration | undefined {\n let result: AstDeclaration | undefined = undefined;\n\n for (const match of matches) {\n const declarationMetadata: DeclarationMetadata = this._collector.fetchDeclarationMetadata(match);\n if (!declarationMetadata.isAncillary) {\n if (result) {\n return undefined; // more than one match\n }\n result = match;\n }\n }\n return result;\n }\n}\n"]}
\ No newline at end of file
import type * as ts from 'typescript';
import type { AstDeclaration } from './AstDeclaration';
import { AstEntity } from './AstEntity';
/**
* Constructor options for AstSymbol
*/
export interface IAstSymbolOptions {
readonly followedSymbol: ts.Symbol;
readonly localName: string;
readonly isExternal: boolean;
readonly nominalAnalysis: boolean;
readonly parentAstSymbol: AstSymbol | undefined;
readonly rootAstSymbol: AstSymbol | undefined;
}
/**
* The AstDeclaration and AstSymbol classes are API Extractor's equivalent of the compiler's
* ts.Declaration and ts.Symbol objects. They are created by the `AstSymbolTable` class.
*
* @remarks
* The AstSymbol represents the ts.Symbol information for an AstDeclaration. For example,
* if a method has 3 overloads, each overloaded signature will have its own AstDeclaration,
* but they will all share a common AstSymbol.
*
* For nested definitions, the AstSymbol has a unique parent (i.e. AstSymbol.rootAstSymbol),
* but the parent/children for each AstDeclaration may be different. Consider this example:
*
* ```ts
* export namespace N {
* export function f(): void { }
* }
*
* export interface N {
* g(): void;
* }
* ```
*
* Note how the parent/child relationships are different for the symbol tree versus
* the declaration tree, and the declaration tree has two roots:
*
* ```
* AstSymbol tree: AstDeclaration tree:
* - N - N (namespace)
* - f - f
* - g - N (interface)
* - g
* ```
*/
export declare class AstSymbol extends AstEntity {
/** {@inheritdoc} */
readonly localName: string;
/**
* If true, then the `followedSymbol` (i.e. original declaration) of this symbol
* is not part of the working package. The working package may still export this symbol,
* but if so it should be emitted as an alias such as `export { X } from "package1";`.
*/
readonly isExternal: boolean;
/**
* The compiler symbol where this type was defined, after following any aliases.
*
* @remarks
* This is a normal form that can be reached from any symbol alias by calling
* `TypeScriptHelpers.followAliases()`. It can be compared to determine whether two
* symbols refer to the same underlying type.
*/
readonly followedSymbol: ts.Symbol;
/**
* If true, then this AstSymbol represents a foreign object whose structure will be
* ignored. The AstDeclaration objects will not have any parent or children, and its references
* will not be analyzed.
*
* Nominal symbols are tracked e.g. when they are reexported by the working package.
*/
readonly nominalAnalysis: boolean;
/**
* Returns the symbol of the parent of this AstSymbol, or undefined if there is no parent.
* @remarks
* If a symbol has multiple declarations, we assume (as an axiom) that their parent
* declarations will belong to the same symbol. This means that the "parent" of a
* symbol is a well-defined concept. However, the "children" of a symbol are not very
* meaningful, because different declarations may have different nested members,
* so we usually need to traverse declarations to find children.
*/
readonly parentAstSymbol: AstSymbol | undefined;
/**
* Returns the symbol of the root of the AstDeclaration hierarchy.
* @remarks
* NOTE: If this AstSymbol is the root, then rootAstSymbol will point to itself.
*/
readonly rootAstSymbol: AstSymbol;
/**
* Additional information that is calculated later by the `Collector`. The actual type is `SymbolMetadata`,
* but we declare it as `unknown` because consumers must obtain this object by calling
* `Collector.fetchSymbolMetadata()`.
*/
symbolMetadata: unknown;
private readonly _astDeclarations;
private _analyzed;
constructor(options: IAstSymbolOptions);
/**
* The one or more declarations for this symbol.
* @remarks
* For example, if this symbol is a method, then the declarations might be
* various method overloads. If this symbol is a namespace, then the declarations
* might be separate namespace blocks with the same name that get combined via
* declaration merging.
*/
get astDeclarations(): ReadonlyArray<AstDeclaration>;
/**
* Returns true if the AstSymbolTable.analyze() was called for this object.
* See that function for details.
* @remarks
* AstSymbolTable.analyze() is always performed on the root AstSymbol. This function
* returns true if-and-only-if the root symbol was analyzed.
*/
get analyzed(): boolean;
/**
* This is an internal callback used when the AstSymbolTable attaches a new
* AstDeclaration to this object.
* @internal
*/
_notifyDeclarationAttach(astDeclaration: AstDeclaration): void;
/**
* This is an internal callback used when the AstSymbolTable.analyze()
* has processed this object.
* @internal
*/
_notifyAnalyzed(): void;
/**
* Helper that calls AstDeclaration.forEachDeclarationRecursive() for each AstDeclaration.
*/
forEachDeclarationRecursive(action: (astDeclaration: AstDeclaration) => void): void;
}
//# sourceMappingURL=AstSymbol.d.ts.map
\ No newline at end of file
{"version":3,"file":"AstSymbol.d.ts","sourceRoot":"","sources":["../../src/analyzer/AstSymbol.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAItC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,eAAe,EAAE,SAAS,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,aAAa,EAAE,SAAS,GAAG,SAAS,CAAC;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,SAAU,SAAQ,SAAS;IACtC,oBAAoB;IACpB,SAAgB,SAAS,EAAE,MAAM,CAAC;IAElC;;;;OAIG;IACH,SAAgB,UAAU,EAAE,OAAO,CAAC;IAEpC;;;;;;;OAOG;IACH,SAAgB,cAAc,EAAE,EAAE,CAAC,MAAM,CAAC;IAE1C;;;;;;OAMG;IACH,SAAgB,eAAe,EAAE,OAAO,CAAC;IAEzC;;;;;;;;OAQG;IACH,SAAgB,eAAe,EAAE,SAAS,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,SAAgB,aAAa,EAAE,SAAS,CAAC;IAEzC;;;;OAIG;IACI,cAAc,EAAE,OAAO,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAmB;IAIpD,OAAO,CAAC,SAAS,CAAkB;gBAEhB,OAAO,EAAE,iBAAiB;IAY7C;;;;;;;OAOG;IACH,IAAW,eAAe,IAAI,aAAa,CAAC,cAAc,CAAC,CAE1D;IAED;;;;;;OAMG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED;;;;OAIG;IACI,wBAAwB,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI;IAOrE;;;;OAIG;IACI,eAAe,IAAI,IAAI;IAO9B;;OAEG;IACI,2BAA2B,CAAC,MAAM,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;CAK3F"}
\ No newline at end of file
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AstSymbol = void 0;
const node_core_library_1 = require("@rushstack/node-core-library");
const AstEntity_1 = require("./AstEntity");
/**
* The AstDeclaration and AstSymbol classes are API Extractor's equivalent of the compiler's
* ts.Declaration and ts.Symbol objects. They are created by the `AstSymbolTable` class.
*
* @remarks
* The AstSymbol represents the ts.Symbol information for an AstDeclaration. For example,
* if a method has 3 overloads, each overloaded signature will have its own AstDeclaration,
* but they will all share a common AstSymbol.
*
* For nested definitions, the AstSymbol has a unique parent (i.e. AstSymbol.rootAstSymbol),
* but the parent/children for each AstDeclaration may be different. Consider this example:
*
* ```ts
* export namespace N {
* export function f(): void { }
* }
*
* export interface N {
* g(): void;
* }
* ```
*
* Note how the parent/child relationships are different for the symbol tree versus
* the declaration tree, and the declaration tree has two roots:
*
* ```
* AstSymbol tree: AstDeclaration tree:
* - N - N (namespace)
* - f - f
* - g - N (interface)
* - g
* ```
*/
class AstSymbol extends AstEntity_1.AstEntity {
constructor(options) {
super();
// This flag is unused if this is not the root symbol.
// Being "analyzed" is a property of the root symbol.
this._analyzed = false;
this.followedSymbol = options.followedSymbol;
this.localName = options.localName;
this.isExternal = options.isExternal;
this.nominalAnalysis = options.nominalAnalysis;
this.parentAstSymbol = options.parentAstSymbol;
this.rootAstSymbol = options.rootAstSymbol || this;
this._astDeclarations = [];
}
/**
* The one or more declarations for this symbol.
* @remarks
* For example, if this symbol is a method, then the declarations might be
* various method overloads. If this symbol is a namespace, then the declarations
* might be separate namespace blocks with the same name that get combined via
* declaration merging.
*/
get astDeclarations() {
return this._astDeclarations;
}
/**
* Returns true if the AstSymbolTable.analyze() was called for this object.
* See that function for details.
* @remarks
* AstSymbolTable.analyze() is always performed on the root AstSymbol. This function
* returns true if-and-only-if the root symbol was analyzed.
*/
get analyzed() {
return this.rootAstSymbol._analyzed;
}
/**
* This is an internal callback used when the AstSymbolTable attaches a new
* AstDeclaration to this object.
* @internal
*/
_notifyDeclarationAttach(astDeclaration) {
if (this.analyzed) {
throw new node_core_library_1.InternalError('_notifyDeclarationAttach() called after analysis is already complete');
}
this._astDeclarations.push(astDeclaration);
}
/**
* This is an internal callback used when the AstSymbolTable.analyze()
* has processed this object.
* @internal
*/
_notifyAnalyzed() {
if (this.parentAstSymbol) {
throw new node_core_library_1.InternalError('_notifyAnalyzed() called for an AstSymbol which is not the root');
}
this._analyzed = true;
}
/**
* Helper that calls AstDeclaration.forEachDeclarationRecursive() for each AstDeclaration.
*/
forEachDeclarationRecursive(action) {
for (const astDeclaration of this.astDeclarations) {
astDeclaration.forEachDeclarationRecursive(action);
}
}
}
exports.AstSymbol = AstSymbol;
//# sourceMappingURL=AstSymbol.js.map
\ No newline at end of file
{"version":3,"file":"AstSymbol.js","sourceRoot":"","sources":["../../src/analyzer/AstSymbol.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D,oEAA6D;AAG7D,2CAAwC;AAcxC;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Ac,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAClD,cAAc,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CACF;AAhID,8BAgIC","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 type * as ts from 'typescript';\n\nimport { InternalError } from '@rushstack/node-core-library';\n\nimport type { AstDeclaration } from './AstDeclaration';\nimport { AstEntity } from './AstEntity';\n\n/**\n * Constructor options for AstSymbol\n */\nexport interface IAstSymbolOptions {\n readonly followedSymbol: ts.Symbol;\n readonly localName: string;\n readonly isExternal: boolean;\n readonly nominalAnalysis: boolean;\n readonly parentAstSymbol: AstSymbol | undefined;\n readonly rootAstSymbol: AstSymbol | undefined;\n}\n\n/**\n * The AstDeclaration and AstSymbol classes are API Extractor's equivalent of the compiler's\n * ts.Declaration and ts.Symbol objects. They are created by the `AstSymbolTable` class.\n *\n * @remarks\n * The AstSymbol represents the ts.Symbol information for an AstDeclaration. For example,\n * if a method has 3 overloads, each overloaded signature will have its own AstDeclaration,\n * but they will all share a common AstSymbol.\n *\n * For nested definitions, the AstSymbol has a unique parent (i.e. AstSymbol.rootAstSymbol),\n * but the parent/children for each AstDeclaration may be different. Consider this example:\n *\n * ```ts\n * export namespace N {\n * export function f(): void { }\n * }\n *\n * export interface N {\n * g(): void;\n * }\n * ```\n *\n * Note how the parent/child relationships are different for the symbol tree versus\n * the declaration tree, and the declaration tree has two roots:\n *\n * ```\n * AstSymbol tree: AstDeclaration tree:\n * - N - N (namespace)\n * - f - f\n * - g - N (interface)\n * - g\n * ```\n */\nexport class AstSymbol extends AstEntity {\n /** {@inheritdoc} */\n public readonly localName: string; // abstract\n\n /**\n * If true, then the `followedSymbol` (i.e. original declaration) of this symbol\n * is not part of the working package. The working package may still export this symbol,\n * but if so it should be emitted as an alias such as `export { X } from \"package1\";`.\n */\n public readonly isExternal: boolean;\n\n /**\n * The compiler symbol where this type was defined, after following any aliases.\n *\n * @remarks\n * This is a normal form that can be reached from any symbol alias by calling\n * `TypeScriptHelpers.followAliases()`. It can be compared to determine whether two\n * symbols refer to the same underlying type.\n */\n public readonly followedSymbol: ts.Symbol;\n\n /**\n * If true, then this AstSymbol represents a foreign object whose structure will be\n * ignored. The AstDeclaration objects will not have any parent or children, and its references\n * will not be analyzed.\n *\n * Nominal symbols are tracked e.g. when they are reexported by the working package.\n */\n public readonly nominalAnalysis: boolean;\n\n /**\n * Returns the symbol of the parent of this AstSymbol, or undefined if there is no parent.\n * @remarks\n * If a symbol has multiple declarations, we assume (as an axiom) that their parent\n * declarations will belong to the same symbol. This means that the \"parent\" of a\n * symbol is a well-defined concept. However, the \"children\" of a symbol are not very\n * meaningful, because different declarations may have different nested members,\n * so we usually need to traverse declarations to find children.\n */\n public readonly parentAstSymbol: AstSymbol | undefined;\n\n /**\n * Returns the symbol of the root of the AstDeclaration hierarchy.\n * @remarks\n * NOTE: If this AstSymbol is the root, then rootAstSymbol will point to itself.\n */\n public readonly rootAstSymbol: AstSymbol;\n\n /**\n * Additional information that is calculated later by the `Collector`. The actual type is `SymbolMetadata`,\n * but we declare it as `unknown` because consumers must obtain this object by calling\n * `Collector.fetchSymbolMetadata()`.\n */\n public symbolMetadata: unknown;\n\n private readonly _astDeclarations: AstDeclaration[];\n\n // This flag is unused if this is not the root symbol.\n // Being \"analyzed\" is a property of the root symbol.\n private _analyzed: boolean = false;\n\n public constructor(options: IAstSymbolOptions) {\n super();\n\n this.followedSymbol = options.followedSymbol;\n this.localName = options.localName;\n this.isExternal = options.isExternal;\n this.nominalAnalysis = options.nominalAnalysis;\n this.parentAstSymbol = options.parentAstSymbol;\n this.rootAstSymbol = options.rootAstSymbol || this;\n this._astDeclarations = [];\n }\n\n /**\n * The one or more declarations for this symbol.\n * @remarks\n * For example, if this symbol is a method, then the declarations might be\n * various method overloads. If this symbol is a namespace, then the declarations\n * might be separate namespace blocks with the same name that get combined via\n * declaration merging.\n */\n public get astDeclarations(): ReadonlyArray<AstDeclaration> {\n return this._astDeclarations;\n }\n\n /**\n * Returns true if the AstSymbolTable.analyze() was called for this object.\n * See that function for details.\n * @remarks\n * AstSymbolTable.analyze() is always performed on the root AstSymbol. This function\n * returns true if-and-only-if the root symbol was analyzed.\n */\n public get analyzed(): boolean {\n return this.rootAstSymbol._analyzed;\n }\n\n /**\n * This is an internal callback used when the AstSymbolTable attaches a new\n * AstDeclaration to this object.\n * @internal\n */\n public _notifyDeclarationAttach(astDeclaration: AstDeclaration): void {\n if (this.analyzed) {\n throw new InternalError('_notifyDeclarationAttach() called after analysis is already complete');\n }\n this._astDeclarations.push(astDeclaration);\n }\n\n /**\n * This is an internal callback used when the AstSymbolTable.analyze()\n * has processed this object.\n * @internal\n */\n public _notifyAnalyzed(): void {\n if (this.parentAstSymbol) {\n throw new InternalError('_notifyAnalyzed() called for an AstSymbol which is not the root');\n }\n this._analyzed = true;\n }\n\n /**\n * Helper that calls AstDeclaration.forEachDeclarationRecursive() for each AstDeclaration.\n */\n public forEachDeclarationRecursive(action: (astDeclaration: AstDeclaration) => void): void {\n for (const astDeclaration of this.astDeclarations) {\n astDeclaration.forEachDeclarationRecursive(action);\n }\n }\n}\n"]}
\ No newline at end of file
import * as ts from 'typescript';
import { type PackageJsonLookup } from '@rushstack/node-core-library';
import { AstDeclaration } from './AstDeclaration';
import type { AstModule, IAstModuleExportInfo } from './AstModule';
import type { AstEntity } from './AstEntity';
import type { MessageRouter } from '../collector/MessageRouter';
/**
* Options for `AstSymbolTable._fetchAstSymbol()`
*/
export interface IFetchAstSymbolOptions {
/**
* The symbol after any symbol aliases have been followed using TypeScriptHelpers.followAliases()
*/
followedSymbol: ts.Symbol;
/**
* True if followedSymbol is not part of the working package
*/
isExternal: boolean;
/**
* If true, symbols with AstSymbol.nominalAnalysis=true will be returned.
* Otherwise `undefined` will be returned for such symbols.
*/
includeNominalAnalysis: boolean;
/**
* True while populating the `AstSymbolTable`; false if we're doing a passive lookup
* without adding anything new to the table
*/
addIfMissing: boolean;
/**
* A hint to help `_fetchAstSymbol()` determine the `AstSymbol.localName`.
*/
localName?: string;
}
/**
* AstSymbolTable is the workhorse that builds AstSymbol and AstDeclaration objects.
* It maintains a cache of already constructed objects. AstSymbolTable constructs
* AstModule objects, but otherwise the state that it maintains is agnostic of
* any particular entry point. (For example, it does not track whether a given AstSymbol
* is "exported" or not.)
*
* Internally, AstSymbolTable relies on ExportAnalyzer to crawl import statements and determine where symbols
* are declared (i.e. the AstImport information needed to import them).
*/
export declare class AstSymbolTable {
private readonly _program;
private readonly _typeChecker;
private readonly _messageRouter;
private readonly _globalVariableAnalyzer;
private readonly _packageMetadataManager;
private readonly _exportAnalyzer;
private readonly _alreadyWarnedGlobalNames;
/**
* A mapping from ts.Symbol --> AstSymbol
* NOTE: The AstSymbol.followedSymbol will always be a lookup key, but additional keys
* are possible.
*
* After following type aliases, we use this map to look up the corresponding AstSymbol.
*/
private readonly _astSymbolsBySymbol;
/**
* A mapping from ts.Declaration --> AstDeclaration
*/
private readonly _astDeclarationsByDeclaration;
private readonly _entitiesByNode;
constructor(program: ts.Program, typeChecker: ts.TypeChecker, packageJsonLookup: PackageJsonLookup, bundledPackageNames: ReadonlySet<string>, messageRouter: MessageRouter);
/**
* Used to analyze an entry point that belongs to the working package.
*/
fetchAstModuleFromWorkingPackage(sourceFile: ts.SourceFile): AstModule;
/**
* This crawls the specified entry point and collects the full set of exported AstSymbols.
*/
fetchAstModuleExportInfo(astModule: AstModule): IAstModuleExportInfo;
/**
* Attempts to retrieve an export by name from the specified `AstModule`.
* Returns undefined if no match was found.
*/
tryGetExportOfAstModule(exportName: string, astModule: AstModule): AstEntity | undefined;
/**
* Ensures that AstSymbol.analyzed is true for the provided symbol. The operation
* starts from the root symbol and then fills out all children of all declarations, and
* also calculates AstDeclaration.referencedAstSymbols for all declarations.
* If the symbol is not imported, any non-imported references are also analyzed.
*
* @remarks
* This is an expensive operation, so we only perform it for top-level exports of an
* the AstModule. For example, if some code references a nested class inside
* a namespace from another library, we do not analyze any of that class's siblings
* or members. (We do always construct its parents however, since AstDefinition.parent
* is immutable, and needed e.g. to calculate release tag inheritance.)
*/
analyze(astEntity: AstEntity): void;
/**
* For a given astDeclaration, this efficiently finds the child corresponding to the
* specified ts.Node. It is assumed that AstDeclaration.isSupportedSyntaxKind() would return true for
* that node type, and that the node is an immediate child of the provided AstDeclaration.
*/
getChildAstDeclarationByNode(node: ts.Node, parentAstDeclaration: AstDeclaration): AstDeclaration;
/**
* For a given ts.Identifier that is part of an AstSymbol that we analyzed, return the AstEntity that
* it refers to. Returns undefined if it doesn't refer to anything interesting.
* @remarks
* Throws an Error if the ts.Identifier is not part of node tree that was analyzed.
*/
tryGetEntityForNode(identifier: ts.Identifier | ts.ImportTypeNode): AstEntity | undefined;
/**
* Builds an AstSymbol.localName for a given ts.Symbol. In the current implementation, the localName is
* a TypeScript-like expression that may be a string literal or ECMAScript symbol expression.
*
* ```ts
* class X {
* // localName="identifier"
* public identifier: number = 1;
* // localName="\"identifier\""
* public "quoted string!": number = 2;
* // localName="[MyNamespace.MySymbol]"
* public [MyNamespace.MySymbol]: number = 3;
* }
* ```
*/
static getLocalNameForSymbol(symbol: ts.Symbol): string;
private _analyzeAstNamespaceImport;
private _analyzeAstSymbol;
/**
* Used by analyze to recursively analyze the entire child tree.
*/
private _analyzeChildTree;
private _fetchEntityForNode;
private _fetchAstDeclaration;
private _fetchAstSymbol;
/**
* Returns the first parent satisfying isAstDeclaration(), or undefined if none is found.
*/
private _tryFindFirstAstDeclarationParent;
}
//# sourceMappingURL=AstSymbolTable.d.ts.map
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment