collector.messageRouter.addAnalyzerIssueForPosition(ExtractorMessageId_1.ExtractorMessageId.MisplacedPackageTag,'The @packageDocumentation comment must appear at the top of entry point *.d.ts file',sourceFile,commentRange.pos);
{"version":3,"file":"PackageDocComment.js","sourceRoot":"","sources":["../../src/aedoc/PackageDocComment.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,+CAAiC;AAGjC,kEAA+D;AAE/D,MAAa,iBAAiB;IAC5B;;OAEG;IACI,MAAM,CAAC,mBAAmB,CAC/B,UAAyB,EACzB,SAAoB;QAEpB,oFAAoF;QACpF,mFAAmF;QACnF,6BAA6B;QAC7B,EAAE;QACF,sFAAsF;QACtF,uFAAuF;QACvF,+DAA+D;QAC/D,EAAE;QACF,kGAAkG;QAClG,wFAAwF;QACxF,8FAA8F;QAC9F,eAAe;QACf,IAAI,mBAAmB,GAA6B,SAAS,CAAC,CAAC,eAAe;QAE9E,KAAK,MAAM,YAAY,IAAI,EAAE,CAAC,uBAAuB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;YACxG,IAAI,YAAY,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,sBAAsB,EAAE,CAAC;gBAC/D,MAAM,WAAW,GAAW,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;gBAE1F,uCAAuC;gBACvC,IAAI,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;oBACnC,oEAAoE;oBACpE,wDAAwD;oBACxD,IAAI,yBAAyB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;wBAChD,mBAAmB,GAAG,YAAY,CAAC;oBACrC,CAAC;oBACD,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACzB,uFAAuF;YACvF,8FAA8F;YAC9F,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;gBAC9C,MAAM,MAAM,GAAsB,EAAE,CAAC;gBACrC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,uBAAuB,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBAC9F,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,wBAAwB,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBAEzF,KAAK,MAAM,YAAY,IAAI,MAAM,EAAE,CAAC;oBAClC,MAAM,WAAW,GAAW,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;oBAE1F,IAAI,yBAAyB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;wBAChD,SAAS,CAAC,aAAa,CAAC,2BAA2B,CACjD,uCAAkB,CAAC,mBAAmB,EACtC,qFAAqF,EACrF,UAAU,EACV,YAAY,CAAC,GAAG,CACjB,CAAC;wBACF,MAAM;oBACR,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CACF;AAhED,8CAgEC","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 type { Collector } from '../collector/Collector';\nimport { ExtractorMessageId } from '../api/ExtractorMessageId';\n\nexport class PackageDocComment {\n /**\n * For the given source file, see if it starts with a TSDoc comment containing the `@packageDocumentation` tag.\n */\n public static tryFindInSourceFile(\n sourceFile: ts.SourceFile,\n collector: Collector\n ): ts.TextRange | undefined {\n // The @packageDocumentation comment is special because it is not attached to an AST\n // definition. Instead, it is part of the \"trivia\" tokens that the compiler treats\n // as irrelevant white space.\n //\n // WARNING: If the comment doesn't precede an export statement, the compiler will omit\n // it from the *.d.ts file, and API Extractor won't find it. If this happens, you need\n // to rearrange your statements to ensure it is passed through.\n //\n // This implementation assumes that the \"@packageDocumentation\" will be in the first TSDoc comment\n // that appears in the entry point *.d.ts file. We could possibly look in other places,\n // but the above warning suggests enforcing a standardized layout. This design choice is open\n // to feedback.\n let packageCommentRange: ts.TextRange | undefined = undefined; // empty string\n\n for (const commentRange of ts.getLeadingCommentRanges(sourceFile.text, sourceFile.getFullStart()) || []) {\n if (commentRange.kind === ts.SyntaxKind.MultiLineCommentTrivia) {\n const commentBody: string = sourceFile.text.substring(commentRange.pos, commentRange.end);\n\n // Choose the first JSDoc-style comment\n if (/^\\s*\\/\\*\\*/.test(commentBody)) {\n // But only if it looks like it's trying to be @packageDocumentation\n // (The TSDoc parser will validate this more rigorously)\n if (/\\@packageDocumentation/i.test(commentBody)) {\n packageCommentRange = commentRange;\n }\n break;\n }\n }\n }\n\n if (!packageCommentRange) {\n // If we didn't find the @packageDocumentation tag in the expected place, is it in some\n // wrong place? This sanity check helps people to figure out why there comment isn't working.\n for (const statement of sourceFile.statements) {\n const ranges: ts.CommentRange[] = [];\n ranges.push(...(ts.getLeadingCommentRanges(sourceFile.text, statement.getFullStart()) || []));\n ranges.push(...(ts.getTrailingCommentRanges(sourceFile.text, statement.getEnd()) || []));\n\n for (const commentRange of ranges) {\n const commentBody: string = sourceFile.text.substring(commentRange.pos, commentRange.end);\n\n if (/\\@packageDocumentation/i.test(commentBody)) {\n collector.messageRouter.addAnalyzerIssueForPosition(\n ExtractorMessageId.MisplacedPackageTag,\n 'The @packageDocumentation comment must appear at the top of entry point *.d.ts file',\n sourceFile,\n commentRange.pos\n );\n break;\n }\n }\n }\n }\n\n return packageCommentRange;\n }\n}\n"]}
{"version":3,"file":"AstDeclaration.js","sourceRoot":"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AAC,WAAW,CAAC;YAC/B,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC;YAC/B,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,mCAAmC;YACtE,KAAK,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC;YACxC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;YACrC,KAAK,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;YACnC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,sDAAsD;YAC5F,KAAK,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC;YACvC,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;YACrC,KAAK,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,0CAA0C;YACnF,KAAK,EAAE,CAAC,UAAU,CAAC,mBAAmB;gBACpC,OAAO,IAAI,CAAC;YAEd,gHAAgH;YAChH,0CAA0C;YAE1C,gGAAgG;YAChG,8FAA8F;YAC9F,4FAA4F;YAC5F,gGAAgG;YAChG,0DAA0D;QAC5D,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAvPD,wCAuPC","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 type { AstSymbol } from './AstSymbol';\nimport { Span } from './Span';\nimport type { AstEntity } from './AstEntity';\n\n/**\n * Constructor options for AstDeclaration\n */\nexport interface IAstDeclarationOptions {\n readonly declaration: ts.Declaration;\n readonly astSymbol: AstSymbol;\n readonly parent: AstDeclaration | undefined;\n}\n\n/**\n * The AstDeclaration and AstSymbol classes are API Extractor's equivalent of the compiler's\n * ts.Declaration and ts.Symbol objects. They are created by the `AstSymbolTable` class.\n *\n * @remarks\n * The AstDeclaration represents one or more syntax components of a symbol. Usually there is\n * only one AstDeclaration per AstSymbol, but certain TypeScript constructs can have multiple\n * declarations (e.g. overloaded functions, merged declarations, etc.).\n *\n * Because of this, the `AstDeclaration` manages the parent/child nesting hierarchy (e.g. with\n * declaration merging, each declaration has its own children) and becomes the main focus\n * of analyzing AEDoc and emitting *.d.ts files.\n *\n * The AstDeclarations correspond to items from the compiler's ts.Node hierarchy, but\n * omitting/skipping any nodes that don't match the AstDeclaration.isSupportedSyntaxKind()\n * criteria. This simplification makes the other API Extractor stages easier to implement.\n */\nexport class AstDeclaration {\n public readonly declaration: ts.Declaration;\n\n public readonly astSymbol: AstSymbol;\n\n /**\n * The parent, if this object is nested inside another AstDeclaration.\n */\n public readonly parent: AstDeclaration | undefined;\n\n /**\n * A bit set of TypeScript modifiers such as \"private\", \"protected\", etc.\n */\n public readonly modifierFlags: ts.ModifierFlags;\n\n /**\n * Additional information that is calculated later by the `Collector`. The actual type is `DeclarationMetadata`,\n * but we declare it as `unknown` because consumers must obtain this object by calling\n * `Collector.fetchDeclarationMetadata()`.\n */\n public declarationMetadata: unknown;\n\n /**\n * Additional information that is calculated later by the `Collector`. The actual type is `ApiItemMetadata`,\n * but we declare it as `unknown` because consumers must obtain this object by calling\n * `Collector.fetchApiItemMetadata()`.\n */\n public apiItemMetadata: unknown;\n\n // NOTE: This array becomes immutable after astSymbol.analyze() sets astSymbol.analyzed=true\n private readonly _analyzedChildren: AstDeclaration[] = [];\n\n private readonly _analyzedReferencedAstEntitiesSet: Set<AstEntity> = new Set<AstEntity>();\n\n // Reverse lookup used by findChildrenWithName()\n private _childrenByName: Map<string, AstDeclaration[]> | undefined = undefined;\n\n public constructor(options: IAstDeclarationOptions) {\n this.declaration = options.declaration;\n this.astSymbol = options.astSymbol;\n this.parent = options.parent;\n\n this.astSymbol._notifyDeclarationAttach(this);\n\n if (this.parent) {\n this.parent._notifyChildAttach(this);\n }\n\n this.modifierFlags = ts.getCombinedModifierFlags(this.declaration);\n\n // Check for ECMAScript private fields, for example:\n //\n // class Person { #name: string; }\n //\n const declarationName: ts.DeclarationName | undefined = ts.getNameOfDeclaration(this.declaration);\n if (declarationName) {\n if (ts.isPrivateIdentifier(declarationName)) {\n // eslint-disable-next-line no-bitwise\n this.modifierFlags |= ts.ModifierFlags.Private;\n }\n }\n }\n\n /**\n * Returns the children for this AstDeclaration.\n * @remarks\n * The collection will be empty until AstSymbol.analyzed is true.\n */\n public get children(): ReadonlyArray<AstDeclaration> {\n return this.astSymbol.analyzed ? this._analyzedChildren : [];\n }\n\n /**\n * Returns the AstEntity objects referenced by this node.\n * @remarks\n * NOTE: The collection will be empty until AstSymbol.analyzed is true.\n *\n * Since we assume references are always collected by a traversal starting at the\n * root of the nesting declarations, this array omits the following items because they\n * would be redundant:\n * - symbols corresponding to parents of this declaration (e.g. a method that returns its own class)\n * - symbols already listed in the referencedAstSymbols property for parents of this declaration\n * (e.g. a method that returns its own class's base class)\n * - symbols that are referenced only by nested children of this declaration\n * (e.g. if a method returns an enum, this doesn't imply that the method's class references that enum)\n */\n public get referencedAstEntities(): ReadonlyArray<AstEntity> {\n return this.astSymbol.analyzed ? [...this._analyzedReferencedAstEntitiesSet] : [];\n }\n\n /**\n * This is an internal callback used when the AstSymbolTable attaches a new\n * child AstDeclaration to this object.\n * @internal\n */\n public _notifyChildAttach(child: AstDeclaration): void {\n if (child.parent !== this) {\n throw new InternalError('Invalid call to notifyChildAttach()');\n }\n\n if (this.astSymbol.analyzed) {\n throw new InternalError('_notifyChildAttach() called after analysis is already complete');\n }\n\n this._analyzedChildren.push(child);\n }\n\n /**\n * Returns a diagnostic dump of the tree, which reports the hierarchy of\n * AstDefinition objects.\n */\n public getDump(indent: string = ''): string {\n const declarationKind: string = ts.SyntaxKind[this.declaration.kind];\n let result: string = indent + `+ ${this.astSymbol.localName} (${declarationKind})`;\n if (this.astSymbol.nominalAnalysis) {\n result += ' (nominal)';\n }\n result += '\\n';\n\n for (const referencedAstEntity of this._analyzedReferencedAstEntitiesSet.values()) {\n result += indent + ` ref: ${referencedAstEntity.localName}\\n`;\n }\n\n for (const child of this.children) {\n result += child.getDump(indent + ' ');\n }\n\n return result;\n }\n\n /**\n * Returns a diagnostic dump using Span.getDump(), which reports the detailed\n * compiler structure.\n */\n public getSpanDump(indent: string = ''): string {\n const span: Span = new Span(this.declaration);\n return span.getDump(indent);\n }\n\n /**\n * This is an internal callback used when AstSymbolTable.analyze() discovers a new\n * type reference associated with this declaration.\n * @internal\n */\n public _notifyReferencedAstEntity(referencedAstEntity: AstEntity): void {\n if (this.astSymbol.analyzed) {\n throw new InternalError('_notifyReferencedAstEntity() called after analysis is already complete');\n }\n\n for (let current: AstDeclaration | undefined = this; current; current = current.parent) {\n // Don't add references to symbols that are already referenced by a parent\n if (current._analyzedReferencedAstEntitiesSet.has(referencedAstEntity)) {\n return;\n }\n // Don't add the symbols of parents either\n if (referencedAstEntity === current.astSymbol) {\n return;\n }\n }\n\n this._analyzedReferencedAstEntitiesSet.add(referencedAstEntity);\n }\n\n /**\n * Visits all the current declaration and all children recursively in a depth-first traversal,\n * and performs the specified action for each one.\n */\n public forEachDeclarationRecursive(action: (astDeclaration: AstDeclaration) => void): void {\n action(this);\n for (const child of this.children) {\n child.forEachDeclarationRecursive(action);\n }\n }\n\n /**\n * Returns the list of child declarations whose `AstSymbol.localName` matches the provided `name`.\n *\n * @remarks\n * This is an efficient O(1) lookup.\n */\n public findChildrenWithName(name: string): ReadonlyArray<AstDeclaration> {\n // The children property returns:\n //\n // return this.astSymbol.analyzed ? this._analyzedChildren : [];\n //\n if (!this.astSymbol.analyzed || this._analyzedChildren.length === 0) {\n return [];\n }\n\n if (this._childrenByName === undefined) {\n // Build the lookup table\n const childrenByName: Map<string, AstDeclaration[]> = new Map<string, AstDeclaration[]>();\n\n for (const child of this._analyzedChildren) {\n const childName: string = child.astSymbol.localName;\n let array: AstDeclaration[] | undefined = childrenByName.get(childName);\n if (array === undefined) {\n array = [];\n childrenByName.set(childName, array);\n }\n array.push(child);\n }\n this._childrenByName = childrenByName;\n }\n\n return this._childrenByName.get(name) || [];\n }\n\n /**\n * This function determines which ts.Node kinds will generate an AstDeclaration.\n * These correspond to the definitions that we can add AEDoc to.\n */\n public static isSupportedSyntaxKind(kind: ts.SyntaxKind): boolean {\n // (alphabetical order)\n switch (kind) {\n case ts.SyntaxKind.CallSignature:\n case ts.SyntaxKind.ClassDeclaration:\n case ts.SyntaxKind.ConstructSignature: // Example: \"new(x: number): IMyClass\"\n case ts.SyntaxKind.Constructor: // Example: \"constructor(x: number)\"\n case ts.SyntaxKind.EnumDeclaration:\n case ts.SyntaxKind.EnumMember:\n case ts.SyntaxKind.FunctionDeclaration: // Example: \"(x: number): number\"\n case ts.SyntaxKind.GetAccessor:\n case ts.SyntaxKind.SetAccessor:\n case ts.SyntaxKind.IndexSignature: // Example: \"[key: string]: string\"\n case ts.SyntaxKind.InterfaceDeclaration:\n case ts.SyntaxKind.MethodDeclaration:\n case ts.SyntaxKind.MethodSignature:\n case ts.SyntaxKind.ModuleDeclaration: // Used for both \"module\" and \"namespace\" declarations\n case ts.SyntaxKind.PropertyDeclaration:\n case ts.SyntaxKind.PropertySignature:\n case ts.SyntaxKind.TypeAliasDeclaration: // Example: \"type Shape = Circle | Square\"\n case ts.SyntaxKind.VariableDeclaration:\n return true;\n\n // NOTE: Prior to TypeScript 3.7, in the emitted .d.ts files, the compiler would merge a GetAccessor/SetAccessor\n // pair into a single PropertyDeclaration.\n\n // NOTE: In contexts where a source file is treated as a module, we do create \"nominal analysis\"\n // AstSymbol objects corresponding to a ts.SyntaxKind.SourceFile node. However, a source file\n // is NOT considered a nesting structure, and it does NOT act as a root for the declarations\n // appearing in the file. This is because the *.d.ts generator is in the business of rolling up\n // source files, and thus wants to ignore them in general.\n }\n\n return false;\n }\n}\n"]}
{"version":3,"file":"AstEntity.js","sourceRoot":"","sources":["../../src/analyzer/AstEntity.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;;;;;;;;;;GAaG;AACH,MAAsB,SAAS;CAY9B;AAZD,8BAYC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAsB,kBAAmB,SAAQ,SAAS;CAAG;AAA7D,gDAA6D","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/**\n * `AstEntity` is the abstract base class for analyzer objects that can become a `CollectorEntity`.\n *\n * @remarks\n *\n * The subclasses are:\n * ```\n * - AstEntity\n * - AstSymbol\n * - AstSyntheticEntity\n * - AstImport\n * - AstNamespaceImport\n * ```\n */\nexport abstract class AstEntity {\n /**\n * The original name of the symbol, as exported from the module (i.e. source file)\n * containing the original TypeScript definition. Constructs such as\n * `import { X as Y } from` may introduce other names that differ from the local name.\n *\n * @remarks\n * For the most part, `localName` corresponds to `followedSymbol.name`, but there\n * are some edge cases. For example, the ts.Symbol.name for `export default class X { }`\n * is actually `\"default\"`, not `\"X\"`.\n */\n public abstract readonly localName: string;\n}\n\n/**\n * `AstSyntheticEntity` is the abstract base class for analyzer objects whose emitted declarations\n * are not text transformations performed by the `Span` helper.\n *\n * @remarks\n * Most of API Extractor's output is produced by using the using the `Span` utility to regurgitate strings from\n * the input .d.ts files. If we need to rename an identifier, the `Span` visitor can pick out an interesting\n * node and rewrite its string, but otherwise the transformation operates on dumb text and not compiler concepts.\n * (Historically we did this because the compiler's emitter was an internal API, but it still has some advantages,\n * for example preserving syntaxes generated by an older compiler to avoid incompatibilities.)\n *\n * This strategy does not work for cases where the output looks very different from the input. Today these\n * cases are always kinds of `import` statements, but that may change in the future.\n */\nexport abstract class AstSyntheticEntity extends AstEntity {}\n"]}
{"version":3,"file":"AstImport.js","sourceRoot":"","sources":["../../src/analyzer/AstImport.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAA6D;AAG7D,2CAAiD;AAEjD;;GAEG;AACH,IAAY,aAyBX;AAzBD,WAAY,aAAa;IACvB;;OAEG;IACH,mEAAa,CAAA;IAEb;;OAEG;IACH,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AC,CAAC,GAAG,CAAC,2BAA2B;oBACjC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,+BAA+B;wBAChE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;wBAClC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;gBACzB,OAAO,GAAG,OAAO,CAAC,UAAU,IAAI,MAAM,EAAE,CAAC;YAC3C,CAAC;YACD;gBACE,MAAM,IAAI,iCAAa,CAAC,uBAAuB,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CACF;AA3GD,8BA2GC","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 { InternalError } from '@rushstack/node-core-library';\n\nimport type { AstSymbol } from './AstSymbol';\nimport { AstSyntheticEntity } from './AstEntity';\n\n/**\n * Indicates the import kind for an `AstImport`.\n */\nexport enum AstImportKind {\n /**\n * An import statement such as `import X from \"y\";`.\n */\n DefaultImport,\n\n /**\n * An import statement such as `import { X } from \"y\";`.\n */\n NamedImport,\n\n /**\n * An import statement such as `import * as x from \"y\";`.\n */\n StarImport,\n\n /**\n * An import statement such as `import x = require(\"y\");`.\n */\n EqualsImport,\n\n /**\n * An import statement such as `interface foo { foo: import(\"bar\").a.b.c }`.\n */\n ImportType\n}\n\n/**\n * Constructor parameters for AstImport\n *\n * @privateRemarks\n * Our naming convention is to use I____Parameters for constructor options and\n * I____Options for general function options. However the word \"parameters\" is\n * confusingly similar to the terminology for function parameters modeled by API Extractor,\n * so we use I____Options for both cases in this code base.\n */\nexport interface IAstImportOptions {\n readonly importKind: AstImportKind;\n readonly modulePath: string;\n readonly exportName: string;\n readonly isTypeOnly: boolean;\n}\n\n/**\n * For a symbol that was imported from an external package, this tracks the import\n * statement that was used to reach it.\n */\nexport class AstImport extends AstSyntheticEntity {\n public readonly importKind: AstImportKind;\n\n /**\n * The name of the external package (and possibly module path) that this definition\n * was imported from.\n *\n * Example: \"@rushstack/node-core-library/lib/FileSystem\"\n */\n public readonly modulePath: string;\n\n /**\n * The name of the symbol being imported.\n *\n * @remarks\n *\n * The name depends on the type of import:\n *\n * ```ts\n * // For AstImportKind.DefaultImport style, exportName would be \"X\" in this example:\n * import X from \"y\";\n *\n * // For AstImportKind.NamedImport style, exportName would be \"X\" in this example:\n * import { X } from \"y\";\n *\n * // For AstImportKind.StarImport style, exportName would be \"x\" in this example:\n * import * as x from \"y\";\n *\n * // For AstImportKind.EqualsImport style, exportName would be \"x\" in this example:\n * import x = require(\"y\");\n *\n * // For AstImportKind.ImportType style, exportName would be \"a.b.c\" in this example:\n * interface foo { foo: import('bar').a.b.c };\n * ```\n */\n public readonly exportName: string;\n\n /**\n * Whether it is a type-only import, for example:\n *\n * ```ts\n * import type { X } from \"y\";\n * ```\n *\n * This is set to true ONLY if the type-only form is used in *every* reference to this AstImport.\n */\n public isTypeOnlyEverywhere: boolean;\n\n /**\n * If this import statement refers to an API from an external package that is tracked by API Extractor\n * (according to `PackageMetadataManager.isAedocSupportedFor()`), then this property will return the\n * corresponding AstSymbol. Otherwise, it is undefined.\n */\n public astSymbol: AstSymbol | undefined;\n\n /**\n * If modulePath and exportName are defined, then this is a dictionary key\n * that combines them with a colon (\":\").\n *\n * Example: \"@rushstack/node-core-library/lib/FileSystem:FileSystem\"\n */\n public readonly key: string;\n\n public constructor(options: IAstImportOptions) {\n super();\n\n this.importKind = options.importKind;\n this.modulePath = options.modulePath;\n this.exportName = options.exportName;\n\n // We start with this assumption, but it may get changed later if non-type-only import is encountered.\n this.isTypeOnlyEverywhere = options.isTypeOnly;\n\n this.key = AstImport.getKey(options);\n }\n\n /** {@inheritdoc} */\n public get localName(): string {\n // abstract\n return this.exportName;\n }\n\n /**\n * Calculates the lookup key used with `AstImport.key`\n */\n public static getKey(options: IAstImportOptions): string {\n switch (options.importKind) {\n case AstImportKind.DefaultImport:\n return `${options.modulePath}:${options.exportName}`;\n case AstImportKind.NamedImport:\n return `${options.modulePath}:${options.exportName}`;\n case AstImportKind.StarImport:\n return `${options.modulePath}:*`;\n case AstImportKind.EqualsImport:\n return `${options.modulePath}:=`;\n case AstImportKind.ImportType: {\n const subKey: string = !options.exportName\n ? '*' // Equivalent to StarImport\n : options.exportName.includes('.') // Equivalent to a named export\n ? options.exportName.split('.')[0]\n : options.exportName;\n return `${options.modulePath}:${subKey}`;\n }\n default:\n throw new InternalError('Unknown AstImportKind');\n }\n }\n}\n"]}