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

update build x-app-sdk

parent 9bb8aadd
{"version":3,"file":"AstSymbolTable.d.ts","sourceRoot":"","sources":["../../src/analyzer/AstSymbolTable.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,8BAA8B,CAAC;AAErF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAKhE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,cAAc,EAAE,EAAE,CAAC,MAAM,CAAC;IAC1B;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;;OAGG;IACH,sBAAsB,EAAE,OAAO,CAAC;IAEhC;;;OAGG;IACH,YAAY,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiB;IAC9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAC/C,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAA0B;IAClE,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAyB;IACjE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAc;IAExD;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA8D;IAElG;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAG1C;IAIJ,OAAO,CAAC,QAAQ,CAAC,eAAe,CAG5B;gBAGF,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,WAAW,EAAE,EAAE,CAAC,WAAW,EAC3B,iBAAiB,EAAE,iBAAiB,EACpC,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAAC,EACxC,aAAa,EAAE,aAAa;IAgB9B;;OAEG;IACI,gCAAgC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,SAAS;IAI7E;;OAEG;IACI,wBAAwB,CAAC,SAAS,EAAE,SAAS,GAAG,oBAAoB;IAI3E;;;OAGG;IACI,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS;IAI/F;;;;;;;;;;;;OAYG;IACI,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAU1C;;;;OAIG;IAEI,4BAA4B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,oBAAoB,EAAE,cAAc,GAAG,cAAc;IAgBxG;;;;;OAKG;IACI,mBAAmB,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,cAAc,GAAG,SAAS,GAAG,SAAS;IAOhG;;;;;;;;;;;;;;OAcG;WACW,qBAAqB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,GAAG,MAAM;IAmE9D,OAAO,CAAC,0BAA0B;IAiBlC,OAAO,CAAC,iBAAiB;IA4CzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAsIzB,OAAO,CAAC,mBAAmB;IA4B3B,OAAO,CAAC,oBAAoB;IAiC5B,OAAO,CAAC,eAAe;IA2JvB;;OAEG;IACH,OAAO,CAAC,iCAAiC;CAU1C"}
\ 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.AstSymbolTable = void 0;
/* eslint-disable no-bitwise */ // for ts.SymbolFlags
const ts = __importStar(require("typescript"));
const node_core_library_1 = require("@rushstack/node-core-library");
const AstDeclaration_1 = require("./AstDeclaration");
const TypeScriptHelpers_1 = require("./TypeScriptHelpers");
const AstSymbol_1 = require("./AstSymbol");
const PackageMetadataManager_1 = require("./PackageMetadataManager");
const ExportAnalyzer_1 = require("./ExportAnalyzer");
const AstNamespaceImport_1 = require("./AstNamespaceImport");
const TypeScriptInternals_1 = require("./TypeScriptInternals");
const SyntaxHelpers_1 = require("./SyntaxHelpers");
const SourceFileLocationFormatter_1 = require("./SourceFileLocationFormatter");
/**
* 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).
*/
class AstSymbolTable {
constructor(program, typeChecker, packageJsonLookup, bundledPackageNames, messageRouter) {
/**
* 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.
*/
this._astSymbolsBySymbol = new Map();
/**
* A mapping from ts.Declaration --> AstDeclaration
*/
this._astDeclarationsByDeclaration = new Map();
// Note that this is a mapping from specific AST nodes that we analyzed, based on the underlying symbol
// for that node.
this._entitiesByNode = new Map();
this._program = program;
this._typeChecker = typeChecker;
this._messageRouter = messageRouter;
this._globalVariableAnalyzer = TypeScriptInternals_1.TypeScriptInternals.getGlobalVariableAnalyzer(program);
this._packageMetadataManager = new PackageMetadataManager_1.PackageMetadataManager(packageJsonLookup, messageRouter);
this._exportAnalyzer = new ExportAnalyzer_1.ExportAnalyzer(this._program, this._typeChecker, bundledPackageNames, {
analyze: this.analyze.bind(this),
fetchAstSymbol: this._fetchAstSymbol.bind(this)
});
this._alreadyWarnedGlobalNames = new Set();
}
/**
* Used to analyze an entry point that belongs to the working package.
*/
fetchAstModuleFromWorkingPackage(sourceFile) {
return this._exportAnalyzer.fetchAstModuleFromSourceFile(sourceFile, undefined, false);
}
/**
* This crawls the specified entry point and collects the full set of exported AstSymbols.
*/
fetchAstModuleExportInfo(astModule) {
return this._exportAnalyzer.fetchAstModuleExportInfo(astModule);
}
/**
* Attempts to retrieve an export by name from the specified `AstModule`.
* Returns undefined if no match was found.
*/
tryGetExportOfAstModule(exportName, astModule) {
return this._exportAnalyzer.tryGetExportOfAstModule(exportName, astModule);
}
/**
* 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) {
if (astEntity instanceof AstSymbol_1.AstSymbol) {
return this._analyzeAstSymbol(astEntity);
}
if (astEntity instanceof AstNamespaceImport_1.AstNamespaceImport) {
return this._analyzeAstNamespaceImport(astEntity);
}
}
/**
* 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.
*/
// NOTE: This could be a method of AstSymbol if it had a backpointer to its AstSymbolTable.
getChildAstDeclarationByNode(node, parentAstDeclaration) {
if (!parentAstDeclaration.astSymbol.analyzed) {
throw new Error('getChildDeclarationByNode() cannot be used for an AstSymbol that was not analyzed');
}
const childAstDeclaration = this._astDeclarationsByDeclaration.get(node);
if (!childAstDeclaration) {
throw new Error('Child declaration not found for the specified node');
}
if (childAstDeclaration.parent !== parentAstDeclaration) {
throw new node_core_library_1.InternalError('The found child is not attached to the parent AstDeclaration');
}
return childAstDeclaration;
}
/**
* 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) {
if (!this._entitiesByNode.has(identifier)) {
throw new node_core_library_1.InternalError('tryGetEntityForIdentifier() called for an identifier that was not analyzed');
}
return this._entitiesByNode.get(identifier);
}
/**
* 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) {
// TypeScript binds well-known ECMAScript symbols like "[Symbol.iterator]" as "__@iterator".
// Decode it back into "[Symbol.iterator]".
const wellKnownSymbolName = TypeScriptHelpers_1.TypeScriptHelpers.tryDecodeWellKnownSymbolName(symbol.escapedName);
if (wellKnownSymbolName) {
return wellKnownSymbolName;
}
const isUniqueSymbol = TypeScriptHelpers_1.TypeScriptHelpers.isUniqueSymbolName(symbol.escapedName);
// We will try to obtain the name from a declaration; otherwise we'll fall back to the symbol name.
let unquotedName = symbol.name;
for (const declaration of symbol.declarations || []) {
// Handle cases such as "export default class X { }" where the symbol name is "default"
// but the local name is "X".
const localSymbol = TypeScriptInternals_1.TypeScriptInternals.tryGetLocalSymbol(declaration);
if (localSymbol) {
unquotedName = localSymbol.name;
}
// If it is a non-well-known symbol, then return the late-bound name. For example, "X.Y.z" in this example:
//
// namespace X {
// export namespace Y {
// export const z: unique symbol = Symbol("z");
// }
// }
//
// class C {
// public [X.Y.z](): void { }
// }
//
if (isUniqueSymbol) {
const declarationName = ts.getNameOfDeclaration(declaration);
if (declarationName && ts.isComputedPropertyName(declarationName)) {
const lateBoundName = TypeScriptHelpers_1.TypeScriptHelpers.tryGetLateBoundName(declarationName);
if (lateBoundName) {
// Here the string may contain an expression such as "[X.Y.z]". Names starting with "[" are always
// expressions. If a string literal contains those characters, the code below will JSON.stringify() it
// to avoid a collision.
return lateBoundName;
}
}
}
}
// Otherwise that name may come from a quoted string or pseudonym like `__constructor`.
// If the string is not a safe identifier, then we must add quotes.
// Note that if it was quoted but did not need to be quoted, here we will remove the quotes.
if (!SyntaxHelpers_1.SyntaxHelpers.isSafeUnquotedMemberIdentifier(unquotedName)) {
// For API Extractor's purposes, a canonical form is more appropriate than trying to reflect whatever
// appeared in the source code. The code is not even guaranteed to be consistent, for example:
//
// class X {
// public "f1"(x: string): void;
// public f1(x: boolean): void;
// public 'f1'(x: string | boolean): void { }
// }
return JSON.stringify(unquotedName);
}
return unquotedName;
}
_analyzeAstNamespaceImport(astNamespaceImport) {
if (astNamespaceImport.analyzed) {
return;
}
// mark before actual analyzing, to handle module cyclic reexport
astNamespaceImport.analyzed = true;
const exportedLocalEntities = this.fetchAstModuleExportInfo(astNamespaceImport.astModule).exportedLocalEntities;
for (const exportedEntity of exportedLocalEntities.values()) {
this.analyze(exportedEntity);
}
}
_analyzeAstSymbol(astSymbol) {
if (astSymbol.analyzed) {
return;
}
if (astSymbol.nominalAnalysis) {
// We don't analyze nominal symbols
astSymbol._notifyAnalyzed();
return;
}
// Start at the root of the tree
const rootAstSymbol = astSymbol.rootAstSymbol;
// Calculate the full child tree for each definition
for (const astDeclaration of rootAstSymbol.astDeclarations) {
this._analyzeChildTree(astDeclaration.declaration, astDeclaration);
}
rootAstSymbol._notifyAnalyzed();
if (!astSymbol.isExternal) {
// If this symbol is non-external (i.e. it belongs to the working package), then we also analyze any
// referencedAstSymbols that are non-external. For example, this ensures that forgotten exports
// get analyzed.
rootAstSymbol.forEachDeclarationRecursive((astDeclaration) => {
for (const referencedAstEntity of astDeclaration.referencedAstEntities) {
// Walk up to the root of the tree, looking for any imports along the way
if (referencedAstEntity instanceof AstSymbol_1.AstSymbol) {
if (!referencedAstEntity.isExternal) {
this._analyzeAstSymbol(referencedAstEntity);
}
}
if (referencedAstEntity instanceof AstNamespaceImport_1.AstNamespaceImport) {
if (!referencedAstEntity.astModule.isExternal) {
this._analyzeAstNamespaceImport(referencedAstEntity);
}
}
}
});
}
}
/**
* Used by analyze to recursively analyze the entire child tree.
*/
_analyzeChildTree(node, governingAstDeclaration) {
switch (node.kind) {
case ts.SyntaxKind.JSDocComment: // Skip JSDoc comments - TS considers @param tags TypeReference nodes
return;
// Is this a reference to another AstSymbol?
case ts.SyntaxKind.TypeReference: // general type references
case ts.SyntaxKind.ExpressionWithTypeArguments: // special case for e.g. the "extends" keyword
case ts.SyntaxKind.ComputedPropertyName: // used for EcmaScript "symbols", e.g. "[toPrimitive]".
case ts.SyntaxKind.TypeQuery: // represents for "typeof X" as a type
{
// Sometimes the type reference will involve multiple identifiers, e.g. "a.b.C".
// In this case, we only need to worry about importing the first identifier,
// so do a depth-first search for it:
const identifierNode = TypeScriptHelpers_1.TypeScriptHelpers.findFirstChildNode(node, ts.SyntaxKind.Identifier);
if (identifierNode) {
let referencedAstEntity = this._entitiesByNode.get(identifierNode);
if (!referencedAstEntity) {
const symbol = this._typeChecker.getSymbolAtLocation(identifierNode);
if (!symbol) {
throw new Error('Symbol not found for identifier: ' + identifierNode.getText());
}
// Normally we expect getSymbolAtLocation() to take us to a declaration within the same source
// file, or else to an explicit "import" statement within the same source file. But in certain
// situations (e.g. a global variable) the symbol will refer to a declaration in some other
// source file. We'll call that case a "displaced symbol".
//
// For more info, see this discussion:
// https://github.com/microsoft/rushstack/issues/1765#issuecomment-595559849
let displacedSymbol = true;
for (const declaration of symbol.declarations || []) {
if (declaration.getSourceFile() === identifierNode.getSourceFile()) {
displacedSymbol = false;
break;
}
}
if (displacedSymbol) {
if (this._globalVariableAnalyzer.hasGlobalName(identifierNode.text)) {
// If the displaced symbol is a global variable, then API Extractor simply ignores it.
// Ambient declarations typically describe the runtime environment (provided by an API consumer),
// so we don't bother analyzing them as an API contract. (There are probably some packages
// that include interesting global variables in their API, but API Extractor doesn't support
// that yet; it would be a feature request.)
if (this._messageRouter.showDiagnostics) {
if (!this._alreadyWarnedGlobalNames.has(identifierNode.text)) {
this._alreadyWarnedGlobalNames.add(identifierNode.text);
this._messageRouter.logDiagnostic(`Ignoring reference to global variable "${identifierNode.text}"` +
` in ` +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(identifierNode));
}
}
}
else {
// If you encounter this, please report a bug with a repro. We're interested to know
// how it can occur.
throw new node_core_library_1.InternalError(`Unable to follow symbol for "${identifierNode.text}"`);
}
}
else {
referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntity(symbol, governingAstDeclaration.astSymbol.isExternal);
this._entitiesByNode.set(identifierNode, referencedAstEntity);
}
}
if (referencedAstEntity) {
governingAstDeclaration._notifyReferencedAstEntity(referencedAstEntity);
}
}
}
break;
// Is this the identifier for the governingAstDeclaration?
case ts.SyntaxKind.Identifier:
{
const identifierNode = node;
if (!this._entitiesByNode.has(identifierNode)) {
const symbol = this._typeChecker.getSymbolAtLocation(identifierNode);
let referencedAstEntity = undefined;
if (symbol === governingAstDeclaration.astSymbol.followedSymbol) {
referencedAstEntity = this._fetchEntityForNode(identifierNode, governingAstDeclaration);
}
this._entitiesByNode.set(identifierNode, referencedAstEntity);
}
}
break;
case ts.SyntaxKind.ImportType:
{
const importTypeNode = node;
let referencedAstEntity = this._entitiesByNode.get(importTypeNode);
if (!this._entitiesByNode.has(importTypeNode)) {
referencedAstEntity = this._fetchEntityForNode(importTypeNode, governingAstDeclaration);
if (!referencedAstEntity) {
// This should never happen
throw new Error('Failed to fetch entity for import() type node: ' + importTypeNode.getText());
}
this._entitiesByNode.set(importTypeNode, referencedAstEntity);
}
if (referencedAstEntity) {
governingAstDeclaration._notifyReferencedAstEntity(referencedAstEntity);
}
}
break;
}
// Is this node declaring a new AstSymbol?
const newGoverningAstDeclaration = this._fetchAstDeclaration(node, governingAstDeclaration.astSymbol.isExternal);
for (const childNode of node.getChildren()) {
this._analyzeChildTree(childNode, newGoverningAstDeclaration || governingAstDeclaration);
}
}
_fetchEntityForNode(node, governingAstDeclaration) {
let referencedAstEntity = this._entitiesByNode.get(node);
if (!referencedAstEntity) {
if (node.kind === ts.SyntaxKind.ImportType) {
referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntityFromImportTypeNode(node, governingAstDeclaration.astSymbol.isExternal);
}
else {
const symbol = this._typeChecker.getSymbolAtLocation(node);
if (!symbol) {
throw new Error('Symbol not found for identifier: ' + node.getText());
}
referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntity(symbol, governingAstDeclaration.astSymbol.isExternal);
}
this._entitiesByNode.set(node, referencedAstEntity);
}
return referencedAstEntity;
}
_fetchAstDeclaration(node, isExternal) {
if (!AstDeclaration_1.AstDeclaration.isSupportedSyntaxKind(node.kind)) {
return undefined;
}
const symbol = TypeScriptHelpers_1.TypeScriptHelpers.getSymbolForDeclaration(node, this._typeChecker);
if (!symbol) {
throw new node_core_library_1.InternalError('Unable to find symbol for node');
}
const astSymbol = this._fetchAstSymbol({
followedSymbol: symbol,
isExternal: isExternal,
includeNominalAnalysis: true,
addIfMissing: true
});
if (!astSymbol) {
return undefined;
}
const astDeclaration = this._astDeclarationsByDeclaration.get(node);
if (!astDeclaration) {
throw new node_core_library_1.InternalError('Unable to find constructed AstDeclaration');
}
return astDeclaration;
}
_fetchAstSymbol(options) {
const followedSymbol = options.followedSymbol;
// Filter out symbols representing constructs that we don't care about
const arbitraryDeclaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(followedSymbol);
if (!arbitraryDeclaration) {
return undefined;
}
if (followedSymbol.flags &
(ts.SymbolFlags.TypeParameter | ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.Transient)) {
if (!TypeScriptInternals_1.TypeScriptInternals.isLateBoundSymbol(followedSymbol)) {
return undefined;
}
}
// API Extractor doesn't analyze ambient declarations at all
if (TypeScriptHelpers_1.TypeScriptHelpers.isAmbient(followedSymbol, this._typeChecker)) {
// We make a special exemption for ambient declarations that appear in a source file containing
// an "export=" declaration that allows them to be imported as non-ambient.
if (!this._exportAnalyzer.isImportableAmbientSourceFile(arbitraryDeclaration.getSourceFile())) {
return undefined;
}
}
// Make sure followedSymbol isn't an alias for something else
if (TypeScriptHelpers_1.TypeScriptHelpers.isFollowableAlias(followedSymbol, this._typeChecker)) {
// We expect the caller to have already followed any aliases
throw new node_core_library_1.InternalError('AstSymbolTable._fetchAstSymbol() cannot be called with a symbol alias');
}
let astSymbol = this._astSymbolsBySymbol.get(followedSymbol);
if (!astSymbol) {
// None of the above lookups worked, so create a new entry...
let nominalAnalysis = false;
if (options.isExternal) {
// If the file is from an external package that does not support AEDoc, normally we ignore it completely.
// But in some cases (e.g. checking star exports of an external package) we need an AstSymbol to
// represent it, but we don't need to analyze its sibling/children.
const followedSymbolSourceFileName = arbitraryDeclaration.getSourceFile().fileName;
if (!this._packageMetadataManager.isAedocSupportedFor(followedSymbolSourceFileName)) {
nominalAnalysis = true;
if (!options.includeNominalAnalysis) {
return undefined;
}
}
}
let parentAstSymbol = undefined;
if (!nominalAnalysis) {
for (const declaration of followedSymbol.declarations || []) {
if (!AstDeclaration_1.AstDeclaration.isSupportedSyntaxKind(declaration.kind)) {
throw new node_core_library_1.InternalError(`The "${followedSymbol.name}" symbol has a` +
` ts.SyntaxKind.${ts.SyntaxKind[declaration.kind]} declaration which is not (yet?)` +
` supported by API Extractor`);
}
}
// We always fetch the entire chain of parents for each declaration.
// (Children/siblings are only analyzed on demand.)
// Key assumptions behind this squirrely logic:
//
// IF a given symbol has two declarations D1 and D2; AND
// If D1 has a parent P1, then
// - D2 will also have a parent P2; AND
// - P1 and P2's symbol will be the same
// - but P1 and P2 may be different (e.g. merged namespaces containing merged interfaces)
// Is there a parent AstSymbol? First we check to see if there is a parent declaration:
if (arbitraryDeclaration) {
const arbitraryParentDeclaration = this._tryFindFirstAstDeclarationParent(arbitraryDeclaration);
if (arbitraryParentDeclaration) {
const parentSymbol = TypeScriptHelpers_1.TypeScriptHelpers.getSymbolForDeclaration(arbitraryParentDeclaration, this._typeChecker);
parentAstSymbol = this._fetchAstSymbol({
followedSymbol: parentSymbol,
isExternal: options.isExternal,
includeNominalAnalysis: false,
addIfMissing: true
});
if (!parentAstSymbol) {
throw new node_core_library_1.InternalError('Unable to construct a parent AstSymbol for ' + followedSymbol.name);
}
}
}
}
const localName = options.localName || AstSymbolTable.getLocalNameForSymbol(followedSymbol);
astSymbol = new AstSymbol_1.AstSymbol({
followedSymbol: followedSymbol,
localName: localName,
isExternal: options.isExternal,
nominalAnalysis: nominalAnalysis,
parentAstSymbol: parentAstSymbol,
rootAstSymbol: parentAstSymbol ? parentAstSymbol.rootAstSymbol : undefined
});
this._astSymbolsBySymbol.set(followedSymbol, astSymbol);
// Okay, now while creating the declarations we will wire them up to the
// their corresponding parent declarations
for (const declaration of followedSymbol.declarations || []) {
let parentAstDeclaration = undefined;
if (parentAstSymbol) {
const parentDeclaration = this._tryFindFirstAstDeclarationParent(declaration);
if (!parentDeclaration) {
throw new node_core_library_1.InternalError('Missing parent declaration');
}
parentAstDeclaration = this._astDeclarationsByDeclaration.get(parentDeclaration);
if (!parentAstDeclaration) {
throw new node_core_library_1.InternalError('Missing parent AstDeclaration');
}
}
const astDeclaration = new AstDeclaration_1.AstDeclaration({
declaration,
astSymbol,
parent: parentAstDeclaration
});
this._astDeclarationsByDeclaration.set(declaration, astDeclaration);
}
}
if (options.isExternal !== astSymbol.isExternal) {
throw new node_core_library_1.InternalError(`Cannot assign isExternal=${options.isExternal} for` +
` the symbol ${astSymbol.localName} because it was previously registered` +
` with isExternal=${astSymbol.isExternal}`);
}
return astSymbol;
}
/**
* Returns the first parent satisfying isAstDeclaration(), or undefined if none is found.
*/
_tryFindFirstAstDeclarationParent(node) {
let currentNode = node.parent;
while (currentNode) {
if (AstDeclaration_1.AstDeclaration.isSupportedSyntaxKind(currentNode.kind)) {
return currentNode;
}
currentNode = currentNode.parent;
}
return undefined;
}
}
exports.AstSymbolTable = AstSymbolTable;
//# sourceMappingURL=AstSymbolTable.js.map
\ No newline at end of file
{"version":3,"file":"AstSymbolTable.js","sourceRoot":"","sources":["../../src/analyzer/AstSymbolTable.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+BAA+B,CAAC,qBAAqB;AAErD,+CAAiC;AAEjC,oEAAqF;AAErF,qDAAkD;AAClD,2DAAwD;AACxD,2CAAwC;AAExC,qEAAkE;AAClE,qDAAkD;AAElD,6DAA0D;AAE1D,+DAA0F;AAC1F,mDAAgD;AAChD,+EAA4E;AAiC5E;;;;;;;;;GASG;AACH,MAAa,cAAc;IAiCzB,YACE,OAAmB,EACnB,WAA2B,EAC3B,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,IAAI,CAAC,oBAAoB,EAAE,CAAC;wBAC1B,MAAM,IAAI,iCAAa,CAAC,+BAA+B,CAAC,CAAC;oBAC3D,CAAC;gBACH,CAAC;gBAED,MAAM,cAAc,GAAmB,IAAI,+BAAc,CAAC;oBACxD,WAAW;oBACX,SAAS;oBACT,MAAM,EAAE,oBAAoB;iBAC7B,CAAC,CAAC;gBAEH,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,UAAU,EAAE,CAAC;YAChD,MAAM,IAAI,iCAAa,CACrB,4BAA4B,OAAO,CAAC,UAAU,MAAM;gBAClD,eAAe,SAAS,CAAC,SAAS,uCAAuC;gBACzE,oBAAoB,SAAS,CAAC,UAAU,EAAE,CAC7C,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACK,iCAAiC,CAAC,IAAa;QACrD,IAAI,WAAW,GAAwB,IAAI,CAAC,MAAM,CAAC;QACnD,OAAO,WAAW,EAAE,CAAC;YACnB,IAAI,+BAAc,CAAC,qBAAqB,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3D,OAAO,WAAW,CAAC;YACrB,CAAC;YACD,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC;QACnC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAnoBD,wCAmoBC","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 */ // for ts.SymbolFlags\n\nimport * as ts from 'typescript';\n\nimport { type PackageJsonLookup, InternalError } from '@rushstack/node-core-library';\n\nimport { AstDeclaration } from './AstDeclaration';\nimport { TypeScriptHelpers } from './TypeScriptHelpers';\nimport { AstSymbol } from './AstSymbol';\nimport type { AstModule, IAstModuleExportInfo } from './AstModule';\nimport { PackageMetadataManager } from './PackageMetadataManager';\nimport { ExportAnalyzer } from './ExportAnalyzer';\nimport type { AstEntity } from './AstEntity';\nimport { AstNamespaceImport } from './AstNamespaceImport';\nimport type { MessageRouter } from '../collector/MessageRouter';\nimport { TypeScriptInternals, type IGlobalVariableAnalyzer } from './TypeScriptInternals';\nimport { SyntaxHelpers } from './SyntaxHelpers';\nimport { SourceFileLocationFormatter } from './SourceFileLocationFormatter';\n\n/**\n * Options for `AstSymbolTable._fetchAstSymbol()`\n */\nexport interface IFetchAstSymbolOptions {\n /**\n * The symbol after any symbol aliases have been followed using TypeScriptHelpers.followAliases()\n */\n followedSymbol: ts.Symbol;\n /**\n * True if followedSymbol is not part of the working package\n */\n isExternal: boolean;\n\n /**\n * If true, symbols with AstSymbol.nominalAnalysis=true will be returned.\n * Otherwise `undefined` will be returned for such symbols.\n */\n includeNominalAnalysis: boolean;\n\n /**\n * True while populating the `AstSymbolTable`; false if we're doing a passive lookup\n * without adding anything new to the table\n */\n addIfMissing: boolean;\n\n /**\n * A hint to help `_fetchAstSymbol()` determine the `AstSymbol.localName`.\n */\n localName?: string;\n}\n\n/**\n * AstSymbolTable is the workhorse that builds AstSymbol and AstDeclaration objects.\n * It maintains a cache of already constructed objects. AstSymbolTable constructs\n * AstModule objects, but otherwise the state that it maintains is agnostic of\n * any particular entry point. (For example, it does not track whether a given AstSymbol\n * is \"exported\" or not.)\n *\n * Internally, AstSymbolTable relies on ExportAnalyzer to crawl import statements and determine where symbols\n * are declared (i.e. the AstImport information needed to import them).\n */\nexport class AstSymbolTable {\n private readonly _program: ts.Program;\n private readonly _typeChecker: ts.TypeChecker;\n private readonly _messageRouter: MessageRouter;\n private readonly _globalVariableAnalyzer: IGlobalVariableAnalyzer;\n private readonly _packageMetadataManager: PackageMetadataManager;\n private readonly _exportAnalyzer: ExportAnalyzer;\n private readonly _alreadyWarnedGlobalNames: Set<string>;\n\n /**\n * A mapping from ts.Symbol --> AstSymbol\n * NOTE: The AstSymbol.followedSymbol will always be a lookup key, but additional keys\n * are possible.\n *\n * After following type aliases, we use this map to look up the corresponding AstSymbol.\n */\n private readonly _astSymbolsBySymbol: Map<ts.Symbol, AstSymbol> = new Map<ts.Symbol, AstSymbol>();\n\n /**\n * A mapping from ts.Declaration --> AstDeclaration\n */\n private readonly _astDeclarationsByDeclaration: Map<ts.Node, AstDeclaration> = new Map<\n ts.Node,\n AstDeclaration\n >();\n\n // Note that this is a mapping from specific AST nodes that we analyzed, based on the underlying symbol\n // for that node.\n private readonly _entitiesByNode: Map<ts.Identifier | ts.ImportTypeNode, AstEntity | undefined> = new Map<\n ts.Identifier,\n AstEntity | undefined\n >();\n\n public constructor(\n program: ts.Program,\n typeChecker: ts.TypeChecker,\n packageJsonLookup: PackageJsonLookup,\n bundledPackageNames: ReadonlySet<string>,\n messageRouter: MessageRouter\n ) {\n this._program = program;\n this._typeChecker = typeChecker;\n this._messageRouter = messageRouter;\n this._globalVariableAnalyzer = TypeScriptInternals.getGlobalVariableAnalyzer(program);\n this._packageMetadataManager = new PackageMetadataManager(packageJsonLookup, messageRouter);\n\n this._exportAnalyzer = new ExportAnalyzer(this._program, this._typeChecker, bundledPackageNames, {\n analyze: this.analyze.bind(this),\n fetchAstSymbol: this._fetchAstSymbol.bind(this)\n });\n\n this._alreadyWarnedGlobalNames = new Set<string>();\n }\n\n /**\n * Used to analyze an entry point that belongs to the working package.\n */\n public fetchAstModuleFromWorkingPackage(sourceFile: ts.SourceFile): AstModule {\n return this._exportAnalyzer.fetchAstModuleFromSourceFile(sourceFile, undefined, false);\n }\n\n /**\n * This crawls the specified entry point and collects the full set of exported AstSymbols.\n */\n public fetchAstModuleExportInfo(astModule: AstModule): IAstModuleExportInfo {\n return this._exportAnalyzer.fetchAstModuleExportInfo(astModule);\n }\n\n /**\n * Attempts to retrieve an export by name from the specified `AstModule`.\n * Returns undefined if no match was found.\n */\n public tryGetExportOfAstModule(exportName: string, astModule: AstModule): AstEntity | undefined {\n return this._exportAnalyzer.tryGetExportOfAstModule(exportName, astModule);\n }\n\n /**\n * Ensures that AstSymbol.analyzed is true for the provided symbol. The operation\n * starts from the root symbol and then fills out all children of all declarations, and\n * also calculates AstDeclaration.referencedAstSymbols for all declarations.\n * If the symbol is not imported, any non-imported references are also analyzed.\n *\n * @remarks\n * This is an expensive operation, so we only perform it for top-level exports of an\n * the AstModule. For example, if some code references a nested class inside\n * a namespace from another library, we do not analyze any of that class's siblings\n * or members. (We do always construct its parents however, since AstDefinition.parent\n * is immutable, and needed e.g. to calculate release tag inheritance.)\n */\n public analyze(astEntity: AstEntity): void {\n if (astEntity instanceof AstSymbol) {\n return this._analyzeAstSymbol(astEntity);\n }\n\n if (astEntity instanceof AstNamespaceImport) {\n return this._analyzeAstNamespaceImport(astEntity);\n }\n }\n\n /**\n * For a given astDeclaration, this efficiently finds the child corresponding to the\n * specified ts.Node. It is assumed that AstDeclaration.isSupportedSyntaxKind() would return true for\n * that node type, and that the node is an immediate child of the provided AstDeclaration.\n */\n // NOTE: This could be a method of AstSymbol if it had a backpointer to its AstSymbolTable.\n public getChildAstDeclarationByNode(node: ts.Node, parentAstDeclaration: AstDeclaration): AstDeclaration {\n if (!parentAstDeclaration.astSymbol.analyzed) {\n throw new Error('getChildDeclarationByNode() cannot be used for an AstSymbol that was not analyzed');\n }\n\n const childAstDeclaration: AstDeclaration | undefined = this._astDeclarationsByDeclaration.get(node);\n if (!childAstDeclaration) {\n throw new Error('Child declaration not found for the specified node');\n }\n if (childAstDeclaration.parent !== parentAstDeclaration) {\n throw new InternalError('The found child is not attached to the parent AstDeclaration');\n }\n\n return childAstDeclaration;\n }\n\n /**\n * For a given ts.Identifier that is part of an AstSymbol that we analyzed, return the AstEntity that\n * it refers to. Returns undefined if it doesn't refer to anything interesting.\n * @remarks\n * Throws an Error if the ts.Identifier is not part of node tree that was analyzed.\n */\n public tryGetEntityForNode(identifier: ts.Identifier | ts.ImportTypeNode): AstEntity | undefined {\n if (!this._entitiesByNode.has(identifier)) {\n throw new InternalError('tryGetEntityForIdentifier() called for an identifier that was not analyzed');\n }\n return this._entitiesByNode.get(identifier);\n }\n\n /**\n * Builds an AstSymbol.localName for a given ts.Symbol. In the current implementation, the localName is\n * a TypeScript-like expression that may be a string literal or ECMAScript symbol expression.\n *\n * ```ts\n * class X {\n * // localName=\"identifier\"\n * public identifier: number = 1;\n * // localName=\"\\\"identifier\\\"\"\n * public \"quoted string!\": number = 2;\n * // localName=\"[MyNamespace.MySymbol]\"\n * public [MyNamespace.MySymbol]: number = 3;\n * }\n * ```\n */\n public static getLocalNameForSymbol(symbol: ts.Symbol): string {\n // TypeScript binds well-known ECMAScript symbols like \"[Symbol.iterator]\" as \"__@iterator\".\n // Decode it back into \"[Symbol.iterator]\".\n const wellKnownSymbolName: string | undefined = TypeScriptHelpers.tryDecodeWellKnownSymbolName(\n symbol.escapedName\n );\n if (wellKnownSymbolName) {\n return wellKnownSymbolName;\n }\n\n const isUniqueSymbol: boolean = TypeScriptHelpers.isUniqueSymbolName(symbol.escapedName);\n\n // We will try to obtain the name from a declaration; otherwise we'll fall back to the symbol name.\n let unquotedName: string = symbol.name;\n\n for (const declaration of symbol.declarations || []) {\n // Handle cases such as \"export default class X { }\" where the symbol name is \"default\"\n // but the local name is \"X\".\n const localSymbol: ts.Symbol | undefined = TypeScriptInternals.tryGetLocalSymbol(declaration);\n if (localSymbol) {\n unquotedName = localSymbol.name;\n }\n\n // If it is a non-well-known symbol, then return the late-bound name. For example, \"X.Y.z\" in this example:\n //\n // namespace X {\n // export namespace Y {\n // export const z: unique symbol = Symbol(\"z\");\n // }\n // }\n //\n // class C {\n // public [X.Y.z](): void { }\n // }\n //\n if (isUniqueSymbol) {\n const declarationName: ts.DeclarationName | undefined = ts.getNameOfDeclaration(declaration);\n if (declarationName && ts.isComputedPropertyName(declarationName)) {\n const lateBoundName: string | undefined = TypeScriptHelpers.tryGetLateBoundName(declarationName);\n if (lateBoundName) {\n // Here the string may contain an expression such as \"[X.Y.z]\". Names starting with \"[\" are always\n // expressions. If a string literal contains those characters, the code below will JSON.stringify() it\n // to avoid a collision.\n return lateBoundName;\n }\n }\n }\n }\n\n // Otherwise that name may come from a quoted string or pseudonym like `__constructor`.\n // If the string is not a safe identifier, then we must add quotes.\n // Note that if it was quoted but did not need to be quoted, here we will remove the quotes.\n if (!SyntaxHelpers.isSafeUnquotedMemberIdentifier(unquotedName)) {\n // For API Extractor's purposes, a canonical form is more appropriate than trying to reflect whatever\n // appeared in the source code. The code is not even guaranteed to be consistent, for example:\n //\n // class X {\n // public \"f1\"(x: string): void;\n // public f1(x: boolean): void;\n // public 'f1'(x: string | boolean): void { }\n // }\n return JSON.stringify(unquotedName);\n }\n\n return unquotedName;\n }\n\n private _analyzeAstNamespaceImport(astNamespaceImport: AstNamespaceImport): void {\n if (astNamespaceImport.analyzed) {\n return;\n }\n\n // mark before actual analyzing, to handle module cyclic reexport\n astNamespaceImport.analyzed = true;\n\n const exportedLocalEntities: Map<string, AstEntity> = this.fetchAstModuleExportInfo(\n astNamespaceImport.astModule\n ).exportedLocalEntities;\n\n for (const exportedEntity of exportedLocalEntities.values()) {\n this.analyze(exportedEntity);\n }\n }\n\n private _analyzeAstSymbol(astSymbol: AstSymbol): void {\n if (astSymbol.analyzed) {\n return;\n }\n\n if (astSymbol.nominalAnalysis) {\n // We don't analyze nominal symbols\n astSymbol._notifyAnalyzed();\n return;\n }\n\n // Start at the root of the tree\n const rootAstSymbol: AstSymbol = astSymbol.rootAstSymbol;\n\n // Calculate the full child tree for each definition\n for (const astDeclaration of rootAstSymbol.astDeclarations) {\n this._analyzeChildTree(astDeclaration.declaration, astDeclaration);\n }\n\n rootAstSymbol._notifyAnalyzed();\n\n if (!astSymbol.isExternal) {\n // If this symbol is non-external (i.e. it belongs to the working package), then we also analyze any\n // referencedAstSymbols that are non-external. For example, this ensures that forgotten exports\n // get analyzed.\n rootAstSymbol.forEachDeclarationRecursive((astDeclaration: AstDeclaration) => {\n for (const referencedAstEntity of astDeclaration.referencedAstEntities) {\n // Walk up to the root of the tree, looking for any imports along the way\n if (referencedAstEntity instanceof AstSymbol) {\n if (!referencedAstEntity.isExternal) {\n this._analyzeAstSymbol(referencedAstEntity);\n }\n }\n\n if (referencedAstEntity instanceof AstNamespaceImport) {\n if (!referencedAstEntity.astModule.isExternal) {\n this._analyzeAstNamespaceImport(referencedAstEntity);\n }\n }\n }\n });\n }\n }\n\n /**\n * Used by analyze to recursively analyze the entire child tree.\n */\n private _analyzeChildTree(node: ts.Node, governingAstDeclaration: AstDeclaration): void {\n switch (node.kind) {\n case ts.SyntaxKind.JSDocComment: // Skip JSDoc comments - TS considers @param tags TypeReference nodes\n return;\n\n // Is this a reference to another AstSymbol?\n case ts.SyntaxKind.TypeReference: // general type references\n case ts.SyntaxKind.ExpressionWithTypeArguments: // special case for e.g. the \"extends\" keyword\n case ts.SyntaxKind.ComputedPropertyName: // used for EcmaScript \"symbols\", e.g. \"[toPrimitive]\".\n case ts.SyntaxKind.TypeQuery: // represents for \"typeof X\" as a type\n {\n // Sometimes the type reference will involve multiple identifiers, e.g. \"a.b.C\".\n // In this case, we only need to worry about importing the first identifier,\n // so do a depth-first search for it:\n const identifierNode: ts.Identifier | undefined = TypeScriptHelpers.findFirstChildNode(\n node,\n ts.SyntaxKind.Identifier\n );\n\n if (identifierNode) {\n let referencedAstEntity: AstEntity | undefined = this._entitiesByNode.get(identifierNode);\n if (!referencedAstEntity) {\n const symbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(identifierNode);\n if (!symbol) {\n throw new Error('Symbol not found for identifier: ' + identifierNode.getText());\n }\n\n // Normally we expect getSymbolAtLocation() to take us to a declaration within the same source\n // file, or else to an explicit \"import\" statement within the same source file. But in certain\n // situations (e.g. a global variable) the symbol will refer to a declaration in some other\n // source file. We'll call that case a \"displaced symbol\".\n //\n // For more info, see this discussion:\n // https://github.com/microsoft/rushstack/issues/1765#issuecomment-595559849\n let displacedSymbol: boolean = true;\n for (const declaration of symbol.declarations || []) {\n if (declaration.getSourceFile() === identifierNode.getSourceFile()) {\n displacedSymbol = false;\n break;\n }\n }\n\n if (displacedSymbol) {\n if (this._globalVariableAnalyzer.hasGlobalName(identifierNode.text)) {\n // If the displaced symbol is a global variable, then API Extractor simply ignores it.\n // Ambient declarations typically describe the runtime environment (provided by an API consumer),\n // so we don't bother analyzing them as an API contract. (There are probably some packages\n // that include interesting global variables in their API, but API Extractor doesn't support\n // that yet; it would be a feature request.)\n\n if (this._messageRouter.showDiagnostics) {\n if (!this._alreadyWarnedGlobalNames.has(identifierNode.text)) {\n this._alreadyWarnedGlobalNames.add(identifierNode.text);\n this._messageRouter.logDiagnostic(\n `Ignoring reference to global variable \"${identifierNode.text}\"` +\n ` in ` +\n SourceFileLocationFormatter.formatDeclaration(identifierNode)\n );\n }\n }\n } else {\n // If you encounter this, please report a bug with a repro. We're interested to know\n // how it can occur.\n throw new InternalError(`Unable to follow symbol for \"${identifierNode.text}\"`);\n }\n } else {\n referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntity(\n symbol,\n governingAstDeclaration.astSymbol.isExternal\n );\n\n this._entitiesByNode.set(identifierNode, referencedAstEntity);\n }\n }\n\n if (referencedAstEntity) {\n governingAstDeclaration._notifyReferencedAstEntity(referencedAstEntity);\n }\n }\n }\n break;\n\n // Is this the identifier for the governingAstDeclaration?\n case ts.SyntaxKind.Identifier:\n {\n const identifierNode: ts.Identifier = node as ts.Identifier;\n if (!this._entitiesByNode.has(identifierNode)) {\n const symbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(identifierNode);\n\n let referencedAstEntity: AstEntity | undefined = undefined;\n\n if (symbol === governingAstDeclaration.astSymbol.followedSymbol) {\n referencedAstEntity = this._fetchEntityForNode(identifierNode, governingAstDeclaration);\n }\n\n this._entitiesByNode.set(identifierNode, referencedAstEntity);\n }\n }\n break;\n\n case ts.SyntaxKind.ImportType:\n {\n const importTypeNode: ts.ImportTypeNode = node as ts.ImportTypeNode;\n let referencedAstEntity: AstEntity | undefined = this._entitiesByNode.get(importTypeNode);\n\n if (!this._entitiesByNode.has(importTypeNode)) {\n referencedAstEntity = this._fetchEntityForNode(importTypeNode, governingAstDeclaration);\n\n if (!referencedAstEntity) {\n // This should never happen\n throw new Error('Failed to fetch entity for import() type node: ' + importTypeNode.getText());\n }\n\n this._entitiesByNode.set(importTypeNode, referencedAstEntity);\n }\n\n if (referencedAstEntity) {\n governingAstDeclaration._notifyReferencedAstEntity(referencedAstEntity);\n }\n }\n break;\n }\n\n // Is this node declaring a new AstSymbol?\n const newGoverningAstDeclaration: AstDeclaration | undefined = this._fetchAstDeclaration(\n node,\n governingAstDeclaration.astSymbol.isExternal\n );\n\n for (const childNode of node.getChildren()) {\n this._analyzeChildTree(childNode, newGoverningAstDeclaration || governingAstDeclaration);\n }\n }\n\n private _fetchEntityForNode(\n node: ts.Identifier | ts.ImportTypeNode,\n governingAstDeclaration: AstDeclaration\n ): AstEntity | undefined {\n let referencedAstEntity: AstEntity | undefined = this._entitiesByNode.get(node);\n if (!referencedAstEntity) {\n if (node.kind === ts.SyntaxKind.ImportType) {\n referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntityFromImportTypeNode(\n node,\n governingAstDeclaration.astSymbol.isExternal\n );\n } else {\n const symbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(node);\n if (!symbol) {\n throw new Error('Symbol not found for identifier: ' + node.getText());\n }\n\n referencedAstEntity = this._exportAnalyzer.fetchReferencedAstEntity(\n symbol,\n governingAstDeclaration.astSymbol.isExternal\n );\n }\n\n this._entitiesByNode.set(node, referencedAstEntity);\n }\n return referencedAstEntity;\n }\n\n private _fetchAstDeclaration(node: ts.Node, isExternal: boolean): AstDeclaration | undefined {\n if (!AstDeclaration.isSupportedSyntaxKind(node.kind)) {\n return undefined;\n }\n\n const symbol: ts.Symbol | undefined = TypeScriptHelpers.getSymbolForDeclaration(\n node as ts.Declaration,\n this._typeChecker\n );\n if (!symbol) {\n throw new InternalError('Unable to find symbol for node');\n }\n\n const astSymbol: AstSymbol | undefined = this._fetchAstSymbol({\n followedSymbol: symbol,\n isExternal: isExternal,\n includeNominalAnalysis: true,\n addIfMissing: true\n });\n\n if (!astSymbol) {\n return undefined;\n }\n\n const astDeclaration: AstDeclaration | undefined = this._astDeclarationsByDeclaration.get(node);\n\n if (!astDeclaration) {\n throw new InternalError('Unable to find constructed AstDeclaration');\n }\n\n return astDeclaration;\n }\n\n private _fetchAstSymbol(options: IFetchAstSymbolOptions): AstSymbol | undefined {\n const followedSymbol: ts.Symbol = options.followedSymbol;\n\n // Filter out symbols representing constructs that we don't care about\n const arbitraryDeclaration: ts.Declaration | undefined =\n TypeScriptHelpers.tryGetADeclaration(followedSymbol);\n if (!arbitraryDeclaration) {\n return undefined;\n }\n\n if (\n followedSymbol.flags &\n (ts.SymbolFlags.TypeParameter | ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.Transient)\n ) {\n if (!TypeScriptInternals.isLateBoundSymbol(followedSymbol)) {\n return undefined;\n }\n }\n\n // API Extractor doesn't analyze ambient declarations at all\n if (TypeScriptHelpers.isAmbient(followedSymbol, this._typeChecker)) {\n // We make a special exemption for ambient declarations that appear in a source file containing\n // an \"export=\" declaration that allows them to be imported as non-ambient.\n if (!this._exportAnalyzer.isImportableAmbientSourceFile(arbitraryDeclaration.getSourceFile())) {\n return undefined;\n }\n }\n\n // Make sure followedSymbol isn't an alias for something else\n if (TypeScriptHelpers.isFollowableAlias(followedSymbol, this._typeChecker)) {\n // We expect the caller to have already followed any aliases\n throw new InternalError('AstSymbolTable._fetchAstSymbol() cannot be called with a symbol alias');\n }\n\n let astSymbol: AstSymbol | undefined = this._astSymbolsBySymbol.get(followedSymbol);\n\n if (!astSymbol) {\n // None of the above lookups worked, so create a new entry...\n let nominalAnalysis: boolean = false;\n\n if (options.isExternal) {\n // If the file is from an external package that does not support AEDoc, normally we ignore it completely.\n // But in some cases (e.g. checking star exports of an external package) we need an AstSymbol to\n // represent it, but we don't need to analyze its sibling/children.\n const followedSymbolSourceFileName: string = arbitraryDeclaration.getSourceFile().fileName;\n\n if (!this._packageMetadataManager.isAedocSupportedFor(followedSymbolSourceFileName)) {\n nominalAnalysis = true;\n\n if (!options.includeNominalAnalysis) {\n return undefined;\n }\n }\n }\n\n let parentAstSymbol: AstSymbol | undefined = undefined;\n\n if (!nominalAnalysis) {\n for (const declaration of followedSymbol.declarations || []) {\n if (!AstDeclaration.isSupportedSyntaxKind(declaration.kind)) {\n throw new InternalError(\n `The \"${followedSymbol.name}\" symbol has a` +\n ` ts.SyntaxKind.${ts.SyntaxKind[declaration.kind]} declaration which is not (yet?)` +\n ` supported by API Extractor`\n );\n }\n }\n\n // We always fetch the entire chain of parents for each declaration.\n // (Children/siblings are only analyzed on demand.)\n\n // Key assumptions behind this squirrely logic:\n //\n // IF a given symbol has two declarations D1 and D2; AND\n // If D1 has a parent P1, then\n // - D2 will also have a parent P2; AND\n // - P1 and P2's symbol will be the same\n // - but P1 and P2 may be different (e.g. merged namespaces containing merged interfaces)\n\n // Is there a parent AstSymbol? First we check to see if there is a parent declaration:\n if (arbitraryDeclaration) {\n const arbitraryParentDeclaration: ts.Node | undefined =\n this._tryFindFirstAstDeclarationParent(arbitraryDeclaration);\n\n if (arbitraryParentDeclaration) {\n const parentSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(\n arbitraryParentDeclaration as ts.Declaration,\n this._typeChecker\n );\n\n parentAstSymbol = this._fetchAstSymbol({\n followedSymbol: parentSymbol,\n isExternal: options.isExternal,\n includeNominalAnalysis: false,\n addIfMissing: true\n });\n if (!parentAstSymbol) {\n throw new InternalError('Unable to construct a parent AstSymbol for ' + followedSymbol.name);\n }\n }\n }\n }\n\n const localName: string | undefined =\n options.localName || AstSymbolTable.getLocalNameForSymbol(followedSymbol);\n\n astSymbol = new AstSymbol({\n followedSymbol: followedSymbol,\n localName: localName,\n isExternal: options.isExternal,\n nominalAnalysis: nominalAnalysis,\n parentAstSymbol: parentAstSymbol,\n rootAstSymbol: parentAstSymbol ? parentAstSymbol.rootAstSymbol : undefined\n });\n\n this._astSymbolsBySymbol.set(followedSymbol, astSymbol);\n\n // Okay, now while creating the declarations we will wire them up to the\n // their corresponding parent declarations\n for (const declaration of followedSymbol.declarations || []) {\n let parentAstDeclaration: AstDeclaration | undefined = undefined;\n if (parentAstSymbol) {\n const parentDeclaration: ts.Node | undefined = this._tryFindFirstAstDeclarationParent(declaration);\n\n if (!parentDeclaration) {\n throw new InternalError('Missing parent declaration');\n }\n\n parentAstDeclaration = this._astDeclarationsByDeclaration.get(parentDeclaration);\n if (!parentAstDeclaration) {\n throw new InternalError('Missing parent AstDeclaration');\n }\n }\n\n const astDeclaration: AstDeclaration = new AstDeclaration({\n declaration,\n astSymbol,\n parent: parentAstDeclaration\n });\n\n this._astDeclarationsByDeclaration.set(declaration, astDeclaration);\n }\n }\n\n if (options.isExternal !== astSymbol.isExternal) {\n throw new InternalError(\n `Cannot assign isExternal=${options.isExternal} for` +\n ` the symbol ${astSymbol.localName} because it was previously registered` +\n ` with isExternal=${astSymbol.isExternal}`\n );\n }\n\n return astSymbol;\n }\n\n /**\n * Returns the first parent satisfying isAstDeclaration(), or undefined if none is found.\n */\n private _tryFindFirstAstDeclarationParent(node: ts.Node): ts.Node | undefined {\n let currentNode: ts.Node | undefined = node.parent;\n while (currentNode) {\n if (AstDeclaration.isSupportedSyntaxKind(currentNode.kind)) {\n return currentNode;\n }\n currentNode = currentNode.parent;\n }\n return undefined;\n }\n}\n"]}
\ No newline at end of file
import * as ts from 'typescript';
import { AstSymbol } from './AstSymbol';
import { AstModule, type IAstModuleExportInfo } from './AstModule';
import type { IFetchAstSymbolOptions } from './AstSymbolTable';
import type { AstEntity } from './AstEntity';
/**
* Exposes the minimal APIs from AstSymbolTable that are needed by ExportAnalyzer.
*
* In particular, we want ExportAnalyzer to be able to call AstSymbolTable._fetchAstSymbol() even though it
* is a very private API that should not be exposed to any other components.
*/
export interface IAstSymbolTable {
fetchAstSymbol(options: IFetchAstSymbolOptions): AstSymbol | undefined;
analyze(astEntity: AstEntity): void;
}
/**
* Used with ExportAnalyzer.fetchAstModuleBySourceFile() to provide contextual information about how the source file
* was imported.
*/
interface IAstModuleReference {
/**
* For example, if we are following a statement like `import { X } from 'some-package'`, this will be the
* string `"some-package"`.
*/
moduleSpecifier: string;
/**
* For example, if we are following a statement like `import { X } from 'some-package'`, this will be the
* symbol for `X`.
*/
moduleSpecifierSymbol: ts.Symbol;
}
/**
* The ExportAnalyzer is an internal part of AstSymbolTable that has been moved out into its own source file
* because it is a complex and mostly self-contained algorithm.
*
* Its job is to build up AstModule objects by crawling import statements to discover where declarations come from.
* This is conceptually the same as the compiler's own TypeChecker.getExportsOfModule(), except that when
* ExportAnalyzer encounters a declaration that was imported from an external package, it remembers how it was imported
* (i.e. the AstImport object). Today the compiler API does not expose this information, which is crucial for
* generating .d.ts rollups.
*/
export declare class ExportAnalyzer {
private readonly _program;
private readonly _typeChecker;
private readonly _bundledPackageNames;
private readonly _astSymbolTable;
private readonly _astModulesByModuleSymbol;
private readonly _importableAmbientSourceFiles;
private readonly _astImportsByKey;
private readonly _astNamespaceImportByModule;
constructor(program: ts.Program, typeChecker: ts.TypeChecker, bundledPackageNames: ReadonlySet<string>, astSymbolTable: IAstSymbolTable);
/**
* For a given source file, this analyzes all of its exports and produces an AstModule object.
*
* @param moduleReference - contextual information about the import statement that took us to this source file.
* or `undefined` if this source file is the initial entry point
* @param isExternal - whether the given `moduleReference` is external.
*/
fetchAstModuleFromSourceFile(sourceFile: ts.SourceFile, moduleReference: IAstModuleReference | undefined, isExternal: boolean): AstModule;
/**
* Retrieves the symbol for the module corresponding to the ts.SourceFile that is being imported/exported.
*
* @remarks
* The `module` keyword can be used to declare multiple TypeScript modules inside a single source file.
* (This is a deprecated construct and mainly used for typings such as `@types/node`.) In this situation,
* `moduleReference` helps us to fish out the correct module symbol.
*/
private _getModuleSymbolFromSourceFile;
/**
* Implementation of {@link AstSymbolTable.fetchAstModuleExportInfo}.
*/
fetchAstModuleExportInfo(entryPointAstModule: AstModule): IAstModuleExportInfo;
/**
* Returns true if the module specifier refers to an external package. Ignores packages listed in the
* "bundledPackages" setting from the api-extractor.json config file.
*/
private _isExternalModulePath;
/**
* Returns true if when we analyzed sourceFile, we found that it contains an "export=" statement that allows
* it to behave /either/ as an ambient module /or/ as a regular importable module. In this case,
* `AstSymbolTable._fetchAstSymbol()` will analyze its symbols even though `TypeScriptHelpers.isAmbient()`
* returns true.
*/
isImportableAmbientSourceFile(sourceFile: ts.SourceFile): boolean;
private _collectAllExportsRecursive;
/**
* For a given symbol (which was encountered in the specified sourceFile), this fetches the AstEntity that it
* refers to. For example, if a particular interface describes the return value of a function, this API can help
* us determine a TSDoc declaration reference for that symbol (if the symbol is exported).
*/
fetchReferencedAstEntity(symbol: ts.Symbol, referringModuleIsExternal: boolean): AstEntity | undefined;
fetchReferencedAstEntityFromImportTypeNode(node: ts.ImportTypeNode, referringModuleIsExternal: boolean): AstEntity | undefined;
private _tryMatchExportDeclaration;
private _getAstNamespaceExport;
private _tryMatchImportDeclaration;
private _getAstNamespaceImport;
private static _getIsTypeOnly;
private _getExportOfSpecifierAstModule;
private _getExportOfAstModule;
/**
* Implementation of {@link AstSymbolTable.tryGetExportOfAstModule}.
*/
tryGetExportOfAstModule(exportName: string, astModule: AstModule): AstEntity | undefined;
private _tryGetExportOfAstModule;
private _tryGetExternalModulePath;
/**
* Given an ImportDeclaration of the form `export { X } from "___";`, this interprets the module specifier (`"___"`)
* and fetches the corresponding AstModule object.
*/
private _fetchSpecifierAstModule;
private _fetchAstImport;
private _getModuleSpecifier;
}
export {};
//# sourceMappingURL=ExportAnalyzer.d.ts.map
\ No newline at end of file
{"version":3,"file":"ExportAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyzer/ExportAnalyzer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAKjC,OAAO,EAAE,SAAS,EAAE,MAAM,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,OAAO,CAAC,8BAA8B;IAiDtC;;OAEG;IACI,wBAAwB,CAAC,mBAAmB,EAAE,SAAS,GAAG,oBAAoB;IAmBrF;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAmD7B;;;;;OAKG;IACI,6BAA6B,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,OAAO;IAIxE,OAAO,CAAC,2BAA2B;IA6CnC;;;;OAIG;IACI,wBAAwB,CAC7B,MAAM,EAAE,EAAE,CAAC,MAAM,EACjB,yBAAyB,EAAE,OAAO,GACjC,SAAS,GAAG,SAAS;IA4DjB,0CAA0C,CAC/C,IAAI,EAAE,EAAE,CAAC,cAAc,EACvB,yBAAyB,EAAE,OAAO,GACjC,SAAS,GAAG,SAAS;IA0FxB,OAAO,CAAC,0BAA0B;IA0ElC,OAAO,CAAC,sBAAsB;IAmB9B,OAAO,CAAC,0BAA0B;IA0JlC,OAAO,CAAC,sBAAsB;IAmB9B,OAAO,CAAC,MAAM,CAAC,cAAc;IAO7B,OAAO,CAAC,8BAA8B;IAatC,OAAO,CAAC,qBAAqB;IAe7B;;OAEG;IACI,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS;IAK/F,OAAO,CAAC,wBAAwB;IAoDhC,OAAO,CAAC,yBAAyB;IAWjC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IA6DhC,OAAO,CAAC,eAAe;IA8BvB,OAAO,CAAC,mBAAmB;CAgB5B"}
\ 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.ExportAnalyzer = void 0;
const ts = __importStar(require("typescript"));
const node_core_library_1 = require("@rushstack/node-core-library");
const TypeScriptHelpers_1 = require("./TypeScriptHelpers");
const AstSymbol_1 = require("./AstSymbol");
const AstImport_1 = require("./AstImport");
const AstModule_1 = require("./AstModule");
const TypeScriptInternals_1 = require("./TypeScriptInternals");
const SourceFileLocationFormatter_1 = require("./SourceFileLocationFormatter");
const AstNamespaceImport_1 = require("./AstNamespaceImport");
const SyntaxHelpers_1 = require("./SyntaxHelpers");
const AstNamespaceExport_1 = require("./AstNamespaceExport");
/**
* The ExportAnalyzer is an internal part of AstSymbolTable that has been moved out into its own source file
* because it is a complex and mostly self-contained algorithm.
*
* Its job is to build up AstModule objects by crawling import statements to discover where declarations come from.
* This is conceptually the same as the compiler's own TypeChecker.getExportsOfModule(), except that when
* ExportAnalyzer encounters a declaration that was imported from an external package, it remembers how it was imported
* (i.e. the AstImport object). Today the compiler API does not expose this information, which is crucial for
* generating .d.ts rollups.
*/
class ExportAnalyzer {
constructor(program, typeChecker, bundledPackageNames, astSymbolTable) {
this._astModulesByModuleSymbol = new Map();
// Used with isImportableAmbientSourceFile()
this._importableAmbientSourceFiles = new Set();
this._astImportsByKey = new Map();
this._astNamespaceImportByModule = new Map();
this._program = program;
this._typeChecker = typeChecker;
this._bundledPackageNames = bundledPackageNames;
this._astSymbolTable = astSymbolTable;
}
/**
* For a given source file, this analyzes all of its exports and produces an AstModule object.
*
* @param moduleReference - contextual information about the import statement that took us to this source file.
* or `undefined` if this source file is the initial entry point
* @param isExternal - whether the given `moduleReference` is external.
*/
fetchAstModuleFromSourceFile(sourceFile, moduleReference, isExternal) {
const moduleSymbol = this._getModuleSymbolFromSourceFile(sourceFile, moduleReference);
// Don't traverse into a module that we already processed before:
// The compiler allows m1 to have "export * from 'm2'" and "export * from 'm3'",
// even if m2 and m3 both have "export * from 'm4'".
let astModule = this._astModulesByModuleSymbol.get(moduleSymbol);
if (!astModule) {
// (If moduleReference === undefined, then this is the entry point of the local project being analyzed.)
const externalModulePath = moduleReference !== undefined && isExternal ? moduleReference.moduleSpecifier : undefined;
astModule = new AstModule_1.AstModule({ sourceFile, moduleSymbol, externalModulePath });
this._astModulesByModuleSymbol.set(moduleSymbol, astModule);
if (astModule.isExternal) {
// It's an external package, so do the special simplified analysis that doesn't crawl into referenced modules
for (const exportedSymbol of this._typeChecker.getExportsOfModule(moduleSymbol)) {
if (externalModulePath === undefined) {
throw new node_core_library_1.InternalError('Failed assertion: externalModulePath=undefined but astModule.isExternal=true');
}
const followedSymbol = TypeScriptHelpers_1.TypeScriptHelpers.followAliases(exportedSymbol, this._typeChecker);
// Ignore virtual symbols that don't have any declarations
const arbitraryDeclaration = TypeScriptHelpers_1.TypeScriptHelpers.tryGetADeclaration(followedSymbol);
if (arbitraryDeclaration) {
const astSymbol = this._astSymbolTable.fetchAstSymbol({
followedSymbol: followedSymbol,
isExternal: astModule.isExternal,
includeNominalAnalysis: true,
addIfMissing: true
});
if (!astSymbol) {
throw new Error(`Unsupported export ${JSON.stringify(exportedSymbol.name)}:\n` +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(arbitraryDeclaration));
}
astModule.cachedExportedEntities.set(exportedSymbol.name, astSymbol);
}
}
}
else {
// The module is part of the local project, so do the full analysis
if (moduleSymbol.exports) {
// The "export * from 'module-name';" declarations are all attached to a single virtual symbol
// whose name is InternalSymbolName.ExportStar
const exportStarSymbol = moduleSymbol.exports.get(ts.InternalSymbolName.ExportStar);
if (exportStarSymbol) {
for (const exportStarDeclaration of exportStarSymbol.getDeclarations() || []) {
if (ts.isExportDeclaration(exportStarDeclaration)) {
const starExportedModule = this._fetchSpecifierAstModule(exportStarDeclaration, exportStarSymbol);
if (starExportedModule !== undefined) {
astModule.starExportedModules.add(starExportedModule);
}
}
else {
// Ignore ExportDeclaration nodes that don't match the expected pattern
// TODO: Should we report a warning?
}
}
}
}
}
}
return astModule;
}
/**
* Retrieves the symbol for the module corresponding to the ts.SourceFile that is being imported/exported.
*
* @remarks
* The `module` keyword can be used to declare multiple TypeScript modules inside a single source file.
* (This is a deprecated construct and mainly used for typings such as `@types/node`.) In this situation,
* `moduleReference` helps us to fish out the correct module symbol.
*/
_getModuleSymbolFromSourceFile(sourceFile, moduleReference) {
const moduleSymbol = TypeScriptInternals_1.TypeScriptInternals.tryGetSymbolForDeclaration(sourceFile, this._typeChecker);
if (moduleSymbol !== undefined) {
// This is the normal case. The SourceFile acts is a module and has a symbol.
return moduleSymbol;
}
if (moduleReference !== undefined) {
// But there is also an elaborate case where the source file contains one or more "module" declarations,
// and our moduleReference took us to one of those.
// eslint-disable-next-line no-bitwise
if ((moduleReference.moduleSpecifierSymbol.flags & ts.SymbolFlags.Alias) !== 0) {
// Follow the import/export declaration to one hop the exported item inside the target module
let followedSymbol = TypeScriptInternals_1.TypeScriptInternals.getImmediateAliasedSymbol(moduleReference.moduleSpecifierSymbol, this._typeChecker);
if (followedSymbol === undefined) {
// This is a workaround for a compiler bug where getImmediateAliasedSymbol() sometimes returns undefined
followedSymbol = this._typeChecker.getAliasedSymbol(moduleReference.moduleSpecifierSymbol);
}
if (followedSymbol !== undefined && followedSymbol !== moduleReference.moduleSpecifierSymbol) {
// The parent of the exported symbol will be the module that we're importing from
const parent = TypeScriptInternals_1.TypeScriptInternals.getSymbolParent(followedSymbol);
if (parent !== undefined) {
// Make sure the thing we found is a module
// eslint-disable-next-line no-bitwise
if ((parent.flags & ts.SymbolFlags.ValueModule) !== 0) {
// Record that that this is an ambient module that can also be imported from
this._importableAmbientSourceFiles.add(sourceFile);
return parent;
}
}
}
}
}
throw new node_core_library_1.InternalError('Unable to determine module for: ' + sourceFile.fileName);
}
/**
* Implementation of {@link AstSymbolTable.fetchAstModuleExportInfo}.
*/
fetchAstModuleExportInfo(entryPointAstModule) {
if (entryPointAstModule.isExternal) {
throw new Error('fetchAstModuleExportInfo() is not supported for external modules');
}
if (entryPointAstModule.astModuleExportInfo === undefined) {
const astModuleExportInfo = {
visitedAstModules: new Set(),
exportedLocalEntities: new Map(),
starExportedExternalModules: new Set()
};
this._collectAllExportsRecursive(astModuleExportInfo, entryPointAstModule);
entryPointAstModule.astModuleExportInfo = astModuleExportInfo;
}
return entryPointAstModule.astModuleExportInfo;
}
/**
* Returns true if the module specifier refers to an external package. Ignores packages listed in the
* "bundledPackages" setting from the api-extractor.json config file.
*/
_isExternalModulePath(importOrExportDeclaration, moduleSpecifier) {
var _a;
let specifier = ts.isImportTypeNode(importOrExportDeclaration)
? importOrExportDeclaration.argument
: importOrExportDeclaration.moduleSpecifier;
if (specifier && ts.isLiteralTypeNode(specifier)) {
specifier = specifier.literal;
}
const mode = specifier && ts.isStringLiteralLike(specifier)
? TypeScriptInternals_1.TypeScriptInternals.getModeForUsageLocation(importOrExportDeclaration.getSourceFile(), specifier, this._program.getCompilerOptions())
: undefined;
const resolvedModule = TypeScriptInternals_1.TypeScriptInternals.getResolvedModule(this._program, importOrExportDeclaration.getSourceFile(), moduleSpecifier, mode);
if (resolvedModule === undefined) {
// The TS compiler API `getResolvedModule` cannot resolve ambient modules. Thus, to match API Extractor's
// previous behavior, simply treat all ambient modules as external. This bug is tracked by
// https://github.com/microsoft/rushstack/issues/3335.
return true;
}
// Either something like `jquery` or `@microsoft/api-extractor`.
const packageName = (_a = resolvedModule.packageId) === null || _a === void 0 ? void 0 : _a.name;
if (packageName !== undefined && this._bundledPackageNames.has(packageName)) {
return false;
}
if (resolvedModule.isExternalLibraryImport === undefined) {
// This presumably means the compiler couldn't figure out whether the module was external, but we're not
// sure how this can happen.
throw new node_core_library_1.InternalError(`Cannot determine whether the module ${JSON.stringify(moduleSpecifier)} is external\n` +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration));
}
return resolvedModule.isExternalLibraryImport;
}
/**
* Returns true if when we analyzed sourceFile, we found that it contains an "export=" statement that allows
* it to behave /either/ as an ambient module /or/ as a regular importable module. In this case,
* `AstSymbolTable._fetchAstSymbol()` will analyze its symbols even though `TypeScriptHelpers.isAmbient()`
* returns true.
*/
isImportableAmbientSourceFile(sourceFile) {
return this._importableAmbientSourceFiles.has(sourceFile);
}
_collectAllExportsRecursive(astModuleExportInfo, astModule) {
const { visitedAstModules, starExportedExternalModules, exportedLocalEntities } = astModuleExportInfo;
if (visitedAstModules.has(astModule)) {
return;
}
visitedAstModules.add(astModule);
if (astModule.isExternal) {
starExportedExternalModules.add(astModule);
}
else {
// Fetch each of the explicit exports for this module
if (astModule.moduleSymbol.exports) {
astModule.moduleSymbol.exports.forEach((exportSymbol, exportName) => {
switch (exportName) {
case ts.InternalSymbolName.ExportStar:
case ts.InternalSymbolName.ExportEquals:
break;
default:
// Don't collect the "export default" symbol unless this is the entry point module
if (exportName !== ts.InternalSymbolName.Default || visitedAstModules.size === 1) {
if (!exportedLocalEntities.has(exportSymbol.name)) {
const astEntity = this._getExportOfAstModule(exportSymbol.name, astModule);
if (astEntity instanceof AstSymbol_1.AstSymbol && !astEntity.isExternal) {
this._astSymbolTable.analyze(astEntity);
}
if (astEntity instanceof AstNamespaceImport_1.AstNamespaceImport && !astEntity.astModule.isExternal) {
this._astSymbolTable.analyze(astEntity);
}
exportedLocalEntities.set(exportSymbol.name, astEntity);
}
}
break;
}
});
}
for (const starExportedModule of astModule.starExportedModules) {
this._collectAllExportsRecursive(astModuleExportInfo, starExportedModule);
}
}
}
/**
* For a given symbol (which was encountered in the specified sourceFile), this fetches the AstEntity that it
* refers to. For example, if a particular interface describes the return value of a function, this API can help
* us determine a TSDoc declaration reference for that symbol (if the symbol is exported).
*/
fetchReferencedAstEntity(symbol, referringModuleIsExternal) {
// eslint-disable-next-line no-bitwise
if ((symbol.flags & ts.SymbolFlags.FunctionScopedVariable) !== 0) {
// If a symbol refers back to part of its own definition, don't follow that rabbit hole
// Example:
//
// function f(x: number): typeof x {
// return 123;
// }
return undefined;
}
let current = symbol;
if (referringModuleIsExternal) {
current = TypeScriptHelpers_1.TypeScriptHelpers.followAliases(symbol, this._typeChecker);
}
else {
for (;;) {
// Is this symbol an import/export that we need to follow to find the real declaration?
for (const declaration of current.declarations || []) {
let matchedAstEntity;
matchedAstEntity = this._tryMatchExportDeclaration(declaration, current);
if (matchedAstEntity !== undefined) {
return matchedAstEntity;
}
matchedAstEntity = this._tryMatchImportDeclaration(declaration, current);
if (matchedAstEntity !== undefined) {
return matchedAstEntity;
}
}
// eslint-disable-next-line no-bitwise
if (!(current.flags & ts.SymbolFlags.Alias)) {
break;
}
const currentAlias = TypeScriptInternals_1.TypeScriptInternals.getImmediateAliasedSymbol(current, this._typeChecker);
// Stop if we reach the end of the chain
if (!currentAlias || currentAlias === current) {
break;
}
current = currentAlias;
}
}
// Otherwise, assume it is a normal declaration
const astSymbol = this._astSymbolTable.fetchAstSymbol({
followedSymbol: current,
isExternal: referringModuleIsExternal,
includeNominalAnalysis: false,
addIfMissing: true
});
return astSymbol;
}
fetchReferencedAstEntityFromImportTypeNode(node, referringModuleIsExternal) {
const externalModulePath = this._tryGetExternalModulePath(node);
if (externalModulePath) {
let exportName;
if (node.qualifier) {
// Example input:
// import('api-extractor-lib1-test').Lib1GenericType<number>
//
// Extracted qualifier:
// Lib1GenericType
exportName = node.qualifier.getText().trim();
}
else {
// Example input:
// import('api-extractor-lib1-test')
//
// Extracted qualifier:
// apiExtractorLib1Test
exportName = SyntaxHelpers_1.SyntaxHelpers.makeCamelCaseIdentifier(externalModulePath);
}
return this._fetchAstImport(undefined, {
importKind: AstImport_1.AstImportKind.ImportType,
exportName: exportName,
modulePath: externalModulePath,
isTypeOnly: false
});
}
// Internal reference: AstSymbol
const rightMostToken = node.qualifier
? node.qualifier.kind === ts.SyntaxKind.QualifiedName
? node.qualifier.right
: node.qualifier
: node;
// There is no symbol property in a ImportTypeNode, obtain the associated export symbol
const exportSymbol = this._typeChecker.getSymbolAtLocation(rightMostToken);
if (!exportSymbol) {
throw new node_core_library_1.InternalError(`Symbol not found for identifier: ${node.getText()}\n` +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(node));
}
let followedSymbol = exportSymbol;
for (;;) {
const referencedAstEntity = this.fetchReferencedAstEntity(followedSymbol, referringModuleIsExternal);
if (referencedAstEntity) {
return referencedAstEntity;
}
const followedSymbolNode = followedSymbol.declarations && followedSymbol.declarations[0];
if (followedSymbolNode && followedSymbolNode.kind === ts.SyntaxKind.ImportType) {
return this.fetchReferencedAstEntityFromImportTypeNode(followedSymbolNode, referringModuleIsExternal);
}
// eslint-disable-next-line no-bitwise
if (!(followedSymbol.flags & ts.SymbolFlags.Alias)) {
break;
}
const currentAlias = this._typeChecker.getAliasedSymbol(followedSymbol);
if (!currentAlias || currentAlias === followedSymbol) {
break;
}
followedSymbol = currentAlias;
}
const astSymbol = this._astSymbolTable.fetchAstSymbol({
followedSymbol: followedSymbol,
isExternal: referringModuleIsExternal,
includeNominalAnalysis: false,
addIfMissing: true
});
return astSymbol;
}
_tryMatchExportDeclaration(declaration, declarationSymbol) {
const exportDeclaration = TypeScriptHelpers_1.TypeScriptHelpers.findFirstParent(declaration, ts.SyntaxKind.ExportDeclaration);
if (exportDeclaration) {
let exportName = undefined;
if (declaration.kind === ts.SyntaxKind.ExportSpecifier) {
// EXAMPLE:
// "export { A } from './file-a';"
//
// ExportDeclaration:
// ExportKeyword: pre=[export] sep=[ ]
// NamedExports:
// FirstPunctuation: pre=[{] sep=[ ]
// SyntaxList:
// ExportSpecifier: <------------- declaration
// Identifier: pre=[A] sep=[ ]
// CloseBraceToken: pre=[}] sep=[ ]
// FromKeyword: pre=[from] sep=[ ]
// StringLiteral: pre=['./file-a']
// SemicolonToken: pre=[;]
// Example: " ExportName as RenamedName"
const exportSpecifier = declaration;
exportName = (exportSpecifier.propertyName || exportSpecifier.name).getText().trim();
}
else if (declaration.kind === ts.SyntaxKind.NamespaceExport) {
// EXAMPLE:
// "export * as theLib from 'the-lib';"
//
// ExportDeclaration:
// ExportKeyword: pre=[export] sep=[ ]
// NamespaceExport:
// AsteriskToken: pre=[*] sep=[ ]
// AsKeyword: pre=[as] sep=[ ]
// Identifier: pre=[theLib] sep=[ ]
// FromKeyword: pre=[from] sep=[ ]
// StringLiteral: pre=['the-lib']
// SemicolonToken: pre=[;]
// Issue tracking this feature: https://github.com/microsoft/rushstack/issues/2780
const astModule = this._fetchSpecifierAstModule(exportDeclaration, declarationSymbol);
return this._getAstNamespaceExport(astModule, declarationSymbol, declaration);
}
else {
throw new node_core_library_1.InternalError(`Unimplemented export declaration kind: ${declaration.getText()}\n` +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(declaration));
}
// Ignore "export { A }" without a module specifier
if (exportDeclaration.moduleSpecifier) {
const externalModulePath = this._tryGetExternalModulePath(exportDeclaration);
if (externalModulePath !== undefined) {
return this._fetchAstImport(declarationSymbol, {
importKind: AstImport_1.AstImportKind.NamedImport,
modulePath: externalModulePath,
exportName: exportName,
isTypeOnly: false
});
}
return this._getExportOfSpecifierAstModule(exportName, exportDeclaration, declarationSymbol);
}
}
return undefined;
}
_getAstNamespaceExport(astModule, declarationSymbol, declaration) {
const imoprtNamespace = this._getAstNamespaceImport(astModule, declarationSymbol, declaration);
return new AstNamespaceExport_1.AstNamespaceExport({
namespaceName: imoprtNamespace.localName,
astModule: astModule,
declaration,
symbol: declarationSymbol
});
}
_tryMatchImportDeclaration(declaration, declarationSymbol) {
const importDeclaration = TypeScriptHelpers_1.TypeScriptHelpers.findFirstParent(declaration, ts.SyntaxKind.ImportDeclaration);
if (importDeclaration) {
const externalModulePath = this._tryGetExternalModulePath(importDeclaration);
if (declaration.kind === ts.SyntaxKind.NamespaceImport) {
// EXAMPLE:
// "import * as theLib from 'the-lib';"
//
// ImportDeclaration:
// ImportKeyword: pre=[import] sep=[ ]
// ImportClause:
// NamespaceImport: <------------- declaration
// AsteriskToken: pre=[*] sep=[ ]
// AsKeyword: pre=[as] sep=[ ]
// Identifier: pre=[theLib] sep=[ ]
// FromKeyword: pre=[from] sep=[ ]
// StringLiteral: pre=['the-lib']
// SemicolonToken: pre=[;]
if (externalModulePath === undefined) {
const astModule = this._fetchSpecifierAstModule(importDeclaration, declarationSymbol);
return this._getAstNamespaceImport(astModule, declarationSymbol, declaration);
}
// Here importSymbol=undefined because {@inheritDoc} and such are not going to work correctly for
// a package or source file.
return this._fetchAstImport(undefined, {
importKind: AstImport_1.AstImportKind.StarImport,
exportName: declarationSymbol.name,
modulePath: externalModulePath,
isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)
});
}
if (declaration.kind === ts.SyntaxKind.ImportSpecifier) {
// EXAMPLE:
// "import { A, B } from 'the-lib';"
//
// ImportDeclaration:
// ImportKeyword: pre=[import] sep=[ ]
// ImportClause:
// NamedImports:
// FirstPunctuation: pre=[{] sep=[ ]
// SyntaxList:
// ImportSpecifier: <------------- declaration
// Identifier: pre=[A]
// CommaToken: pre=[,] sep=[ ]
// ImportSpecifier:
// Identifier: pre=[B] sep=[ ]
// CloseBraceToken: pre=[}] sep=[ ]
// FromKeyword: pre=[from] sep=[ ]
// StringLiteral: pre=['the-lib']
// SemicolonToken: pre=[;]
// Example: " ExportName as RenamedName"
const importSpecifier = declaration;
const exportName = (importSpecifier.propertyName || importSpecifier.name).getText().trim();
if (externalModulePath !== undefined) {
return this._fetchAstImport(declarationSymbol, {
importKind: AstImport_1.AstImportKind.NamedImport,
modulePath: externalModulePath,
exportName: exportName,
isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)
});
}
return this._getExportOfSpecifierAstModule(exportName, importDeclaration, declarationSymbol);
}
else if (declaration.kind === ts.SyntaxKind.ImportClause) {
// EXAMPLE:
// "import A, { B } from './A';"
//
// ImportDeclaration:
// ImportKeyword: pre=[import] sep=[ ]
// ImportClause: <------------- declaration (referring to A)
// Identifier: pre=[A]
// CommaToken: pre=[,] sep=[ ]
// NamedImports:
// FirstPunctuation: pre=[{] sep=[ ]
// SyntaxList:
// ImportSpecifier:
// Identifier: pre=[B] sep=[ ]
// CloseBraceToken: pre=[}] sep=[ ]
// FromKeyword: pre=[from] sep=[ ]
// StringLiteral: pre=['./A']
// SemicolonToken: pre=[;]
const importClause = declaration;
const exportName = importClause.name
? importClause.name.getText().trim()
: ts.InternalSymbolName.Default;
if (externalModulePath !== undefined) {
return this._fetchAstImport(declarationSymbol, {
importKind: AstImport_1.AstImportKind.DefaultImport,
modulePath: externalModulePath,
exportName,
isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)
});
}
return this._getExportOfSpecifierAstModule(ts.InternalSymbolName.Default, importDeclaration, declarationSymbol);
}
else {
throw new node_core_library_1.InternalError(`Unimplemented import declaration kind: ${declaration.getText()}\n` +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(declaration));
}
}
if (ts.isImportEqualsDeclaration(declaration)) {
// EXAMPLE:
// import myLib = require('my-lib');
//
// ImportEqualsDeclaration:
// ImportKeyword: pre=[import] sep=[ ]
// Identifier: pre=[myLib] sep=[ ]
// FirstAssignment: pre=[=] sep=[ ]
// ExternalModuleReference:
// RequireKeyword: pre=[require]
// OpenParenToken: pre=[(]
// StringLiteral: pre=['my-lib']
// CloseParenToken: pre=[)]
// SemicolonToken: pre=[;]
if (ts.isExternalModuleReference(declaration.moduleReference)) {
if (ts.isStringLiteralLike(declaration.moduleReference.expression)) {
const variableName = TypeScriptInternals_1.TypeScriptInternals.getTextOfIdentifierOrLiteral(declaration.name);
const externalModuleName = TypeScriptInternals_1.TypeScriptInternals.getTextOfIdentifierOrLiteral(declaration.moduleReference.expression);
return this._fetchAstImport(declarationSymbol, {
importKind: AstImport_1.AstImportKind.EqualsImport,
modulePath: externalModuleName,
exportName: variableName,
isTypeOnly: false
});
}
}
}
return undefined;
}
_getAstNamespaceImport(astModule, declarationSymbol, declaration) {
let namespaceImport = this._astNamespaceImportByModule.get(astModule);
if (namespaceImport === undefined) {
namespaceImport = new AstNamespaceImport_1.AstNamespaceImport({
namespaceName: declarationSymbol.name,
astModule: astModule,
declaration: declaration,
symbol: declarationSymbol
});
this._astNamespaceImportByModule.set(astModule, namespaceImport);
}
return namespaceImport;
}
static _getIsTypeOnly(importDeclaration) {
if (importDeclaration.importClause) {
return !!importDeclaration.importClause.isTypeOnly;
}
return false;
}
_getExportOfSpecifierAstModule(exportName, importOrExportDeclaration, exportSymbol) {
const specifierAstModule = this._fetchSpecifierAstModule(importOrExportDeclaration, exportSymbol);
const astEntity = this._getExportOfAstModule(exportName, specifierAstModule);
return astEntity;
}
_getExportOfAstModule(exportName, astModule) {
const visitedAstModules = new Set();
const astEntity = this._tryGetExportOfAstModule(exportName, astModule, visitedAstModules);
if (astEntity === undefined) {
throw new node_core_library_1.InternalError(`Unable to analyze the export ${JSON.stringify(exportName)} in\n` + astModule.sourceFile.fileName);
}
return astEntity;
}
/**
* Implementation of {@link AstSymbolTable.tryGetExportOfAstModule}.
*/
tryGetExportOfAstModule(exportName, astModule) {
const visitedAstModules = new Set();
return this._tryGetExportOfAstModule(exportName, astModule, visitedAstModules);
}
_tryGetExportOfAstModule(exportName, astModule, visitedAstModules) {
if (visitedAstModules.has(astModule)) {
return undefined;
}
visitedAstModules.add(astModule);
let astEntity = astModule.cachedExportedEntities.get(exportName);
if (astEntity !== undefined) {
return astEntity;
}
// Try the explicit exports
const escapedExportName = ts.escapeLeadingUnderscores(exportName);
if (astModule.moduleSymbol.exports) {
const exportSymbol = astModule.moduleSymbol.exports.get(escapedExportName);
if (exportSymbol) {
astEntity = this.fetchReferencedAstEntity(exportSymbol, astModule.isExternal);
if (astEntity !== undefined) {
astModule.cachedExportedEntities.set(exportName, astEntity); // cache for next time
return astEntity;
}
}
}
// Try each of the star imports
for (const starExportedModule of astModule.starExportedModules) {
astEntity = this._tryGetExportOfAstModule(exportName, starExportedModule, visitedAstModules);
if (astEntity !== undefined) {
if (starExportedModule.externalModulePath !== undefined) {
// This entity was obtained from an external module, so return an AstImport instead
const astSymbol = astEntity;
return this._fetchAstImport(astSymbol.followedSymbol, {
importKind: AstImport_1.AstImportKind.NamedImport,
modulePath: starExportedModule.externalModulePath,
exportName: exportName,
isTypeOnly: false
});
}
return astEntity;
}
}
return undefined;
}
_tryGetExternalModulePath(importOrExportDeclaration) {
const moduleSpecifier = this._getModuleSpecifier(importOrExportDeclaration);
if (this._isExternalModulePath(importOrExportDeclaration, moduleSpecifier)) {
return moduleSpecifier;
}
return undefined;
}
/**
* Given an ImportDeclaration of the form `export { X } from "___";`, this interprets the module specifier (`"___"`)
* and fetches the corresponding AstModule object.
*/
_fetchSpecifierAstModule(importOrExportDeclaration, exportSymbol) {
const moduleSpecifier = this._getModuleSpecifier(importOrExportDeclaration);
const mode = importOrExportDeclaration.moduleSpecifier &&
ts.isStringLiteralLike(importOrExportDeclaration.moduleSpecifier)
? TypeScriptInternals_1.TypeScriptInternals.getModeForUsageLocation(importOrExportDeclaration.getSourceFile(), importOrExportDeclaration.moduleSpecifier, this._program.getCompilerOptions())
: undefined;
const resolvedModule = TypeScriptInternals_1.TypeScriptInternals.getResolvedModule(this._program, importOrExportDeclaration.getSourceFile(), moduleSpecifier, mode);
if (resolvedModule === undefined) {
// Encountered in https://github.com/microsoft/rushstack/issues/1914.
//
// It's also possible for this to occur with ambient modules. However, in practice this doesn't happen
// as API Extractor treats all ambient modules as external per the logic in `_isExternalModulePath`, and
// thus this code path is never reached for ambient modules.
throw new node_core_library_1.InternalError(`getResolvedModule() could not resolve module name ${JSON.stringify(moduleSpecifier)}\n` +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration));
}
// Map the filename back to the corresponding SourceFile. This circuitous approach is needed because
// we have no way to access the compiler's internal resolveExternalModuleName() function
const moduleSourceFile = this._program.getSourceFile(resolvedModule.resolvedFileName);
if (!moduleSourceFile) {
// This should not happen, since getResolvedModule() specifically looks up names that the compiler
// found in export declarations for this source file
throw new node_core_library_1.InternalError(`getSourceFile() failed to locate ${JSON.stringify(resolvedModule.resolvedFileName)}\n` +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration));
}
const isExternal = this._isExternalModulePath(importOrExportDeclaration, moduleSpecifier);
const moduleReference = {
moduleSpecifier: moduleSpecifier,
moduleSpecifierSymbol: exportSymbol
};
const specifierAstModule = this.fetchAstModuleFromSourceFile(moduleSourceFile, moduleReference, isExternal);
return specifierAstModule;
}
_fetchAstImport(importSymbol, options) {
const key = AstImport_1.AstImport.getKey(options);
let astImport = this._astImportsByKey.get(key);
if (!astImport) {
astImport = new AstImport_1.AstImport(options);
this._astImportsByKey.set(key, astImport);
if (importSymbol) {
const followedSymbol = TypeScriptHelpers_1.TypeScriptHelpers.followAliases(importSymbol, this._typeChecker);
astImport.astSymbol = this._astSymbolTable.fetchAstSymbol({
followedSymbol: followedSymbol,
isExternal: true,
includeNominalAnalysis: false,
addIfMissing: true
});
}
}
else {
// If we encounter at least one import that does not use the type-only form,
// then the .d.ts rollup will NOT use "import type".
if (!options.isTypeOnly) {
astImport.isTypeOnlyEverywhere = false;
}
}
return astImport;
}
_getModuleSpecifier(importOrExportDeclaration) {
// The name of the module, which could be like "./SomeLocalFile' or like 'external-package/entry/point'
const moduleSpecifier = TypeScriptHelpers_1.TypeScriptHelpers.getModuleSpecifier(importOrExportDeclaration);
if (!moduleSpecifier) {
throw new node_core_library_1.InternalError('Unable to parse module specifier\n' +
SourceFileLocationFormatter_1.SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration));
}
return moduleSpecifier;
}
}
exports.ExportAnalyzer = ExportAnalyzer;
//# sourceMappingURL=ExportAnalyzer.js.map
\ No newline at end of file
{"version":3,"file":"ExportAnalyzer.js","sourceRoot":"","sources":["../../src/analyzer/ExportAnalyzer.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+CAAiC;AAEjC,oEAA6D;AAE7D,2DAAwD;AACxD,2CAAwC;AACxC,2CAA+E;AAC/E,2CAAmE;AACnE,+DAA4D;AAC5D,+EAA4E;AAG5E,6DAA0D;AAC1D,mDAAgD;AAChD,6DAA0D;AAgC1D;;;;;;;;;GASG;AACH,MAAa,cAAc;IAczB,YACE,OAAmB,EACnB,WAA2B,EAC3B,mBAAwC,EACxC,cAA+B;QAZhB,8BAAyB,GAA8B,IAAI,GAAG,EAAwB,CAAC;QAExG,4CAA4C;QAC3B,kCAA6B,GAAuB,IAAI,GAAG,EAAiB,CAAC;QAE7E,qBAAgB,GAA2B,IAAI,GAAG,EAAqB,CAAC;QACxE,gCAA2B,GAAuC,IAAI,GAAG,EAAE,CAAC;QAQ3F,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;QAChD,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACI,4BAA4B,CACjC,UAAyB,EACzB,eAAgD,EAChD,UAAmB;QAEnB,MAAM,YAAY,GAAc,IAAI,CAAC,8BAA8B,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QAEjG,iEAAiE;QACjE,gFAAgF;QAChF,oDAAoD;QACpD,IAAI,SAAS,GAA0B,IAAI,C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,GAAG,CAAC,CAAC;QAEtE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS,GAAG,IAAI,qBAAS,CAAC,OAAO,CAAC,CAAC;YACnC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAE1C,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,cAAc,GAAc,qCAAiB,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;gBAEnG,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC;oBACxD,cAAc,EAAE,cAAc;oBAC9B,UAAU,EAAE,IAAI;oBAChB,sBAAsB,EAAE,KAAK;oBAC7B,YAAY,EAAE,IAAI;iBACnB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;aAAM,CAAC;YACN,4EAA4E;YAC5E,oDAAoD;YACpD,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;gBACxB,SAAS,CAAC,oBAAoB,GAAG,KAAK,CAAC;YACzC,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,mBAAmB,CACzB,yBAA0F;QAE1F,uGAAuG;QACvG,MAAM,eAAe,GACnB,qCAAiB,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;QAElE,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,iCAAa,CACrB,oCAAoC;gBAClC,yDAA2B,CAAC,iBAAiB,CAAC,yBAAyB,CAAC,CAC3E,CAAC;QACJ,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AA17BD,wCA07BC","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 { InternalError } from '@rushstack/node-core-library';\n\nimport { TypeScriptHelpers } from './TypeScriptHelpers';\nimport { AstSymbol } from './AstSymbol';\nimport { AstImport, type IAstImportOptions, AstImportKind } from './AstImport';\nimport { AstModule, type IAstModuleExportInfo } from './AstModule';\nimport { TypeScriptInternals } from './TypeScriptInternals';\nimport { SourceFileLocationFormatter } from './SourceFileLocationFormatter';\nimport type { IFetchAstSymbolOptions } from './AstSymbolTable';\nimport type { AstEntity } from './AstEntity';\nimport { AstNamespaceImport } from './AstNamespaceImport';\nimport { SyntaxHelpers } from './SyntaxHelpers';\nimport { AstNamespaceExport } from './AstNamespaceExport';\n\n/**\n * Exposes the minimal APIs from AstSymbolTable that are needed by ExportAnalyzer.\n *\n * In particular, we want ExportAnalyzer to be able to call AstSymbolTable._fetchAstSymbol() even though it\n * is a very private API that should not be exposed to any other components.\n */\nexport interface IAstSymbolTable {\n fetchAstSymbol(options: IFetchAstSymbolOptions): AstSymbol | undefined;\n\n analyze(astEntity: AstEntity): void;\n}\n\n/**\n * Used with ExportAnalyzer.fetchAstModuleBySourceFile() to provide contextual information about how the source file\n * was imported.\n */\ninterface IAstModuleReference {\n /**\n * For example, if we are following a statement like `import { X } from 'some-package'`, this will be the\n * string `\"some-package\"`.\n */\n moduleSpecifier: string;\n\n /**\n * For example, if we are following a statement like `import { X } from 'some-package'`, this will be the\n * symbol for `X`.\n */\n moduleSpecifierSymbol: ts.Symbol;\n}\n\n/**\n * The ExportAnalyzer is an internal part of AstSymbolTable that has been moved out into its own source file\n * because it is a complex and mostly self-contained algorithm.\n *\n * Its job is to build up AstModule objects by crawling import statements to discover where declarations come from.\n * This is conceptually the same as the compiler's own TypeChecker.getExportsOfModule(), except that when\n * ExportAnalyzer encounters a declaration that was imported from an external package, it remembers how it was imported\n * (i.e. the AstImport object). Today the compiler API does not expose this information, which is crucial for\n * generating .d.ts rollups.\n */\nexport class ExportAnalyzer {\n private readonly _program: ts.Program;\n private readonly _typeChecker: ts.TypeChecker;\n private readonly _bundledPackageNames: ReadonlySet<string>;\n private readonly _astSymbolTable: IAstSymbolTable;\n\n private readonly _astModulesByModuleSymbol: Map<ts.Symbol, AstModule> = new Map<ts.Symbol, AstModule>();\n\n // Used with isImportableAmbientSourceFile()\n private readonly _importableAmbientSourceFiles: Set<ts.SourceFile> = new Set<ts.SourceFile>();\n\n private readonly _astImportsByKey: Map<string, AstImport> = new Map<string, AstImport>();\n private readonly _astNamespaceImportByModule: Map<AstModule, AstNamespaceImport> = new Map();\n\n public constructor(\n program: ts.Program,\n typeChecker: ts.TypeChecker,\n bundledPackageNames: ReadonlySet<string>,\n astSymbolTable: IAstSymbolTable\n ) {\n this._program = program;\n this._typeChecker = typeChecker;\n this._bundledPackageNames = bundledPackageNames;\n this._astSymbolTable = astSymbolTable;\n }\n\n /**\n * For a given source file, this analyzes all of its exports and produces an AstModule object.\n *\n * @param moduleReference - contextual information about the import statement that took us to this source file.\n * or `undefined` if this source file is the initial entry point\n * @param isExternal - whether the given `moduleReference` is external.\n */\n public fetchAstModuleFromSourceFile(\n sourceFile: ts.SourceFile,\n moduleReference: IAstModuleReference | undefined,\n isExternal: boolean\n ): AstModule {\n const moduleSymbol: ts.Symbol = this._getModuleSymbolFromSourceFile(sourceFile, moduleReference);\n\n // Don't traverse into a module that we already processed before:\n // The compiler allows m1 to have \"export * from 'm2'\" and \"export * from 'm3'\",\n // even if m2 and m3 both have \"export * from 'm4'\".\n let astModule: AstModule | undefined = this._astModulesByModuleSymbol.get(moduleSymbol);\n if (!astModule) {\n // (If moduleReference === undefined, then this is the entry point of the local project being analyzed.)\n const externalModulePath: string | undefined =\n moduleReference !== undefined && isExternal ? moduleReference.moduleSpecifier : undefined;\n\n astModule = new AstModule({ sourceFile, moduleSymbol, externalModulePath });\n\n this._astModulesByModuleSymbol.set(moduleSymbol, astModule);\n\n if (astModule.isExternal) {\n // It's an external package, so do the special simplified analysis that doesn't crawl into referenced modules\n for (const exportedSymbol of this._typeChecker.getExportsOfModule(moduleSymbol)) {\n if (externalModulePath === undefined) {\n throw new InternalError(\n 'Failed assertion: externalModulePath=undefined but astModule.isExternal=true'\n );\n }\n\n const followedSymbol: ts.Symbol = TypeScriptHelpers.followAliases(\n exportedSymbol,\n this._typeChecker\n );\n\n // Ignore virtual symbols that don't have any declarations\n const arbitraryDeclaration: ts.Declaration | undefined =\n TypeScriptHelpers.tryGetADeclaration(followedSymbol);\n if (arbitraryDeclaration) {\n const astSymbol: AstSymbol | undefined = this._astSymbolTable.fetchAstSymbol({\n followedSymbol: followedSymbol,\n isExternal: astModule.isExternal,\n includeNominalAnalysis: true,\n addIfMissing: true\n });\n\n if (!astSymbol) {\n throw new Error(\n `Unsupported export ${JSON.stringify(exportedSymbol.name)}:\\n` +\n SourceFileLocationFormatter.formatDeclaration(arbitraryDeclaration)\n );\n }\n\n astModule.cachedExportedEntities.set(exportedSymbol.name, astSymbol);\n }\n }\n } else {\n // The module is part of the local project, so do the full analysis\n\n if (moduleSymbol.exports) {\n // The \"export * from 'module-name';\" declarations are all attached to a single virtual symbol\n // whose name is InternalSymbolName.ExportStar\n const exportStarSymbol: ts.Symbol | undefined = moduleSymbol.exports.get(\n ts.InternalSymbolName.ExportStar\n );\n if (exportStarSymbol) {\n for (const exportStarDeclaration of exportStarSymbol.getDeclarations() || []) {\n if (ts.isExportDeclaration(exportStarDeclaration)) {\n const starExportedModule: AstModule | undefined = this._fetchSpecifierAstModule(\n exportStarDeclaration,\n exportStarSymbol\n );\n\n if (starExportedModule !== undefined) {\n astModule.starExportedModules.add(starExportedModule);\n }\n } else {\n // Ignore ExportDeclaration nodes that don't match the expected pattern\n // TODO: Should we report a warning?\n }\n }\n }\n }\n }\n }\n\n return astModule;\n }\n\n /**\n * Retrieves the symbol for the module corresponding to the ts.SourceFile that is being imported/exported.\n *\n * @remarks\n * The `module` keyword can be used to declare multiple TypeScript modules inside a single source file.\n * (This is a deprecated construct and mainly used for typings such as `@types/node`.) In this situation,\n * `moduleReference` helps us to fish out the correct module symbol.\n */\n private _getModuleSymbolFromSourceFile(\n sourceFile: ts.SourceFile,\n moduleReference: IAstModuleReference | undefined\n ): ts.Symbol {\n const moduleSymbol: ts.Symbol | undefined = TypeScriptInternals.tryGetSymbolForDeclaration(\n sourceFile,\n this._typeChecker\n );\n if (moduleSymbol !== undefined) {\n // This is the normal case. The SourceFile acts is a module and has a symbol.\n return moduleSymbol;\n }\n\n if (moduleReference !== undefined) {\n // But there is also an elaborate case where the source file contains one or more \"module\" declarations,\n // and our moduleReference took us to one of those.\n\n // eslint-disable-next-line no-bitwise\n if ((moduleReference.moduleSpecifierSymbol.flags & ts.SymbolFlags.Alias) !== 0) {\n // Follow the import/export declaration to one hop the exported item inside the target module\n let followedSymbol: ts.Symbol | undefined = TypeScriptInternals.getImmediateAliasedSymbol(\n moduleReference.moduleSpecifierSymbol,\n this._typeChecker\n );\n\n if (followedSymbol === undefined) {\n // This is a workaround for a compiler bug where getImmediateAliasedSymbol() sometimes returns undefined\n followedSymbol = this._typeChecker.getAliasedSymbol(moduleReference.moduleSpecifierSymbol);\n }\n\n if (followedSymbol !== undefined && followedSymbol !== moduleReference.moduleSpecifierSymbol) {\n // The parent of the exported symbol will be the module that we're importing from\n const parent: ts.Symbol | undefined = TypeScriptInternals.getSymbolParent(followedSymbol);\n if (parent !== undefined) {\n // Make sure the thing we found is a module\n // eslint-disable-next-line no-bitwise\n if ((parent.flags & ts.SymbolFlags.ValueModule) !== 0) {\n // Record that that this is an ambient module that can also be imported from\n this._importableAmbientSourceFiles.add(sourceFile);\n return parent;\n }\n }\n }\n }\n }\n\n throw new InternalError('Unable to determine module for: ' + sourceFile.fileName);\n }\n\n /**\n * Implementation of {@link AstSymbolTable.fetchAstModuleExportInfo}.\n */\n public fetchAstModuleExportInfo(entryPointAstModule: AstModule): IAstModuleExportInfo {\n if (entryPointAstModule.isExternal) {\n throw new Error('fetchAstModuleExportInfo() is not supported for external modules');\n }\n\n if (entryPointAstModule.astModuleExportInfo === undefined) {\n const astModuleExportInfo: IAstModuleExportInfo = {\n visitedAstModules: new Set<AstModule>(),\n exportedLocalEntities: new Map<string, AstEntity>(),\n starExportedExternalModules: new Set<AstModule>()\n };\n\n this._collectAllExportsRecursive(astModuleExportInfo, entryPointAstModule);\n\n entryPointAstModule.astModuleExportInfo = astModuleExportInfo;\n }\n return entryPointAstModule.astModuleExportInfo;\n }\n\n /**\n * Returns true if the module specifier refers to an external package. Ignores packages listed in the\n * \"bundledPackages\" setting from the api-extractor.json config file.\n */\n private _isExternalModulePath(\n importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration | ts.ImportTypeNode,\n moduleSpecifier: string\n ): boolean {\n let specifier: ts.TypeNode | ts.Expression | undefined = ts.isImportTypeNode(importOrExportDeclaration)\n ? importOrExportDeclaration.argument\n : importOrExportDeclaration.moduleSpecifier;\n if (specifier && ts.isLiteralTypeNode(specifier)) {\n specifier = specifier.literal;\n }\n const mode: ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined =\n specifier && ts.isStringLiteralLike(specifier)\n ? TypeScriptInternals.getModeForUsageLocation(\n importOrExportDeclaration.getSourceFile(),\n specifier,\n this._program.getCompilerOptions()\n )\n : undefined;\n\n const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(\n this._program,\n importOrExportDeclaration.getSourceFile(),\n moduleSpecifier,\n mode\n );\n\n if (resolvedModule === undefined) {\n // The TS compiler API `getResolvedModule` cannot resolve ambient modules. Thus, to match API Extractor's\n // previous behavior, simply treat all ambient modules as external. This bug is tracked by\n // https://github.com/microsoft/rushstack/issues/3335.\n return true;\n }\n\n // Either something like `jquery` or `@microsoft/api-extractor`.\n const packageName: string | undefined = resolvedModule.packageId?.name;\n if (packageName !== undefined && this._bundledPackageNames.has(packageName)) {\n return false;\n }\n\n if (resolvedModule.isExternalLibraryImport === undefined) {\n // This presumably means the compiler couldn't figure out whether the module was external, but we're not\n // sure how this can happen.\n throw new InternalError(\n `Cannot determine whether the module ${JSON.stringify(moduleSpecifier)} is external\\n` +\n SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration)\n );\n }\n\n return resolvedModule.isExternalLibraryImport;\n }\n\n /**\n * Returns true if when we analyzed sourceFile, we found that it contains an \"export=\" statement that allows\n * it to behave /either/ as an ambient module /or/ as a regular importable module. In this case,\n * `AstSymbolTable._fetchAstSymbol()` will analyze its symbols even though `TypeScriptHelpers.isAmbient()`\n * returns true.\n */\n public isImportableAmbientSourceFile(sourceFile: ts.SourceFile): boolean {\n return this._importableAmbientSourceFiles.has(sourceFile);\n }\n\n private _collectAllExportsRecursive(astModuleExportInfo: IAstModuleExportInfo, astModule: AstModule): void {\n const { visitedAstModules, starExportedExternalModules, exportedLocalEntities } = astModuleExportInfo;\n if (visitedAstModules.has(astModule)) {\n return;\n }\n visitedAstModules.add(astModule);\n\n if (astModule.isExternal) {\n starExportedExternalModules.add(astModule);\n } else {\n // Fetch each of the explicit exports for this module\n if (astModule.moduleSymbol.exports) {\n astModule.moduleSymbol.exports.forEach((exportSymbol, exportName) => {\n switch (exportName) {\n case ts.InternalSymbolName.ExportStar:\n case ts.InternalSymbolName.ExportEquals:\n break;\n default:\n // Don't collect the \"export default\" symbol unless this is the entry point module\n if (exportName !== ts.InternalSymbolName.Default || visitedAstModules.size === 1) {\n if (!exportedLocalEntities.has(exportSymbol.name)) {\n const astEntity: AstEntity = this._getExportOfAstModule(exportSymbol.name, astModule);\n\n if (astEntity instanceof AstSymbol && !astEntity.isExternal) {\n this._astSymbolTable.analyze(astEntity);\n }\n\n if (astEntity instanceof AstNamespaceImport && !astEntity.astModule.isExternal) {\n this._astSymbolTable.analyze(astEntity);\n }\n\n exportedLocalEntities.set(exportSymbol.name, astEntity);\n }\n }\n break;\n }\n });\n }\n\n for (const starExportedModule of astModule.starExportedModules) {\n this._collectAllExportsRecursive(astModuleExportInfo, starExportedModule);\n }\n }\n }\n\n /**\n * For a given symbol (which was encountered in the specified sourceFile), this fetches the AstEntity that it\n * refers to. For example, if a particular interface describes the return value of a function, this API can help\n * us determine a TSDoc declaration reference for that symbol (if the symbol is exported).\n */\n public fetchReferencedAstEntity(\n symbol: ts.Symbol,\n referringModuleIsExternal: boolean\n ): AstEntity | undefined {\n // eslint-disable-next-line no-bitwise\n if ((symbol.flags & ts.SymbolFlags.FunctionScopedVariable) !== 0) {\n // If a symbol refers back to part of its own definition, don't follow that rabbit hole\n // Example:\n //\n // function f(x: number): typeof x {\n // return 123;\n // }\n return undefined;\n }\n\n let current: ts.Symbol = symbol;\n\n if (referringModuleIsExternal) {\n current = TypeScriptHelpers.followAliases(symbol, this._typeChecker);\n } else {\n for (;;) {\n // Is this symbol an import/export that we need to follow to find the real declaration?\n for (const declaration of current.declarations || []) {\n let matchedAstEntity: AstEntity | undefined;\n matchedAstEntity = this._tryMatchExportDeclaration(declaration, current);\n if (matchedAstEntity !== undefined) {\n return matchedAstEntity;\n }\n matchedAstEntity = this._tryMatchImportDeclaration(declaration, current);\n if (matchedAstEntity !== undefined) {\n return matchedAstEntity;\n }\n }\n\n // eslint-disable-next-line no-bitwise\n if (!(current.flags & ts.SymbolFlags.Alias)) {\n break;\n }\n\n const currentAlias: ts.Symbol = TypeScriptInternals.getImmediateAliasedSymbol(\n current,\n this._typeChecker\n );\n // Stop if we reach the end of the chain\n if (!currentAlias || currentAlias === current) {\n break;\n }\n\n current = currentAlias;\n }\n }\n\n // Otherwise, assume it is a normal declaration\n const astSymbol: AstSymbol | undefined = this._astSymbolTable.fetchAstSymbol({\n followedSymbol: current,\n isExternal: referringModuleIsExternal,\n includeNominalAnalysis: false,\n addIfMissing: true\n });\n\n return astSymbol;\n }\n\n public fetchReferencedAstEntityFromImportTypeNode(\n node: ts.ImportTypeNode,\n referringModuleIsExternal: boolean\n ): AstEntity | undefined {\n const externalModulePath: string | undefined = this._tryGetExternalModulePath(node);\n\n if (externalModulePath) {\n let exportName: string;\n if (node.qualifier) {\n // Example input:\n // import('api-extractor-lib1-test').Lib1GenericType<number>\n //\n // Extracted qualifier:\n // Lib1GenericType\n exportName = node.qualifier.getText().trim();\n } else {\n // Example input:\n // import('api-extractor-lib1-test')\n //\n // Extracted qualifier:\n // apiExtractorLib1Test\n\n exportName = SyntaxHelpers.makeCamelCaseIdentifier(externalModulePath);\n }\n\n return this._fetchAstImport(undefined, {\n importKind: AstImportKind.ImportType,\n exportName: exportName,\n modulePath: externalModulePath,\n isTypeOnly: false\n });\n }\n\n // Internal reference: AstSymbol\n const rightMostToken: ts.Identifier | ts.ImportTypeNode = node.qualifier\n ? node.qualifier.kind === ts.SyntaxKind.QualifiedName\n ? node.qualifier.right\n : node.qualifier\n : node;\n\n // There is no symbol property in a ImportTypeNode, obtain the associated export symbol\n const exportSymbol: ts.Symbol | undefined = this._typeChecker.getSymbolAtLocation(rightMostToken);\n if (!exportSymbol) {\n throw new InternalError(\n `Symbol not found for identifier: ${node.getText()}\\n` +\n SourceFileLocationFormatter.formatDeclaration(node)\n );\n }\n\n let followedSymbol: ts.Symbol = exportSymbol;\n for (;;) {\n const referencedAstEntity: AstEntity | undefined = this.fetchReferencedAstEntity(\n followedSymbol,\n referringModuleIsExternal\n );\n\n if (referencedAstEntity) {\n return referencedAstEntity;\n }\n\n const followedSymbolNode: ts.Node | ts.ImportTypeNode | undefined =\n followedSymbol.declarations && (followedSymbol.declarations[0] as ts.Node | undefined);\n\n if (followedSymbolNode && followedSymbolNode.kind === ts.SyntaxKind.ImportType) {\n return this.fetchReferencedAstEntityFromImportTypeNode(\n followedSymbolNode as ts.ImportTypeNode,\n referringModuleIsExternal\n );\n }\n\n // eslint-disable-next-line no-bitwise\n if (!(followedSymbol.flags & ts.SymbolFlags.Alias)) {\n break;\n }\n\n const currentAlias: ts.Symbol = this._typeChecker.getAliasedSymbol(followedSymbol);\n if (!currentAlias || currentAlias === followedSymbol) {\n break;\n }\n\n followedSymbol = currentAlias;\n }\n\n const astSymbol: AstSymbol | undefined = this._astSymbolTable.fetchAstSymbol({\n followedSymbol: followedSymbol,\n isExternal: referringModuleIsExternal,\n includeNominalAnalysis: false,\n addIfMissing: true\n });\n\n return astSymbol;\n }\n\n private _tryMatchExportDeclaration(\n declaration: ts.Declaration,\n declarationSymbol: ts.Symbol\n ): AstEntity | undefined {\n const exportDeclaration: ts.ExportDeclaration | undefined =\n TypeScriptHelpers.findFirstParent<ts.ExportDeclaration>(declaration, ts.SyntaxKind.ExportDeclaration);\n\n if (exportDeclaration) {\n let exportName: string | undefined = undefined;\n\n if (declaration.kind === ts.SyntaxKind.ExportSpecifier) {\n // EXAMPLE:\n // \"export { A } from './file-a';\"\n //\n // ExportDeclaration:\n // ExportKeyword: pre=[export] sep=[ ]\n // NamedExports:\n // FirstPunctuation: pre=[{] sep=[ ]\n // SyntaxList:\n // ExportSpecifier: <------------- declaration\n // Identifier: pre=[A] sep=[ ]\n // CloseBraceToken: pre=[}] sep=[ ]\n // FromKeyword: pre=[from] sep=[ ]\n // StringLiteral: pre=['./file-a']\n // SemicolonToken: pre=[;]\n\n // Example: \" ExportName as RenamedName\"\n const exportSpecifier: ts.ExportSpecifier = declaration as ts.ExportSpecifier;\n exportName = (exportSpecifier.propertyName || exportSpecifier.name).getText().trim();\n } else if (declaration.kind === ts.SyntaxKind.NamespaceExport) {\n // EXAMPLE:\n // \"export * as theLib from 'the-lib';\"\n //\n // ExportDeclaration:\n // ExportKeyword: pre=[export] sep=[ ]\n // NamespaceExport:\n // AsteriskToken: pre=[*] sep=[ ]\n // AsKeyword: pre=[as] sep=[ ]\n // Identifier: pre=[theLib] sep=[ ]\n // FromKeyword: pre=[from] sep=[ ]\n // StringLiteral: pre=['the-lib']\n // SemicolonToken: pre=[;]\n\n // Issue tracking this feature: https://github.com/microsoft/rushstack/issues/2780\n\n const astModule: AstModule = this._fetchSpecifierAstModule(exportDeclaration, declarationSymbol);\n return this._getAstNamespaceExport(astModule, declarationSymbol, declaration);\n } else {\n throw new InternalError(\n `Unimplemented export declaration kind: ${declaration.getText()}\\n` +\n SourceFileLocationFormatter.formatDeclaration(declaration)\n );\n }\n\n // Ignore \"export { A }\" without a module specifier\n if (exportDeclaration.moduleSpecifier) {\n const externalModulePath: string | undefined = this._tryGetExternalModulePath(exportDeclaration);\n\n if (externalModulePath !== undefined) {\n return this._fetchAstImport(declarationSymbol, {\n importKind: AstImportKind.NamedImport,\n modulePath: externalModulePath,\n exportName: exportName,\n isTypeOnly: false\n });\n }\n\n return this._getExportOfSpecifierAstModule(exportName, exportDeclaration, declarationSymbol);\n }\n }\n\n return undefined;\n }\n\n private _getAstNamespaceExport(\n astModule: AstModule,\n declarationSymbol: ts.Symbol,\n declaration: ts.Declaration\n ): AstNamespaceExport {\n const imoprtNamespace: AstNamespaceImport = this._getAstNamespaceImport(\n astModule,\n declarationSymbol,\n declaration\n );\n\n return new AstNamespaceExport({\n namespaceName: imoprtNamespace.localName,\n astModule: astModule,\n declaration,\n symbol: declarationSymbol\n });\n }\n\n private _tryMatchImportDeclaration(\n declaration: ts.Declaration,\n declarationSymbol: ts.Symbol\n ): AstEntity | undefined {\n const importDeclaration: ts.ImportDeclaration | undefined =\n TypeScriptHelpers.findFirstParent<ts.ImportDeclaration>(declaration, ts.SyntaxKind.ImportDeclaration);\n\n if (importDeclaration) {\n const externalModulePath: string | undefined = this._tryGetExternalModulePath(importDeclaration);\n\n if (declaration.kind === ts.SyntaxKind.NamespaceImport) {\n // EXAMPLE:\n // \"import * as theLib from 'the-lib';\"\n //\n // ImportDeclaration:\n // ImportKeyword: pre=[import] sep=[ ]\n // ImportClause:\n // NamespaceImport: <------------- declaration\n // AsteriskToken: pre=[*] sep=[ ]\n // AsKeyword: pre=[as] sep=[ ]\n // Identifier: pre=[theLib] sep=[ ]\n // FromKeyword: pre=[from] sep=[ ]\n // StringLiteral: pre=['the-lib']\n // SemicolonToken: pre=[;]\n\n if (externalModulePath === undefined) {\n const astModule: AstModule = this._fetchSpecifierAstModule(importDeclaration, declarationSymbol);\n return this._getAstNamespaceImport(astModule, declarationSymbol, declaration);\n }\n\n // Here importSymbol=undefined because {@inheritDoc} and such are not going to work correctly for\n // a package or source file.\n return this._fetchAstImport(undefined, {\n importKind: AstImportKind.StarImport,\n exportName: declarationSymbol.name,\n modulePath: externalModulePath,\n isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)\n });\n }\n\n if (declaration.kind === ts.SyntaxKind.ImportSpecifier) {\n // EXAMPLE:\n // \"import { A, B } from 'the-lib';\"\n //\n // ImportDeclaration:\n // ImportKeyword: pre=[import] sep=[ ]\n // ImportClause:\n // NamedImports:\n // FirstPunctuation: pre=[{] sep=[ ]\n // SyntaxList:\n // ImportSpecifier: <------------- declaration\n // Identifier: pre=[A]\n // CommaToken: pre=[,] sep=[ ]\n // ImportSpecifier:\n // Identifier: pre=[B] sep=[ ]\n // CloseBraceToken: pre=[}] sep=[ ]\n // FromKeyword: pre=[from] sep=[ ]\n // StringLiteral: pre=['the-lib']\n // SemicolonToken: pre=[;]\n\n // Example: \" ExportName as RenamedName\"\n const importSpecifier: ts.ImportSpecifier = declaration as ts.ImportSpecifier;\n const exportName: string = (importSpecifier.propertyName || importSpecifier.name).getText().trim();\n\n if (externalModulePath !== undefined) {\n return this._fetchAstImport(declarationSymbol, {\n importKind: AstImportKind.NamedImport,\n modulePath: externalModulePath,\n exportName: exportName,\n isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)\n });\n }\n\n return this._getExportOfSpecifierAstModule(exportName, importDeclaration, declarationSymbol);\n } else if (declaration.kind === ts.SyntaxKind.ImportClause) {\n // EXAMPLE:\n // \"import A, { B } from './A';\"\n //\n // ImportDeclaration:\n // ImportKeyword: pre=[import] sep=[ ]\n // ImportClause: <------------- declaration (referring to A)\n // Identifier: pre=[A]\n // CommaToken: pre=[,] sep=[ ]\n // NamedImports:\n // FirstPunctuation: pre=[{] sep=[ ]\n // SyntaxList:\n // ImportSpecifier:\n // Identifier: pre=[B] sep=[ ]\n // CloseBraceToken: pre=[}] sep=[ ]\n // FromKeyword: pre=[from] sep=[ ]\n // StringLiteral: pre=['./A']\n // SemicolonToken: pre=[;]\n\n const importClause: ts.ImportClause = declaration as ts.ImportClause;\n const exportName: string = importClause.name\n ? importClause.name.getText().trim()\n : ts.InternalSymbolName.Default;\n\n if (externalModulePath !== undefined) {\n return this._fetchAstImport(declarationSymbol, {\n importKind: AstImportKind.DefaultImport,\n modulePath: externalModulePath,\n exportName,\n isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)\n });\n }\n\n return this._getExportOfSpecifierAstModule(\n ts.InternalSymbolName.Default,\n importDeclaration,\n declarationSymbol\n );\n } else {\n throw new InternalError(\n `Unimplemented import declaration kind: ${declaration.getText()}\\n` +\n SourceFileLocationFormatter.formatDeclaration(declaration)\n );\n }\n }\n\n if (ts.isImportEqualsDeclaration(declaration)) {\n // EXAMPLE:\n // import myLib = require('my-lib');\n //\n // ImportEqualsDeclaration:\n // ImportKeyword: pre=[import] sep=[ ]\n // Identifier: pre=[myLib] sep=[ ]\n // FirstAssignment: pre=[=] sep=[ ]\n // ExternalModuleReference:\n // RequireKeyword: pre=[require]\n // OpenParenToken: pre=[(]\n // StringLiteral: pre=['my-lib']\n // CloseParenToken: pre=[)]\n // SemicolonToken: pre=[;]\n if (ts.isExternalModuleReference(declaration.moduleReference)) {\n if (ts.isStringLiteralLike(declaration.moduleReference.expression)) {\n const variableName: string = TypeScriptInternals.getTextOfIdentifierOrLiteral(declaration.name);\n const externalModuleName: string = TypeScriptInternals.getTextOfIdentifierOrLiteral(\n declaration.moduleReference.expression\n );\n\n return this._fetchAstImport(declarationSymbol, {\n importKind: AstImportKind.EqualsImport,\n modulePath: externalModuleName,\n exportName: variableName,\n isTypeOnly: false\n });\n }\n }\n }\n\n return undefined;\n }\n\n private _getAstNamespaceImport(\n astModule: AstModule,\n declarationSymbol: ts.Symbol,\n declaration: ts.Declaration\n ): AstNamespaceImport {\n let namespaceImport: AstNamespaceImport | undefined = this._astNamespaceImportByModule.get(astModule);\n if (namespaceImport === undefined) {\n namespaceImport = new AstNamespaceImport({\n namespaceName: declarationSymbol.name,\n astModule: astModule,\n declaration: declaration,\n symbol: declarationSymbol\n });\n this._astNamespaceImportByModule.set(astModule, namespaceImport);\n }\n\n return namespaceImport;\n }\n\n private static _getIsTypeOnly(importDeclaration: ts.ImportDeclaration): boolean {\n if (importDeclaration.importClause) {\n return !!importDeclaration.importClause.isTypeOnly;\n }\n return false;\n }\n\n private _getExportOfSpecifierAstModule(\n exportName: string,\n importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration,\n exportSymbol: ts.Symbol\n ): AstEntity {\n const specifierAstModule: AstModule = this._fetchSpecifierAstModule(\n importOrExportDeclaration,\n exportSymbol\n );\n const astEntity: AstEntity = this._getExportOfAstModule(exportName, specifierAstModule);\n return astEntity;\n }\n\n private _getExportOfAstModule(exportName: string, astModule: AstModule): AstEntity {\n const visitedAstModules: Set<AstModule> = new Set<AstModule>();\n const astEntity: AstEntity | undefined = this._tryGetExportOfAstModule(\n exportName,\n astModule,\n visitedAstModules\n );\n if (astEntity === undefined) {\n throw new InternalError(\n `Unable to analyze the export ${JSON.stringify(exportName)} in\\n` + astModule.sourceFile.fileName\n );\n }\n return astEntity;\n }\n\n /**\n * Implementation of {@link AstSymbolTable.tryGetExportOfAstModule}.\n */\n public tryGetExportOfAstModule(exportName: string, astModule: AstModule): AstEntity | undefined {\n const visitedAstModules: Set<AstModule> = new Set<AstModule>();\n return this._tryGetExportOfAstModule(exportName, astModule, visitedAstModules);\n }\n\n private _tryGetExportOfAstModule(\n exportName: string,\n astModule: AstModule,\n visitedAstModules: Set<AstModule>\n ): AstEntity | undefined {\n if (visitedAstModules.has(astModule)) {\n return undefined;\n }\n visitedAstModules.add(astModule);\n\n let astEntity: AstEntity | undefined = astModule.cachedExportedEntities.get(exportName);\n if (astEntity !== undefined) {\n return astEntity;\n }\n\n // Try the explicit exports\n const escapedExportName: ts.__String = ts.escapeLeadingUnderscores(exportName);\n if (astModule.moduleSymbol.exports) {\n const exportSymbol: ts.Symbol | undefined = astModule.moduleSymbol.exports.get(escapedExportName);\n if (exportSymbol) {\n astEntity = this.fetchReferencedAstEntity(exportSymbol, astModule.isExternal);\n\n if (astEntity !== undefined) {\n astModule.cachedExportedEntities.set(exportName, astEntity); // cache for next time\n return astEntity;\n }\n }\n }\n\n // Try each of the star imports\n for (const starExportedModule of astModule.starExportedModules) {\n astEntity = this._tryGetExportOfAstModule(exportName, starExportedModule, visitedAstModules);\n\n if (astEntity !== undefined) {\n if (starExportedModule.externalModulePath !== undefined) {\n // This entity was obtained from an external module, so return an AstImport instead\n const astSymbol: AstSymbol = astEntity as AstSymbol;\n return this._fetchAstImport(astSymbol.followedSymbol, {\n importKind: AstImportKind.NamedImport,\n modulePath: starExportedModule.externalModulePath,\n exportName: exportName,\n isTypeOnly: false\n });\n }\n\n return astEntity;\n }\n }\n\n return undefined;\n }\n\n private _tryGetExternalModulePath(\n importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration | ts.ImportTypeNode\n ): string | undefined {\n const moduleSpecifier: string = this._getModuleSpecifier(importOrExportDeclaration);\n if (this._isExternalModulePath(importOrExportDeclaration, moduleSpecifier)) {\n return moduleSpecifier;\n }\n\n return undefined;\n }\n\n /**\n * Given an ImportDeclaration of the form `export { X } from \"___\";`, this interprets the module specifier (`\"___\"`)\n * and fetches the corresponding AstModule object.\n */\n private _fetchSpecifierAstModule(\n importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration,\n exportSymbol: ts.Symbol\n ): AstModule {\n const moduleSpecifier: string = this._getModuleSpecifier(importOrExportDeclaration);\n const mode: ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined =\n importOrExportDeclaration.moduleSpecifier &&\n ts.isStringLiteralLike(importOrExportDeclaration.moduleSpecifier)\n ? TypeScriptInternals.getModeForUsageLocation(\n importOrExportDeclaration.getSourceFile(),\n importOrExportDeclaration.moduleSpecifier,\n this._program.getCompilerOptions()\n )\n : undefined;\n const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule(\n this._program,\n importOrExportDeclaration.getSourceFile(),\n moduleSpecifier,\n mode\n );\n\n if (resolvedModule === undefined) {\n // Encountered in https://github.com/microsoft/rushstack/issues/1914.\n //\n // It's also possible for this to occur with ambient modules. However, in practice this doesn't happen\n // as API Extractor treats all ambient modules as external per the logic in `_isExternalModulePath`, and\n // thus this code path is never reached for ambient modules.\n throw new InternalError(\n `getResolvedModule() could not resolve module name ${JSON.stringify(moduleSpecifier)}\\n` +\n SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration)\n );\n }\n\n // Map the filename back to the corresponding SourceFile. This circuitous approach is needed because\n // we have no way to access the compiler's internal resolveExternalModuleName() function\n const moduleSourceFile: ts.SourceFile | undefined = this._program.getSourceFile(\n resolvedModule.resolvedFileName\n );\n if (!moduleSourceFile) {\n // This should not happen, since getResolvedModule() specifically looks up names that the compiler\n // found in export declarations for this source file\n throw new InternalError(\n `getSourceFile() failed to locate ${JSON.stringify(resolvedModule.resolvedFileName)}\\n` +\n SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration)\n );\n }\n\n const isExternal: boolean = this._isExternalModulePath(importOrExportDeclaration, moduleSpecifier);\n const moduleReference: IAstModuleReference = {\n moduleSpecifier: moduleSpecifier,\n moduleSpecifierSymbol: exportSymbol\n };\n const specifierAstModule: AstModule = this.fetchAstModuleFromSourceFile(\n moduleSourceFile,\n moduleReference,\n isExternal\n );\n\n return specifierAstModule;\n }\n\n private _fetchAstImport(importSymbol: ts.Symbol | undefined, options: IAstImportOptions): AstImport {\n const key: string = AstImport.getKey(options);\n\n let astImport: AstImport | undefined = this._astImportsByKey.get(key);\n\n if (!astImport) {\n astImport = new AstImport(options);\n this._astImportsByKey.set(key, astImport);\n\n if (importSymbol) {\n const followedSymbol: ts.Symbol = TypeScriptHelpers.followAliases(importSymbol, this._typeChecker);\n\n astImport.astSymbol = this._astSymbolTable.fetchAstSymbol({\n followedSymbol: followedSymbol,\n isExternal: true,\n includeNominalAnalysis: false,\n addIfMissing: true\n });\n }\n } else {\n // If we encounter at least one import that does not use the type-only form,\n // then the .d.ts rollup will NOT use \"import type\".\n if (!options.isTypeOnly) {\n astImport.isTypeOnlyEverywhere = false;\n }\n }\n\n return astImport;\n }\n\n private _getModuleSpecifier(\n importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration | ts.ImportTypeNode\n ): string {\n // The name of the module, which could be like \"./SomeLocalFile' or like 'external-package/entry/point'\n const moduleSpecifier: string | undefined =\n TypeScriptHelpers.getModuleSpecifier(importOrExportDeclaration);\n\n if (!moduleSpecifier) {\n throw new InternalError(\n 'Unable to parse module specifier\\n' +\n SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration)\n );\n }\n\n return moduleSpecifier;\n }\n}\n"]}
\ 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