Generated module conversion step - inlineImports

This step converts as many explicit accesses as possible in favor of direct imports from the modules in which things were declared. This restores the code (as much as possible) back to how it looked originally before the explicitify step, e.g. instead of "ts.Node" and "ts.Symbol", we have just "Node" and "Symbol".
This commit is contained in:
Jake Bailey
2022-11-07 13:33:07 -08:00
parent b6c0538826
commit 07758c08ab
240 changed files with 59309 additions and 56278 deletions
+17 -14
View File
@@ -1,16 +1,19 @@
import * as ts from "./_namespaces/ts";
import {
Debug, ESMap, FileWatcher, Map, ModulePath, ModuleSpecifierCache, ModuleSpecifierOptions, nodeModulesPathPart, Path,
ResolvedModuleSpecifierInfo, UserPreferences,
} from "./_namespaces/ts";
/** @internal */
export interface ModuleSpecifierResolutionCacheHost {
watchNodeModulesForPackageJsonChanges(directoryPath: string): ts.FileWatcher;
watchNodeModulesForPackageJsonChanges(directoryPath: string): FileWatcher;
}
/** @internal */
export function createModuleSpecifierCache(host: ModuleSpecifierResolutionCacheHost): ts.ModuleSpecifierCache {
let containedNodeModulesWatchers: ts.ESMap<string, ts.FileWatcher> | undefined;
let cache: ts.ESMap<ts.Path, ts.ResolvedModuleSpecifierInfo> | undefined;
export function createModuleSpecifierCache(host: ModuleSpecifierResolutionCacheHost): ModuleSpecifierCache {
let containedNodeModulesWatchers: ESMap<string, FileWatcher> | undefined;
let cache: ESMap<Path, ResolvedModuleSpecifierInfo> | undefined;
let currentKey: string | undefined;
const result: ts.ModuleSpecifierCache = {
const result: ModuleSpecifierCache = {
get(fromFileName, toFileName, preferences, options) {
if (!cache || currentKey !== key(fromFileName, preferences, options)) return undefined;
return cache.get(toFileName);
@@ -27,9 +30,9 @@ export function createModuleSpecifierCache(host: ModuleSpecifierResolutionCacheH
for (const p of modulePaths) {
if (p.isInNodeModules) {
// No trailing slash
const nodeModulesPath = p.path.substring(0, p.path.indexOf(ts.nodeModulesPathPart) + ts.nodeModulesPathPart.length - 1);
const nodeModulesPath = p.path.substring(0, p.path.indexOf(nodeModulesPathPart) + nodeModulesPathPart.length - 1);
if (!containedNodeModulesWatchers?.has(nodeModulesPath)) {
(containedNodeModulesWatchers ||= new ts.Map()).set(
(containedNodeModulesWatchers ||= new Map()).set(
nodeModulesPath,
host.watchNodeModulesForPackageJsonChanges(nodeModulesPath),
);
@@ -68,29 +71,29 @@ export function createModuleSpecifierCache(host: ModuleSpecifierResolutionCacheH
return cache ? cache.size : 0;
}
};
if (ts.Debug.isDebugging) {
if (Debug.isDebugging) {
Object.defineProperty(result, "__cache", { get: () => cache });
}
return result;
function ensureCache(fromFileName: ts.Path, preferences: ts.UserPreferences, options: ts.ModuleSpecifierOptions) {
function ensureCache(fromFileName: Path, preferences: UserPreferences, options: ModuleSpecifierOptions) {
const newKey = key(fromFileName, preferences, options);
if (cache && (currentKey !== newKey)) {
result.clear();
}
currentKey = newKey;
return cache ||= new ts.Map();
return cache ||= new Map();
}
function key(fromFileName: ts.Path, preferences: ts.UserPreferences, options: ts.ModuleSpecifierOptions) {
function key(fromFileName: Path, preferences: UserPreferences, options: ModuleSpecifierOptions) {
return `${fromFileName},${preferences.importModuleSpecifierEnding},${preferences.importModuleSpecifierPreference},${options.overrideImportMode}`;
}
function createInfo(
modulePaths: readonly ts.ModulePath[] | undefined,
modulePaths: readonly ModulePath[] | undefined,
moduleSpecifiers: readonly string[] | undefined,
isBlockedByPackageJsonDependencies: boolean | undefined,
): ts.ResolvedModuleSpecifierInfo {
): ResolvedModuleSpecifierInfo {
return { modulePaths, moduleSpecifiers, isBlockedByPackageJsonDependencies };
}
}