@microsoft/api-extractor
Version:
Analyze the exported API for a TypeScript library and generate reviews, documentation, and .d.ts rollups
79 lines • 2.6 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AstNamespaceImport = void 0;
const AstEntity_1 = require("./AstEntity");
/**
* `AstNamespaceImport` represents a namespace that is created implicitly by a statement
* such as `import * as example from "./file";`
*
* @remarks
*
* A typical input looks like this:
* ```ts
* // Suppose that example.ts exports two functions f1() and f2().
* import * as example from "./file";
* export { example };
* ```
*
* API Extractor's .d.ts rollup will transform it into an explicit namespace, like this:
* ```ts
* declare f1(): void;
* declare f2(): void;
*
* declare namespace example {
* export {
* f1,
* f2
* }
* }
* ```
*
* The current implementation does not attempt to relocate f1()/f2() to be inside the `namespace`
* because other type signatures may reference them directly (without using the namespace qualifier).
* The `declare namespace example` is a synthetic construct represented by `AstNamespaceImport`.
*/
class AstNamespaceImport extends AstEntity_1.AstSyntheticEntity {
/**
* Returns true if the AstSymbolTable.analyze() was called for this object.
* See that function for details.
*/
analyzed = false;
/**
* For example, if the original statement was `import * as example from "./file";`
* then `astModule` refers to the `./file.d.ts` file.
*/
astModule;
/**
* For example, if the original statement was `import * as example from "./file";`
* then `namespaceName` would be `example`.
*/
namespaceName;
/**
* The original `ts.SyntaxKind.NamespaceImport` which can be used as a location for error messages.
*/
declaration;
/**
* The original `ts.SymbolFlags.Namespace` symbol.
*/
symbol;
constructor(options) {
super();
this.astModule = options.astModule;
this.namespaceName = options.namespaceName;
this.declaration = options.declaration;
this.symbol = options.symbol;
}
/** {@inheritdoc} */
get localName() {
// abstract
return this.namespaceName;
}
fetchAstModuleExportInfo(collector) {
const astModuleExportInfo = collector.astSymbolTable.fetchAstModuleExportInfo(this.astModule);
return astModuleExportInfo;
}
}
exports.AstNamespaceImport = AstNamespaceImport;
//# sourceMappingURL=AstNamespaceImport.js.map