@microsoft/api-extractor
Version:
Validate, document, and review the exported API for a TypeScript library
52 lines • 2.06 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
/**
* This is a data structure used by DtsRollupGenerator to track an AstSymbol that may be
* emitted in the *.d.ts file.
* @remarks
* The additional contextual state beyond AstSymbol is:
* - Whether it's an export of this entry point or not
* - The calculated ReleaseTag, which we use for trimming
* - The nameForEmit, which may get renamed by DtsRollupGenerator._makeUniqueNames()
*/
class DtsEntry {
constructor(parameters) {
this._nameForEmit = undefined;
this._sortKey = undefined;
this.astSymbol = parameters.astSymbol;
this.originalName = parameters.originalName;
this.exported = parameters.exported;
}
/**
* The originalName, possibly renamed to ensure that all the top-level exports have unique names.
*/
get nameForEmit() {
return this._nameForEmit;
}
set nameForEmit(value) {
this._nameForEmit = value;
this._sortKey = undefined; // invalidate the cached value
}
/**
* A sorting key used by DtsRollupGenerator._makeUniqueNames()
*/
getSortKey() {
if (!this._sortKey) {
const name = this.nameForEmit || this.originalName;
if (name.substr(0, 1) === '_') {
// Removes the leading underscore, for example: "_example" --> "example*"
// This causes internal definitions to sort alphabetically with regular definitions.
// The star is appended to preserve uniqueness, since "*" is not a legal identifier character.
this._sortKey = name.substr(1) + '*';
}
else {
this._sortKey = name;
}
}
return this._sortKey;
}
}
exports.DtsEntry = DtsEntry;
//# sourceMappingURL=DtsEntry.js.map