Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions apps/api-documenter/src/nodes/CustomDocNodeKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export enum CustomDocNodeKind {
TableRow = 'TableRow'
}

export class CustomDocNodes {
private static _configuration: TSDocConfiguration | undefined;
let _configuration: TSDocConfiguration | undefined;

export class CustomDocNodes {
public static get configuration(): TSDocConfiguration {
if (CustomDocNodes._configuration === undefined) {
if (_configuration === undefined) {
const configuration: TSDocConfiguration = new TSDocConfiguration();

configuration.docNodeManager.registerDocNodes('@micrososft/api-documenter', [
Expand All @@ -53,8 +53,8 @@ export class CustomDocNodes {
CustomDocNodeKind.EmphasisSpan
]);

CustomDocNodes._configuration = configuration;
_configuration = configuration;
}
return CustomDocNodes._configuration;
return _configuration;
}
}
5 changes: 3 additions & 2 deletions apps/api-documenter/src/utils/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

import { ApiParameterListMixin, type ApiItem } from '@microsoft/api-extractor-model';

const _badFilenameCharsRegExp: RegExp = /[^a-z0-9_\-\.]/gi;

export class Utilities {
private static readonly _badFilenameCharsRegExp: RegExp = /[^a-z0-9_\-\.]/gi;
/**
* Generates a concise signature for a function. Example: "getArea(width, height)"
*/
Expand All @@ -21,6 +22,6 @@ export class Utilities {
public static getSafeFilenameForName(name: string): string {
// TODO: This can introduce naming collisions.
// We will fix that as part of https://github.com/microsoft/rushstack/issues/1308
return name.replace(Utilities._badFilenameCharsRegExp, '_').toLowerCase();
return name.replace(_badFilenameCharsRegExp, '_').toLowerCase();
}
}
20 changes: 10 additions & 10 deletions apps/api-extractor/src/analyzer/ExportAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ export class ExportAnalyzer {
importKind: AstImportKind.StarImport,
exportName: declarationSymbol.name,
modulePath: externalModulePath,
isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)
isTypeOnly: _getIsTypeOnly(importDeclaration)
});
}

Expand Down Expand Up @@ -690,7 +690,7 @@ export class ExportAnalyzer {
importKind: AstImportKind.NamedImport,
modulePath: externalModulePath,
exportName: exportName,
isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)
isTypeOnly: _getIsTypeOnly(importDeclaration)
});
}

Expand Down Expand Up @@ -724,7 +724,7 @@ export class ExportAnalyzer {
importKind: AstImportKind.DefaultImport,
modulePath: externalModulePath,
exportName,
isTypeOnly: ExportAnalyzer._getIsTypeOnly(importDeclaration)
isTypeOnly: _getIsTypeOnly(importDeclaration)
});
}

Expand Down Expand Up @@ -794,13 +794,6 @@ export class ExportAnalyzer {
return namespaceImport;
}

private static _getIsTypeOnly(importDeclaration: ts.ImportDeclaration): boolean {
if (importDeclaration.importClause) {
return !!importDeclaration.importClause.isTypeOnly;
}
return false;
}

private _getExportOfSpecifierAstModule(
exportName: string,
importOrExportDeclaration: ts.ImportDeclaration | ts.ExportDeclaration,
Expand Down Expand Up @@ -1012,3 +1005,10 @@ export class ExportAnalyzer {
return moduleSpecifier;
}
}

function _getIsTypeOnly(importDeclaration: ts.ImportDeclaration): boolean {
if (importDeclaration.importClause) {
return !!importDeclaration.importClause.isTypeOnly;
}
return false;
}
58 changes: 29 additions & 29 deletions apps/api-extractor/src/analyzer/PackageMetadataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ function _tryResolveTsdocMetadataFromMainField({ main }: INodePackageJson): stri
}
}

/**
* This feature is still being standardized: https://github.com/microsoft/tsdoc/issues/7
* In the future we will use the @microsoft/tsdoc library to read this file.
*/
function _resolveTsdocMetadataPathFromPackageJson(
packageFolder: string,
packageJson: INodePackageJson
): string {
const tsdocMetadataRelativePath: string =
_tryResolveTsdocMetadataFromTsdocMetadataField(packageJson) ??
_tryResolveTsdocMetadataFromExportsField(packageJson) ??
_tryResolveTsdocMetadataFromTypesVersionsField(packageJson) ??
_tryResolveTsdocMetadataFromTypesOrTypingsFields(packageJson) ??
_tryResolveTsdocMetadataFromMainField(packageJson) ??
// As a final fallback, place the file in the root of the package.
TSDOC_METADATA_FILENAME;

// Always resolve relative to the package folder.
const tsdocMetadataPath: string = path.resolve(
packageFolder,
// This non-null assertion is safe because the last entry in TSDOC_METADATA_RESOLUTION_FUNCTIONS
// returns a non-undefined value.
tsdocMetadataRelativePath!
);
return tsdocMetadataPath;
}

/**
* This class maintains a cache of analyzed information obtained from package.json
* files. It is built on top of the PackageJsonLookup class.
Expand Down Expand Up @@ -202,33 +229,6 @@ export class PackageMetadataManager {
this._messageRouter = messageRouter;
}

/**
* This feature is still being standardized: https://github.com/microsoft/tsdoc/issues/7
* In the future we will use the @microsoft/tsdoc library to read this file.
*/
private static _resolveTsdocMetadataPathFromPackageJson(
packageFolder: string,
packageJson: INodePackageJson
): string {
const tsdocMetadataRelativePath: string =
_tryResolveTsdocMetadataFromTsdocMetadataField(packageJson) ??
_tryResolveTsdocMetadataFromExportsField(packageJson) ??
_tryResolveTsdocMetadataFromTypesVersionsField(packageJson) ??
_tryResolveTsdocMetadataFromTypesOrTypingsFields(packageJson) ??
_tryResolveTsdocMetadataFromMainField(packageJson) ??
// As a final fallback, place the file in the root of the package.
TSDOC_METADATA_FILENAME;

// Always resolve relative to the package folder.
const tsdocMetadataPath: string = path.resolve(
packageFolder,
// This non-null assertion is safe because the last entry in TSDOC_METADATA_RESOLUTION_FUNCTIONS
// returns a non-undefined value.
tsdocMetadataRelativePath!
);
return tsdocMetadataPath;
}

/**
* @param tsdocMetadataPath - An explicit path that can be configured in api-extractor.json.
* If this parameter is not an empty string, it overrides the normal path calculation.
Expand All @@ -243,7 +243,7 @@ export class PackageMetadataManager {
return path.resolve(packageFolder, tsdocMetadataPath);
}

return PackageMetadataManager._resolveTsdocMetadataPathFromPackageJson(packageFolder, packageJson);
return _resolveTsdocMetadataPathFromPackageJson(packageFolder, packageJson);
}

/**
Expand Down Expand Up @@ -292,7 +292,7 @@ export class PackageMetadataManager {

let aedocSupported: boolean = false;

const tsdocMetadataPath: string = PackageMetadataManager._resolveTsdocMetadataPathFromPackageJson(
const tsdocMetadataPath: string = _resolveTsdocMetadataPathFromPackageJson(
packageJsonFolder,
packageJson
);
Expand Down
18 changes: 9 additions & 9 deletions apps/api-extractor/src/analyzer/TypeScriptHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { InternalError } from '@rushstack/node-core-library';
import { SourceFileLocationFormatter } from './SourceFileLocationFormatter';
import { TypeScriptInternals } from './TypeScriptInternals';

export class TypeScriptHelpers {
// Matches TypeScript's encoded names for well-known ECMAScript symbols like
// "__@iterator" or "__@toStringTag".
private static readonly _wellKnownSymbolNameRegExp: RegExp = /^__@(\w+)$/;
// Matches TypeScript's encoded names for well-known ECMAScript symbols like
// "__@iterator" or "__@toStringTag".
const _wellKnownSymbolNameRegExp: RegExp = /^__@(\w+)$/;

// Matches TypeScript's encoded names for late-bound symbols derived from `unique symbol` declarations
// which have the form of "__@<variableName>@<symbolId>", i.e. "__@someSymbol@12345".
private static readonly _uniqueSymbolNameRegExp: RegExp = /^__@.*@\d+$/;
// Matches TypeScript's encoded names for late-bound symbols derived from `unique symbol` declarations
// which have the form of "__@<variableName>@<symbolId>", i.e. "__@someSymbol@12345".
const _uniqueSymbolNameRegExp: RegExp = /^__@.*@\d+$/;

export class TypeScriptHelpers {
/**
* This traverses any symbol aliases to find the original place where an item was defined.
* For example, suppose a class is defined as "export default class MyClass { }"
Expand Down Expand Up @@ -268,7 +268,7 @@ export class TypeScriptHelpers {
* If the string does not start with `__@` then `undefined` is returned.
*/
public static tryDecodeWellKnownSymbolName(name: ts.__String): string | undefined {
const match: RegExpExecArray | null = TypeScriptHelpers._wellKnownSymbolNameRegExp.exec(name as string);
const match: RegExpExecArray | null = _wellKnownSymbolNameRegExp.exec(name as string);
if (match) {
const identifier: string = match[1];
return `[Symbol.${identifier}]`;
Expand All @@ -280,7 +280,7 @@ export class TypeScriptHelpers {
* Returns whether the provided name was generated for a TypeScript `unique symbol`.
*/
public static isUniqueSymbolName(name: ts.__String): boolean {
return TypeScriptHelpers._uniqueSymbolNameRegExp.test(name as string);
return _uniqueSymbolNameRegExp.test(name as string);
}

/**
Expand Down
Loading