mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Add alias ResolutionMode for ModuleKind.ESNext | ModuleKind.CommonJs | undefined (#51482)
* Add alias ResolutionMode for ModuleKind.ESNext | ModuleKind.CommonJs | undefined * ResolutionMode | undefined = ResolutionMode * More
This commit is contained in:
parent
3eafb64faf
commit
c5aea89230
@ -3,7 +3,7 @@ import {
|
||||
ExportedModulesFromDeclarationEmit, GetCanonicalFileName, getDirectoryPath, getSourceFileOfNode,
|
||||
isDeclarationFileName, isExternalOrCommonJsModule, isGlobalScopeAugmentation, isJsonSourceFile,
|
||||
isModuleWithStringLiteralName, isStringLiteral, mapDefined, mapDefinedIterator, ModuleDeclaration,
|
||||
ModuleKind, outFile, OutputFile, Path, Program, some, SourceFile, StringLiteralLike, Symbol,
|
||||
ModuleKind, outFile, OutputFile, Path, Program, ResolutionMode, some, SourceFile, StringLiteralLike, Symbol,
|
||||
toPath, TypeChecker,
|
||||
} from "./_namespaces/ts";
|
||||
|
||||
@ -75,7 +75,7 @@ export namespace BuilderState {
|
||||
readonly version: string;
|
||||
signature: string | undefined;
|
||||
affectsGlobalScope: true | undefined;
|
||||
impliedFormat: SourceFile["impliedNodeFormat"];
|
||||
impliedFormat: ResolutionMode;
|
||||
}
|
||||
|
||||
export interface ReadonlyManyToManyPathMap {
|
||||
|
||||
@ -195,7 +195,7 @@ import {
|
||||
usingSingleLineStringWriter, VariableDeclaration, VariableDeclarationList, VariableLikeDeclaration,
|
||||
VariableStatement, VarianceFlags, visitEachChild, visitNode, visitNodes, Visitor, VisitResult, VoidExpression,
|
||||
walkUpBindingElementsAndPatterns, walkUpParenthesizedExpressions, walkUpParenthesizedTypes,
|
||||
walkUpParenthesizedTypesAndGetParentAndChild, WhileStatement, WideningContext, WithStatement, YieldExpression,
|
||||
walkUpParenthesizedTypesAndGetParentAndChild, WhileStatement, WideningContext, WithStatement, YieldExpression, ResolutionMode,
|
||||
} from "./_namespaces/ts";
|
||||
import * as performance from "./_namespaces/ts.performance";
|
||||
import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers";
|
||||
@ -2969,7 +2969,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return isStringLiteralLike(usage) ? getModeForUsageLocation(getSourceFileOfNode(usage), usage) : undefined;
|
||||
}
|
||||
|
||||
function isESMFormatImportImportingCommonjsFormatFile(usageMode: SourceFile["impliedNodeFormat"], targetMode: SourceFile["impliedNodeFormat"]) {
|
||||
function isESMFormatImportImportingCommonjsFormatFile(usageMode: ResolutionMode, targetMode: ResolutionMode) {
|
||||
return usageMode === ModuleKind.ESNext && targetMode === ModuleKind.CommonJS;
|
||||
}
|
||||
|
||||
@ -6559,7 +6559,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return top;
|
||||
}
|
||||
|
||||
function getSpecifierForModuleSymbol(symbol: Symbol, context: NodeBuilderContext, overrideImportMode?: SourceFile["impliedNodeFormat"]) {
|
||||
function getSpecifierForModuleSymbol(symbol: Symbol, context: NodeBuilderContext, overrideImportMode?: ResolutionMode) {
|
||||
let file = getDeclarationOfKind<SourceFile>(symbol, SyntaxKind.SourceFile);
|
||||
if (!file) {
|
||||
const equivalentFileSymbol = firstDefined(symbol.declarations, d => getFileSymbolIfFileSymbolExportEqualsContainer(d, symbol));
|
||||
@ -6623,7 +6623,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
return specifier;
|
||||
|
||||
function getSpecifierCacheKey(path: string, mode: SourceFile["impliedNodeFormat"] | undefined) {
|
||||
function getSpecifierCacheKey(path: string, mode: ResolutionMode | undefined) {
|
||||
return mode === undefined ? path : `${mode}|${path}`;
|
||||
}
|
||||
}
|
||||
@ -44091,10 +44091,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// this variable and functions that use it are deliberately moved here from the outer scope
|
||||
// to avoid scope pollution
|
||||
const resolvedTypeReferenceDirectives = host.getResolvedTypeReferenceDirectives();
|
||||
let fileToDirective: Map<string, [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined]>;
|
||||
let fileToDirective: Map<string, [specifier: string, mode: ResolutionMode | undefined]>;
|
||||
if (resolvedTypeReferenceDirectives) {
|
||||
// populate reverse mapping: file path -> type reference directive that was resolved to this file
|
||||
fileToDirective = new Map<string, [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined]>();
|
||||
fileToDirective = new Map<string, [specifier: string, mode: ResolutionMode | undefined]>();
|
||||
resolvedTypeReferenceDirectives.forEach((resolvedDirective, key, mode) => {
|
||||
if (!resolvedDirective || !resolvedDirective.resolvedFileName) {
|
||||
return;
|
||||
@ -44226,7 +44226,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
// defined here to avoid outer scope pollution
|
||||
function getTypeReferenceDirectivesForEntityName(node: EntityNameOrEntityNameExpression): [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined][] | undefined {
|
||||
function getTypeReferenceDirectivesForEntityName(node: EntityNameOrEntityNameExpression): [specifier: string, mode: ResolutionMode | undefined][] | undefined {
|
||||
// program does not have any files with type reference directives - bail out
|
||||
if (!fileToDirective) {
|
||||
return undefined;
|
||||
@ -44251,13 +44251,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
// defined here to avoid outer scope pollution
|
||||
function getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined][] | undefined {
|
||||
function getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): [specifier: string, mode: ResolutionMode | undefined][] | undefined {
|
||||
// program does not have any files with type reference directives - bail out
|
||||
if (!fileToDirective || !isSymbolFromTypeDeclarationFile(symbol)) {
|
||||
return undefined;
|
||||
}
|
||||
// check what declarations in the symbol can contribute to the target meaning
|
||||
let typeReferenceDirectives: [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined][] | undefined;
|
||||
let typeReferenceDirectives: [specifier: string, mode: ResolutionMode | undefined][] | undefined;
|
||||
for (const decl of symbol.declarations!) {
|
||||
// check meaning of the local symbol to see if declaration needs to be analyzed further
|
||||
if (decl.symbol && decl.symbol.flags & meaning!) {
|
||||
@ -44308,7 +44308,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return false;
|
||||
}
|
||||
|
||||
function addReferencedFilesToTypeDirective(file: SourceFile, key: string, mode: SourceFile["impliedNodeFormat"] | undefined) {
|
||||
function addReferencedFilesToTypeDirective(file: SourceFile, key: string, mode: ResolutionMode | undefined) {
|
||||
if (fileToDirective.has(file.path)) return;
|
||||
fileToDirective.set(file.path, [key, mode]);
|
||||
for (const { fileName, resolutionMode } of file.referencedFiles) {
|
||||
|
||||
@ -13,6 +13,7 @@ import {
|
||||
ModuleKind, ModuleResolutionHost, ModuleResolutionKind, noop, noopPush, normalizePath, normalizeSlashes,
|
||||
optionsHaveModuleResolutionChanges, PackageId, packageIdToString, ParsedCommandLine, Path, pathIsRelative, Pattern,
|
||||
patternText, perfLogger, Push, readJson, removeExtension, removeFileExtension, removePrefix,
|
||||
ResolutionMode,
|
||||
ResolvedModuleWithFailedLookupLocations, ResolvedProjectReference, ResolvedTypeReferenceDirective,
|
||||
ResolvedTypeReferenceDirectiveWithFailedLookupLocations, some, sort, SourceFile, startsWith, stringContains,
|
||||
StringLiteralLike, supportedTSExtensionsFlat, toFileNameLowerCase, toPath, tryExtractTSExtension, tryGetExtensionFromPath,
|
||||
@ -333,7 +334,7 @@ function arePathsEqual(path1: string, path2: string, host: ModuleResolutionHost)
|
||||
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
||||
* is assumed to be the same as root directory of the project.
|
||||
*/
|
||||
export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, cache?: TypeReferenceDirectiveResolutionCache, resolutionMode?: SourceFile["impliedNodeFormat"]): ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
|
||||
export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, cache?: TypeReferenceDirectiveResolutionCache, resolutionMode?: ResolutionMode): ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
|
||||
Debug.assert(typeof typeReferenceDirectiveName === "string", "Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.");
|
||||
const traceEnabled = isTraceEnabled(options, host);
|
||||
if (redirectedReference) {
|
||||
@ -571,11 +572,11 @@ export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResol
|
||||
}
|
||||
|
||||
export interface ModeAwareCache<T> {
|
||||
get(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): T | undefined;
|
||||
set(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, value: T): this;
|
||||
delete(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): this;
|
||||
has(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): boolean;
|
||||
forEach(cb: (elem: T, key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) => void): void;
|
||||
get(key: string, mode: ResolutionMode): T | undefined;
|
||||
set(key: string, mode: ResolutionMode, value: T): this;
|
||||
delete(key: string, mode: ResolutionMode): this;
|
||||
has(key: string, mode: ResolutionMode): boolean;
|
||||
forEach(cb: (elem: T, key: string, mode: ResolutionMode) => void): void;
|
||||
size(): number;
|
||||
}
|
||||
|
||||
@ -603,7 +604,7 @@ export interface ModuleResolutionCache extends PerDirectoryResolutionCache<Resol
|
||||
* We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive.
|
||||
*/
|
||||
export interface NonRelativeModuleNameResolutionCache extends PackageJsonInfoCache {
|
||||
getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache;
|
||||
getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ResolutionMode, redirectedReference?: ResolvedProjectReference): PerModuleNameCache;
|
||||
}
|
||||
|
||||
export interface PackageJsonInfoCache {
|
||||
@ -758,7 +759,7 @@ function createPerDirectoryResolutionCache<T>(currentDirectory: string, getCanon
|
||||
export function createModeAwareCache<T>(): ModeAwareCache<T> {
|
||||
const underlying = new Map<ModeAwareCacheKey, T>();
|
||||
type ModeAwareCacheKey = string & { __modeAwareCacheKey: any; };
|
||||
const memoizedReverseKeys = new Map<ModeAwareCacheKey, [specifier: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined]>();
|
||||
const memoizedReverseKeys = new Map<ModeAwareCacheKey, [specifier: string, mode: ResolutionMode]>();
|
||||
|
||||
const cache: ModeAwareCache<T> = {
|
||||
get(specifier, mode) {
|
||||
@ -787,7 +788,7 @@ export function createModeAwareCache<T>(): ModeAwareCache<T> {
|
||||
};
|
||||
return cache;
|
||||
|
||||
function getUnderlyingCacheKey(specifier: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) {
|
||||
function getUnderlyingCacheKey(specifier: string, mode: ResolutionMode) {
|
||||
const result = (mode === undefined ? specifier : `${mode}|${specifier}`) as ModeAwareCacheKey;
|
||||
memoizedReverseKeys.set(result, [specifier, mode]);
|
||||
return result;
|
||||
@ -864,7 +865,7 @@ export function createModuleResolutionCache(
|
||||
updateRedirectsMap(options, directoryToModuleNameMap!, moduleNameToDirectoryMap);
|
||||
}
|
||||
|
||||
function getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache {
|
||||
function getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ResolutionMode, redirectedReference?: ResolvedProjectReference): PerModuleNameCache {
|
||||
Debug.assert(!isExternalModuleNameRelative(nonRelativeModuleName));
|
||||
return getOrCreateCache(moduleNameToDirectoryMap!, redirectedReference, mode === undefined ? nonRelativeModuleName : `${mode}|${nonRelativeModuleName}`, createPerModuleNameCache);
|
||||
}
|
||||
@ -983,14 +984,14 @@ export function createTypeReferenceDirectiveResolutionCache(
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined {
|
||||
export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined {
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
const perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory);
|
||||
if (!perFolderCache) return undefined;
|
||||
return perFolderCache.get(moduleName, mode);
|
||||
}
|
||||
|
||||
export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations {
|
||||
export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations {
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
if (redirectedReference) {
|
||||
compilerOptions = redirectedReference.commandLine.options;
|
||||
@ -1312,7 +1313,7 @@ export enum NodeResolutionFeatures {
|
||||
|
||||
function node16ModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions,
|
||||
host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference,
|
||||
resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations {
|
||||
resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations {
|
||||
return nodeNextModuleNameResolverWorker(
|
||||
NodeResolutionFeatures.Node16Default,
|
||||
moduleName,
|
||||
@ -1327,7 +1328,7 @@ function node16ModuleNameResolver(moduleName: string, containingFile: string, co
|
||||
|
||||
function nodeNextModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions,
|
||||
host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference,
|
||||
resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations {
|
||||
resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations {
|
||||
return nodeNextModuleNameResolverWorker(
|
||||
NodeResolutionFeatures.NodeNextDefault,
|
||||
moduleName,
|
||||
@ -1344,7 +1345,7 @@ const jsOnlyExtensions = [Extensions.JavaScript];
|
||||
const tsExtensions = [Extensions.TypeScript, Extensions.JavaScript];
|
||||
const tsPlusJsonExtensions = [...tsExtensions, Extensions.Json];
|
||||
const tsconfigExtensions = [Extensions.TSConfig];
|
||||
function nodeNextModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations {
|
||||
function nodeNextModuleNameResolverWorker(features: NodeResolutionFeatures, moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations {
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
|
||||
// es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features
|
||||
|
||||
@ -16,7 +16,7 @@ import {
|
||||
ModuleSpecifierResolutionHost, NodeFlags, NodeModulePathParts, normalizePath, Path, pathContainsNodeModules,
|
||||
pathIsBareSpecifier, pathIsRelative, PropertyAccessExpression, removeFileExtension, removeSuffix, resolvePath,
|
||||
ScriptKind, some, SourceFile, startsWith, startsWithDirectory, stringContains, StringLiteral, Symbol, SymbolFlags,
|
||||
toPath, tryGetExtensionFromPath, tryParsePatterns, TypeChecker, UserPreferences,
|
||||
toPath, tryGetExtensionFromPath, tryParsePatterns, TypeChecker, UserPreferences, ResolutionMode,
|
||||
} from "./_namespaces/ts";
|
||||
|
||||
// Used by importFixes, getEditsForFileRename, and declaration emit to synthesize import module specifiers.
|
||||
@ -322,7 +322,7 @@ function getInfo(importingSourceFileName: Path, host: ModuleSpecifierResolutionH
|
||||
return { getCanonicalFileName, importingSourceFileName, sourceDirectory };
|
||||
}
|
||||
|
||||
function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOptions: CompilerOptions, host: ModuleSpecifierResolutionHost, importMode: SourceFile["impliedNodeFormat"], { ending, relativePreference }: Preferences): string {
|
||||
function getLocalModuleSpecifier(moduleFileName: string, info: Info, compilerOptions: CompilerOptions, host: ModuleSpecifierResolutionHost, importMode: ResolutionMode, { ending, relativePreference }: Preferences): string {
|
||||
const { baseUrl, paths, rootDirs } = compilerOptions;
|
||||
const { sourceDirectory, getCanonicalFileName } = info;
|
||||
const relativePath = rootDirs && tryGetModuleNameFromRootDirs(rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName, ending, compilerOptions) ||
|
||||
@ -589,7 +589,7 @@ function tryGetModuleNameFromAmbientModule(moduleSymbol: Symbol, checker: TypeCh
|
||||
}
|
||||
}
|
||||
|
||||
function getAllowedEndings(preferredEnding: Ending, compilerOptions: CompilerOptions, importMode: SourceFile["impliedNodeFormat"]) {
|
||||
function getAllowedEndings(preferredEnding: Ending, compilerOptions: CompilerOptions, importMode: ResolutionMode) {
|
||||
if (getEmitModuleResolutionKind(compilerOptions) >= ModuleResolutionKind.Node16 && importMode === ModuleKind.ESNext) {
|
||||
return [Ending.JsExtension];
|
||||
}
|
||||
@ -776,7 +776,7 @@ function tryGetModuleNameFromRootDirs(rootDirs: readonly string[], moduleFileNam
|
||||
: removeFileExtension(shortest);
|
||||
}
|
||||
|
||||
function tryGetModuleNameAsNodeModule({ path, isRedirect }: ModulePath, { getCanonicalFileName, sourceDirectory }: Info, importingSourceFile: SourceFile, host: ModuleSpecifierResolutionHost, options: CompilerOptions, userPreferences: UserPreferences, packageNameOnly?: boolean, overrideMode?: ModuleKind.ESNext | ModuleKind.CommonJS): string | undefined {
|
||||
function tryGetModuleNameAsNodeModule({ path, isRedirect }: ModulePath, { getCanonicalFileName, sourceDirectory }: Info, importingSourceFile: SourceFile, host: ModuleSpecifierResolutionHost, options: CompilerOptions, userPreferences: UserPreferences, packageNameOnly?: boolean, overrideMode?: ResolutionMode): string | undefined {
|
||||
if (!host.fileExists || !host.readFile) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ import {
|
||||
PragmaPseudoMap, PragmaPseudoMapEntry, PrefixUnaryExpression, PrefixUnaryOperator, PrimaryExpression,
|
||||
PrivateIdentifier, PropertyAccessEntityNameExpression, PropertyAccessExpression, PropertyAssignment,
|
||||
PropertyDeclaration, PropertyName, PropertySignature, QualifiedName, QuestionDotToken, QuestionToken,
|
||||
ReadonlyKeyword, ReadonlyPragmaMap, ReadonlyTextRange, RestTypeNode, ReturnStatement, SatisfiesExpression,
|
||||
ReadonlyKeyword, ReadonlyPragmaMap, ReadonlyTextRange, ResolutionMode, RestTypeNode, ReturnStatement, SatisfiesExpression,
|
||||
ScriptKind, ScriptTarget, SetAccessorDeclaration, setParent, setParentRecursive, setTextRange, setTextRangePos,
|
||||
setTextRangePosEnd, setTextRangePosWidth, ShorthandPropertyAssignment, skipTrivia, some, SourceFile,
|
||||
SpreadAssignment, SpreadElement, startsWith, Statement, StringLiteral, supportedDeclarationExtensions,
|
||||
@ -989,7 +989,7 @@ export interface CreateSourceFileOptions {
|
||||
* and files on disk, but needs to be done with a module resolution cache in scope to be performant.
|
||||
* This is usually `undefined` for compilations that do not have `moduleResolution` values of `node16` or `nodenext`.
|
||||
*/
|
||||
impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
/**
|
||||
* Controls how module-y-ness is set for the given file. Usually the result of calling
|
||||
* `getSetExternalModuleIndicator` on a valid `CompilerOptions` object. If not present, the default
|
||||
@ -9791,7 +9791,7 @@ export interface PragmaContext {
|
||||
moduleName?: string;
|
||||
}
|
||||
|
||||
function parseResolutionMode(mode: string | undefined, pos: number, end: number, reportDiagnostic: PragmaDiagnosticReporter): ModuleKind.ESNext | ModuleKind.CommonJS | undefined {
|
||||
function parseResolutionMode(mode: string | undefined, pos: number, end: number, reportDiagnostic: PragmaDiagnosticReporter): ResolutionMode {
|
||||
if (!mode) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ import {
|
||||
targetOptionDeclaration, toFileNameLowerCase, tokenToString, trace, tracing, trimStringEnd, TsConfigSourceFile,
|
||||
TypeChecker, typeDirectiveIsEqualTo, TypeReferenceDirectiveResolutionCache, UnparsedSource, VariableDeclaration,
|
||||
VariableStatement, walkUpParenthesizedExpressions, WriteFileCallback, WriteFileCallbackData,
|
||||
writeFileEnsuringDirectories, zipToModeAwareCache, TypeReferenceDirectiveResolutionInfo, getResolvedTypeReferenceDirective,
|
||||
writeFileEnsuringDirectories, zipToModeAwareCache, TypeReferenceDirectiveResolutionInfo, getResolvedTypeReferenceDirective, ResolutionMode,
|
||||
} from "./_namespaces/ts";
|
||||
import * as performance from "./_namespaces/ts.performance";
|
||||
|
||||
@ -253,7 +253,7 @@ export function changeCompilerHostLikeToUseCache(
|
||||
const readFileCache = new Map<Path, string | false>();
|
||||
const fileExistsCache = new Map<Path, boolean>();
|
||||
const directoryExistsCache = new Map<Path, boolean>();
|
||||
const sourceFileCache = new Map<SourceFile["impliedNodeFormat"], Map<Path, SourceFile>>();
|
||||
const sourceFileCache = new Map<ResolutionMode, Map<Path, SourceFile>>();
|
||||
|
||||
const readFileWithCache = (fileName: string): string | undefined => {
|
||||
const key = toPath(fileName);
|
||||
@ -280,7 +280,7 @@ export function changeCompilerHostLikeToUseCache(
|
||||
|
||||
const getSourceFileWithCache: CompilerHost["getSourceFile"] | undefined = getSourceFile ? (fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
|
||||
const key = toPath(fileName);
|
||||
const impliedNodeFormat: SourceFile["impliedNodeFormat"] = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.impliedNodeFormat : undefined;
|
||||
const impliedNodeFormat: ResolutionMode = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.impliedNodeFormat : undefined;
|
||||
const forImpliedNodeFormat = sourceFileCache.get(impliedNodeFormat);
|
||||
const value = forImpliedNodeFormat?.get(key);
|
||||
if (value) return value;
|
||||
@ -555,7 +555,7 @@ export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageCha
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function loadWithTypeDirectiveCache<T>(names: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, containingFileMode: SourceFile["impliedNodeFormat"], loader: (name: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined, resolutionMode: SourceFile["impliedNodeFormat"]) => T): T[] {
|
||||
export function loadWithTypeDirectiveCache<T>(names: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, containingFileMode: ResolutionMode, loader: (name: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined, resolutionMode: ResolutionMode) => T): T[] {
|
||||
if (names.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@ -587,14 +587,14 @@ export function loadWithTypeDirectiveCache<T>(names: string[] | readonly FileRef
|
||||
export interface SourceFileImportsList {
|
||||
/** @internal */ imports: SourceFile["imports"];
|
||||
/** @internal */ moduleAugmentations: SourceFile["moduleAugmentations"];
|
||||
impliedNodeFormat?: SourceFile["impliedNodeFormat"];
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly
|
||||
* provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file.
|
||||
*/
|
||||
export function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]) {
|
||||
export function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode) {
|
||||
return (isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode;
|
||||
}
|
||||
|
||||
@ -605,11 +605,11 @@ export function getModeForFileReference(ref: FileReference | string, containingF
|
||||
* @param file File to fetch the resolution mode within
|
||||
* @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations
|
||||
*/
|
||||
export function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
|
||||
export function getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
||||
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
|
||||
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined {
|
||||
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ResolutionMode;
|
||||
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ResolutionMode {
|
||||
if (file.impliedNodeFormat === undefined) return undefined;
|
||||
// we ensure all elements of file.imports and file.moduleAugmentations have the relevant parent pointers set during program setup,
|
||||
// so it's safe to use them even pre-bind
|
||||
@ -636,7 +636,7 @@ export function isExclusivelyTypeOnlyImportOrExport(decl: ImportDeclaration | Ex
|
||||
* @param usage The module reference string
|
||||
* @returns The final resolution mode of the import
|
||||
*/
|
||||
export function getModeForUsageLocation(file: { impliedNodeFormat?: SourceFile["impliedNodeFormat"] }, usage: StringLiteralLike) {
|
||||
export function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMode }, usage: StringLiteralLike) {
|
||||
if (file.impliedNodeFormat === undefined) return undefined;
|
||||
if ((isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent))) {
|
||||
const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
|
||||
@ -685,7 +685,7 @@ export function getResolutionModeOverrideForClause(clause: AssertClause | undefi
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function loadWithModeAwareCache<T>(names: readonly StringLiteralLike[] | readonly string[], containingFile: SourceFile, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined, resolutionInfo: ModuleResolutionInfo | undefined, loader: (name: string, resolverMode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined) => T): T[] {
|
||||
export function loadWithModeAwareCache<T>(names: readonly StringLiteralLike[] | readonly string[], containingFile: SourceFile, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined, resolutionInfo: ModuleResolutionInfo | undefined, loader: (name: string, resolverMode: ResolutionMode, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined) => T): T[] {
|
||||
if (names.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@ -931,7 +931,7 @@ export function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCom
|
||||
* @param options The compiler options to perform the analysis under - relevant options are `moduleResolution` and `traceResolution`
|
||||
* @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
|
||||
*/
|
||||
export function getImpliedNodeFormatForFile(fileName: Path, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ModuleKind.ESNext | ModuleKind.CommonJS | undefined {
|
||||
export function getImpliedNodeFormatForFile(fileName: Path, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ResolutionMode {
|
||||
const result = getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options);
|
||||
return typeof result === "object" ? result.impliedNodeFormat : result;
|
||||
}
|
||||
@ -1195,7 +1195,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
}
|
||||
else {
|
||||
moduleResolutionCache = createModuleResolutionCache(currentDirectory, getCanonicalFileName, options);
|
||||
const loader = (moduleName: string, resolverMode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined) =>
|
||||
const loader = (moduleName: string, resolverMode: ResolutionMode, containingFileName: string, redirectedReference: ResolvedProjectReference | undefined) =>
|
||||
resolveModuleName(moduleName, containingFileName, options, host, moduleResolutionCache, redirectedReference, resolverMode).resolvedModule;
|
||||
actualResolveModuleNamesWorker = (moduleNames, containingFile, containingFileName, redirectedReference, resolutionInfo) =>
|
||||
loadWithModeAwareCache(moduleNames, containingFile, containingFileName, redirectedReference, resolutionInfo, loader);
|
||||
@ -1205,7 +1205,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
typeDirectiveNames: string[] | readonly FileReference[],
|
||||
containingFile: string,
|
||||
redirectedReference: ResolvedProjectReference | undefined,
|
||||
containingFileMode: SourceFile["impliedNodeFormat"] | undefined,
|
||||
containingFileMode: ResolutionMode | undefined,
|
||||
resolutionInfo: TypeReferenceDirectiveResolutionInfo | undefined,
|
||||
) => (ResolvedTypeReferenceDirective | undefined)[];
|
||||
if (host.resolveTypeReferenceDirectives) {
|
||||
@ -1214,7 +1214,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
}
|
||||
else {
|
||||
typeReferenceDirectiveResolutionCache = createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache?.getPackageJsonInfoCache());
|
||||
const loader = (typesRef: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined, resolutionMode: SourceFile["impliedNodeFormat"] | undefined) => resolveTypeReferenceDirective(
|
||||
const loader = (typesRef: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined, resolutionMode: ResolutionMode | undefined) => resolveTypeReferenceDirective(
|
||||
typesRef,
|
||||
containingFile,
|
||||
options,
|
||||
@ -1581,7 +1581,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
return libs.length + 2;
|
||||
}
|
||||
|
||||
function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined {
|
||||
function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, mode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined {
|
||||
return moduleResolutionCache && resolveModuleNameFromCache(moduleName, containingFile, moduleResolutionCache, mode);
|
||||
}
|
||||
|
||||
@ -3342,7 +3342,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
|
||||
function processTypeReferenceDirective(
|
||||
typeReferenceDirective: string,
|
||||
mode: SourceFile["impliedNodeFormat"] | undefined,
|
||||
mode: ResolutionMode | undefined,
|
||||
resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined,
|
||||
reason: FileIncludeReason
|
||||
): void {
|
||||
@ -3353,7 +3353,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
|
||||
function processTypeReferenceDirectiveWorker(
|
||||
typeReferenceDirective: string,
|
||||
mode: SourceFile["impliedNodeFormat"] | undefined,
|
||||
mode: ResolutionMode | undefined,
|
||||
resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined,
|
||||
reason: FileIncludeReason
|
||||
): void {
|
||||
|
||||
@ -9,10 +9,10 @@ import {
|
||||
getModeForUsageLocation, getNormalizedAbsolutePath, getResolutionName, getRootLength, HasInvalidatedResolutions,
|
||||
ignoredPaths, inferredTypesContainingFile, isEmittedFileOfProgram, isExternalModuleNameRelative,
|
||||
isExternalOrCommonJsModule, isNodeModulesDirectory, isRootedDiskPath, isString, isStringLiteralLike, isTraceEnabled,
|
||||
length, loadModuleFromGlobalCache, memoize, MinimalResolutionCacheHost, ModeAwareCache, ModuleKind,
|
||||
length, loadModuleFromGlobalCache, memoize, MinimalResolutionCacheHost, ModeAwareCache,
|
||||
ModuleResolutionCache, ModuleResolutionHost, ModuleResolutionInfo, mutateMap, noopFileWatcher, normalizePath,
|
||||
PackageId, packageIdToString, parseNodeModuleFromPath, Path, pathContainsNodeModules, PerModuleNameCache, Program,
|
||||
removeSuffix, removeTrailingDirectorySeparator, resolutionExtensionIsTSOrJson, ResolvedModuleFull,
|
||||
removeSuffix, removeTrailingDirectorySeparator, resolutionExtensionIsTSOrJson, ResolutionMode, ResolvedModuleFull,
|
||||
ResolvedModuleWithFailedLookupLocations, ResolvedProjectReference, ResolvedTypeReferenceDirective,
|
||||
ResolvedTypeReferenceDirectiveWithFailedLookupLocations, returnTrue, some, SourceFile, startsWith,
|
||||
stringContains, trace, TypeReferenceDirectiveResolutionInfo, unorderedRemoveItem, WatchDirectoryFlags,
|
||||
@ -35,12 +35,12 @@ export interface ResolutionCache {
|
||||
containingSourceFile: SourceFile | undefined,
|
||||
resolutionInfo: ModuleResolutionInfo | undefined
|
||||
): (ResolvedModuleFull | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): CachedResolvedModuleWithFailedLookupLocations | undefined;
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ResolutionMode): CachedResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives(
|
||||
typeDirectiveNames: string[] | readonly FileReference[],
|
||||
containingFile: string,
|
||||
redirectedReference: ResolvedProjectReference | undefined,
|
||||
containingFileMode: SourceFile["impliedNodeFormat"] | undefined,
|
||||
containingFileMode: ResolutionMode,
|
||||
resolutionInfo: TypeReferenceDirectiveResolutionInfo | undefined,
|
||||
): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
|
||||
@ -404,7 +404,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
hasChangedAutomaticTypeDirectiveNames = false;
|
||||
}
|
||||
|
||||
function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, _containingSourceFile?: never, mode?: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): CachedResolvedModuleWithFailedLookupLocations {
|
||||
function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, _containingSourceFile?: never, mode?: ResolutionMode): CachedResolvedModuleWithFailedLookupLocations {
|
||||
const primaryResult = ts.resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode);
|
||||
// return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
|
||||
if (!resolutionHost.getGlobalCache) {
|
||||
@ -437,7 +437,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
return primaryResult;
|
||||
}
|
||||
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, _containingSourceFile?: SourceFile, resolutionMode?: SourceFile["impliedNodeFormat"] | undefined): CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations {
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, _containingSourceFile?: SourceFile, resolutionMode?: ResolutionMode): CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations {
|
||||
return ts.resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference, typeReferenceDirectiveResolutionCache, resolutionMode);
|
||||
}
|
||||
|
||||
@ -447,14 +447,14 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
redirectedReference: ResolvedProjectReference | undefined;
|
||||
cache: Map<Path, ModeAwareCache<T>>;
|
||||
perDirectoryCacheWithRedirects: CacheWithRedirects<ModeAwareCache<T>>;
|
||||
loader: (name: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, containingSourceFile?: SourceFile, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) => T;
|
||||
loader: (name: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, containingSourceFile?: SourceFile, resolutionMode?: ResolutionMode) => T;
|
||||
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>;
|
||||
shouldRetryResolution: (t: T) => boolean;
|
||||
reusedNames?: readonly string[];
|
||||
resolutionInfo?: ModuleResolutionInfo | TypeReferenceDirectiveResolutionInfo;
|
||||
logChanges?: boolean;
|
||||
containingSourceFile?: SourceFile;
|
||||
containingSourceFileMode?: SourceFile["impliedNodeFormat"];
|
||||
containingSourceFileMode?: ResolutionMode;
|
||||
}
|
||||
function resolveNamesWithLocalCache<T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName>({
|
||||
names, containingFile, redirectedReference,
|
||||
@ -627,7 +627,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
typeDirectiveNames: string[] | readonly FileReference[],
|
||||
containingFile: string,
|
||||
redirectedReference?: ResolvedProjectReference,
|
||||
containingFileMode?: SourceFile["impliedNodeFormat"],
|
||||
containingFileMode?: ResolutionMode,
|
||||
resolutionInfo?: TypeReferenceDirectiveResolutionInfo,
|
||||
): (ResolvedTypeReferenceDirective | undefined)[] {
|
||||
return resolveNamesWithLocalCache<CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations, ResolvedTypeReferenceDirective>({
|
||||
@ -668,7 +668,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
});
|
||||
}
|
||||
|
||||
function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): CachedResolvedModuleWithFailedLookupLocations | undefined {
|
||||
function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ResolutionMode): CachedResolvedModuleWithFailedLookupLocations | undefined {
|
||||
const cache = resolvedModuleNames.get(resolutionHost.toPath(containingFile));
|
||||
if (!cache) return undefined;
|
||||
return cache.get(moduleName, resolutionMode);
|
||||
|
||||
@ -31,7 +31,7 @@ import {
|
||||
ModifierFlags, ModuleBody, ModuleDeclaration, NamedDeclaration, NamespaceDeclaration,
|
||||
needsScopeMarker, Node, NodeArray, NodeBuilderFlags, NodeFlags, NodeId, normalizeSlashes, OmittedExpression,
|
||||
orderedRemoveItem, ParameterDeclaration, parseNodeFactory, pathContainsNodeModules, pathIsRelative,
|
||||
PropertyDeclaration, PropertySignature, pushIfUnique, removeAllComments, SetAccessorDeclaration,
|
||||
PropertyDeclaration, PropertySignature, pushIfUnique, removeAllComments, ResolutionMode, SetAccessorDeclaration,
|
||||
setCommentRange, setEmitFlags, setOriginalNode, setParent, setTextRange, SignatureDeclaration, skipTrivia, some,
|
||||
SourceFile, startsWith, Statement, stringContains, StringLiteral, Symbol, SymbolAccessibility,
|
||||
SymbolAccessibilityResult, SymbolFlags, SymbolTracker, SyntaxKind, toFileNameLowerCase, toPath,
|
||||
@ -103,7 +103,7 @@ export function transformDeclarations(context: TransformationContext) {
|
||||
let needsScopeFixMarker = false;
|
||||
let resultHasScopeMarker = false;
|
||||
let enclosingDeclaration: Node;
|
||||
let necessaryTypeReferences: Set<[specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined]> | undefined;
|
||||
let necessaryTypeReferences: Set<[specifier: string, mode: ResolutionMode]> | undefined;
|
||||
let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined;
|
||||
let lateStatementReplacementMap: Map<NodeId, VisitResult<LateVisibilityPaintedStatement | ExportAssignment>>;
|
||||
let suppressNewDiagnosticContexts: boolean;
|
||||
@ -138,7 +138,7 @@ export function transformDeclarations(context: TransformationContext) {
|
||||
const { noResolve, stripInternal } = options;
|
||||
return transformRoot;
|
||||
|
||||
function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: readonly [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined][] | undefined): void {
|
||||
function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: readonly [specifier: string, mode: ResolutionMode][] | undefined): void {
|
||||
if (!typeReferenceDirectives) {
|
||||
return;
|
||||
}
|
||||
@ -408,7 +408,7 @@ export function transformDeclarations(context: TransformationContext) {
|
||||
return necessaryTypeReferences ? mapDefined(arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : [];
|
||||
}
|
||||
|
||||
function getFileReferenceForSpecifierModeTuple([typeName, mode]: [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined]): FileReference | undefined {
|
||||
function getFileReferenceForSpecifierModeTuple([typeName, mode]: [specifier: string, mode: ResolutionMode]): FileReference | undefined {
|
||||
// Elide type references for which we have imports
|
||||
if (emittedImports) {
|
||||
for (const importStatement of emittedImports) {
|
||||
|
||||
@ -15,10 +15,11 @@ import {
|
||||
getLocaleTimeString, getNormalizedAbsolutePath, getParsedCommandLineOfConfigFile, getPendingEmitKind,
|
||||
getSourceFileVersionAsHashFromText, getTsBuildInfoEmitOutputFilePath, getWatchErrorSummaryDiagnosticMessage,
|
||||
hasProperty, identity, isArray, isIgnoredFileFromWildCardWatching, isIncrementalCompilation, isString, listFiles,
|
||||
loadWithModeAwareCache, loadWithTypeDirectiveCache, map, maybeBind, missingFileModifiedTime, ModuleKind,
|
||||
loadWithModeAwareCache, loadWithTypeDirectiveCache, map, maybeBind, missingFileModifiedTime,
|
||||
ModuleResolutionCache, mutateMap, mutateMapSkippingNewValues, noop, outFile, OutputFile, ParseConfigFileHost,
|
||||
parseConfigHostFromCompilerHostLike, ParsedCommandLine, Path, PollingInterval, Program, ProgramBuildInfo,
|
||||
ProgramBundleEmitBuildInfo, ProgramHost, ProgramMultiFileEmitBuildInfo, readBuilderProgram, ReadBuildProgramHost,
|
||||
ResolutionMode,
|
||||
resolveConfigFileProjectName, ResolvedConfigFileName, ResolvedProjectReference, ResolvedTypeReferenceDirective,
|
||||
resolveModuleName, resolvePath, resolveProjectReferencePath, resolveTypeReferenceDirective, returnUndefined,
|
||||
SemanticDiagnosticsBuilderProgram, setGetSourceFileAsHashVersioned, SharedExtendedConfigFileWatcher, some,
|
||||
@ -339,14 +340,14 @@ function createSolutionBuilderState<T extends BuilderProgram>(watch: boolean, ho
|
||||
const moduleResolutionCache = !compilerHost.resolveModuleNames ? createModuleResolutionCache(currentDirectory, getCanonicalFileName) : undefined;
|
||||
const typeReferenceDirectiveResolutionCache = !compilerHost.resolveTypeReferenceDirectives ? createTypeReferenceDirectiveResolutionCache(currentDirectory, getCanonicalFileName, /*options*/ undefined, moduleResolutionCache?.getPackageJsonInfoCache()) : undefined;
|
||||
if (!compilerHost.resolveModuleNames) {
|
||||
const loader = (moduleName: string, resolverMode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) =>
|
||||
const loader = (moduleName: string, resolverMode: ResolutionMode, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) =>
|
||||
resolveModuleName(moduleName, containingFile, state.projectCompilerOptions, compilerHost, moduleResolutionCache, redirectedReference, resolverMode).resolvedModule;
|
||||
compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, _options, containingSourceFile, resolutionInfo) =>
|
||||
loadWithModeAwareCache(Debug.checkEachDefined(moduleNames), Debug.checkDefined(containingSourceFile), containingFile, redirectedReference, resolutionInfo, loader);
|
||||
compilerHost.getModuleResolutionCache = () => moduleResolutionCache;
|
||||
}
|
||||
if (!compilerHost.resolveTypeReferenceDirectives) {
|
||||
const loader = (moduleName: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined, containingFileMode: SourceFile["impliedNodeFormat"] | undefined) => resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache, containingFileMode).resolvedTypeReferenceDirective!;
|
||||
const loader = (moduleName: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined, containingFileMode: ResolutionMode) => resolveTypeReferenceDirective(moduleName, containingFile, state.projectCompilerOptions, compilerHost, redirectedReference, state.typeReferenceDirectiveResolutionCache, containingFileMode).resolvedTypeReferenceDirective!;
|
||||
compilerHost.resolveTypeReferenceDirectives = (typeReferenceDirectiveNames, containingFile, redirectedReference, _options, containingFileMode) =>
|
||||
loadWithTypeDirectiveCache<ResolvedTypeReferenceDirective>(Debug.checkEachDefined(typeReferenceDirectiveNames), containingFile, redirectedReference, containingFileMode, loader);
|
||||
}
|
||||
|
||||
@ -3588,7 +3588,7 @@ export interface ExportAssignment extends DeclarationStatement, JSDocContainer {
|
||||
|
||||
export interface FileReference extends TextRange {
|
||||
fileName: string;
|
||||
resolutionMode?: SourceFile["impliedNodeFormat"];
|
||||
resolutionMode?: ResolutionMode;
|
||||
}
|
||||
|
||||
export interface CheckJsDirective extends TextRange {
|
||||
@ -3968,6 +3968,8 @@ export interface RedirectInfo {
|
||||
readonly unredirected: SourceFile;
|
||||
}
|
||||
|
||||
export type ResolutionMode = ModuleKind.ESNext | ModuleKind.CommonJS | undefined;
|
||||
|
||||
// Source files are declarations when they are external modules.
|
||||
export interface SourceFile extends Declaration {
|
||||
readonly kind: SyntaxKind.SourceFile;
|
||||
@ -4044,7 +4046,7 @@ export interface SourceFile extends Declaration {
|
||||
* of `node`). If so, this field will be unset and source files will be considered to be
|
||||
* CommonJS-output-format by the node module transformer and type checker, regardless of extension or context.
|
||||
*/
|
||||
impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
/** @internal */ packageJsonLocations?: readonly string[];
|
||||
/** @internal */ packageJsonScope?: PackageJsonInfo;
|
||||
|
||||
@ -4506,7 +4508,7 @@ export interface Program extends ScriptReferenceHost {
|
||||
/** @internal */ getFileIncludeReasons(): MultiMap<Path, FileIncludeReason>;
|
||||
/** @internal */ useCaseSensitiveFileNames(): boolean;
|
||||
|
||||
/** @internal */ getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
/** @internal */ getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, mode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
|
||||
getProjectReferences(): readonly ProjectReference[] | undefined;
|
||||
getResolvedProjectReferences(): readonly (ResolvedProjectReference | undefined)[] | undefined;
|
||||
@ -5328,8 +5330,8 @@ export interface EmitResolver {
|
||||
moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean;
|
||||
isArgumentsLocalBinding(node: Identifier): boolean;
|
||||
getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode | ImportCall): SourceFile | undefined;
|
||||
getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined][] | undefined;
|
||||
getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined][] | undefined;
|
||||
getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): [specifier: string, mode: ResolutionMode | undefined][] | undefined;
|
||||
getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): [specifier: string, mode: ResolutionMode | undefined][] | undefined;
|
||||
isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean;
|
||||
getJsxFactoryEntity(location?: Node): EntityName | undefined;
|
||||
getJsxFragmentFactoryEntity(location?: Node): EntityName | undefined;
|
||||
@ -7326,7 +7328,7 @@ export interface CompilerHost extends ModuleResolutionHost {
|
||||
/**
|
||||
* This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
|
||||
*/
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getEnvironmentVariable?(name: string): string | undefined;
|
||||
/** @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions, hasSourceFileByPath: boolean): void;
|
||||
/** @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, optionOptions: CompilerOptions): void;
|
||||
@ -9074,7 +9076,7 @@ export interface ResolvedModuleSpecifierInfo {
|
||||
|
||||
/** @internal */
|
||||
export interface ModuleSpecifierOptions {
|
||||
overrideImportMode?: SourceFile["impliedNodeFormat"];
|
||||
overrideImportMode?: ResolutionMode;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@ -90,7 +90,7 @@ import {
|
||||
TypePredicate, TypePredicateKind, TypeReferenceNode, unescapeLeadingUnderscores, UnionOrIntersectionTypeNode,
|
||||
ValidImportTypeNode, VariableDeclaration, VariableDeclarationInitializedTo, VariableDeclarationList,
|
||||
VariableLikeDeclaration, VariableStatement, version, WhileStatement, WithStatement, WriteFileCallback,
|
||||
WriteFileCallbackData, YieldExpression,
|
||||
WriteFileCallbackData, YieldExpression, ResolutionMode,
|
||||
} from "./_namespaces/ts";
|
||||
|
||||
/** @internal */
|
||||
@ -277,12 +277,12 @@ export function getFullWidth(node: Node) {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getResolvedModule(sourceFile: SourceFile | undefined, moduleNameText: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): ResolvedModuleFull | undefined {
|
||||
export function getResolvedModule(sourceFile: SourceFile | undefined, moduleNameText: string, mode: ResolutionMode): ResolvedModuleFull | undefined {
|
||||
return sourceFile && sourceFile.resolvedModules && sourceFile.resolvedModules.get(moduleNameText, mode);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function setResolvedModule(sourceFile: SourceFile, moduleNameText: string, resolvedModule: ResolvedModuleFull | undefined, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): void {
|
||||
export function setResolvedModule(sourceFile: SourceFile, moduleNameText: string, resolvedModule: ResolvedModuleFull | undefined, mode: ResolutionMode): void {
|
||||
if (!sourceFile.resolvedModules) {
|
||||
sourceFile.resolvedModules = createModeAwareCache();
|
||||
}
|
||||
@ -291,7 +291,7 @@ export function setResolvedModule(sourceFile: SourceFile, moduleNameText: string
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function setResolvedTypeReferenceDirective(sourceFile: SourceFile, typeReferenceDirectiveName: string, resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): void {
|
||||
export function setResolvedTypeReferenceDirective(sourceFile: SourceFile, typeReferenceDirectiveName: string, resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined, mode: ResolutionMode): void {
|
||||
if (!sourceFile.resolvedTypeReferenceDirectiveNames) {
|
||||
sourceFile.resolvedTypeReferenceDirectiveNames = createModeAwareCache();
|
||||
}
|
||||
@ -300,7 +300,7 @@ export function setResolvedTypeReferenceDirective(sourceFile: SourceFile, typeRe
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function getResolvedTypeReferenceDirective(sourceFile: SourceFile | undefined, typeReferenceDirectiveName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): ResolvedTypeReferenceDirective | undefined {
|
||||
export function getResolvedTypeReferenceDirective(sourceFile: SourceFile | undefined, typeReferenceDirectiveName: string, mode: ResolutionMode): ResolvedTypeReferenceDirective | undefined {
|
||||
return sourceFile?.resolvedTypeReferenceDirectiveNames?.get(typeReferenceDirectiveName, mode);
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import {
|
||||
getNormalizedAbsolutePath, getParsedCommandLineOfConfigFile, getTsBuildInfoEmitOutputFilePath,
|
||||
HasInvalidatedResolutions, isArray, isIgnoredFileFromWildCardWatching, isProgramUptoDate, MapLike, maybeBind,
|
||||
ModuleResolutionCache, ModuleResolutionInfo, noop, noopFileWatcher, parseConfigHostFromCompilerHostLike,
|
||||
ParsedCommandLine, Path, perfLogger, PollingInterval, ProjectReference, ResolutionCacheHost, ResolvedModule,
|
||||
ParsedCommandLine, Path, perfLogger, PollingInterval, ProjectReference, ResolutionCacheHost, ResolutionMode, ResolvedModule,
|
||||
ResolvedProjectReference, ResolvedTypeReferenceDirective, returnFalse, returnTrue, ScriptTarget,
|
||||
setGetSourceFileAsHashVersioned, SharedExtendedConfigFileWatcher, SourceFile, sys, System, toPath,
|
||||
TypeReferenceDirectiveResolutionInfo,
|
||||
@ -135,7 +135,7 @@ export interface ProgramHost<T extends BuilderProgram> {
|
||||
/** If provided, used to resolve the module names, otherwise typescript's default module resolution */
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile, resolutionInfo?: ModuleResolutionInfo): (ResolvedModule | undefined)[];
|
||||
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
/**
|
||||
|
||||
@ -19,11 +19,11 @@ import {
|
||||
getNormalizedAbsolutePath, getOrUpdate, getStringComparer, HasInvalidatedResolutions, HostCancellationToken,
|
||||
inferredTypesContainingFile, InstallPackageOptions, IScriptSnapshot, isDeclarationFileName,
|
||||
isExternalModuleNameRelative, isInsideNodeModules, JsTyping, LanguageService, LanguageServiceHost,
|
||||
LanguageServiceMode, map, mapDefined, maybeBind, ModuleKind, ModuleResolutionCache, ModuleResolutionHost,
|
||||
LanguageServiceMode, map, mapDefined, maybeBind, ModuleResolutionCache, ModuleResolutionHost,
|
||||
ModuleResolutionInfo, noop, noopFileWatcher, normalizePath, normalizeSlashes, orderedRemoveItem, outFile,
|
||||
PackageJsonAutoImportPreference, PackageJsonInfo, ParsedCommandLine, parsePackageName, Path, perfLogger,
|
||||
PerformanceEvent, PluginImport, PollingInterval, Program, ProjectPackageJsonInfo, ProjectReference,
|
||||
removeFileExtension, ResolutionCache, resolutionExtensionIsTSOrJson, ResolvedModuleFull,
|
||||
removeFileExtension, ResolutionCache, resolutionExtensionIsTSOrJson, ResolutionMode, ResolvedModuleFull,
|
||||
ResolvedModuleWithFailedLookupLocations, ResolvedProjectReference, ResolvedTypeReferenceDirective,
|
||||
resolvePackageNameToPackageJson, returnFalse, returnTrue, ScriptKind, some, sort, sortAndDeduplicate,
|
||||
SortedReadonlyArray, SourceFile, SourceMapper, startsWith, stripQuotes, StructureIsReused, SymlinkCache,
|
||||
@ -551,11 +551,11 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
|
||||
return this.resolutionCache.getModuleResolutionCache();
|
||||
}
|
||||
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined {
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined {
|
||||
return this.resolutionCache.getResolvedModuleWithFailedLookupLocationsFromCache(moduleName, containingFile, resolutionMode);
|
||||
}
|
||||
|
||||
resolveTypeReferenceDirectives(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference?: ResolvedProjectReference, _options?: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[] {
|
||||
resolveTypeReferenceDirectives(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference?: ResolvedProjectReference, _options?: CompilerOptions, containingFileMode?: ResolutionMode, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[] {
|
||||
return this.resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference, containingFileMode, resolutionInfo);
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import {
|
||||
arrayFrom, CompilerOptions, createGetCanonicalFileName, createLanguageServiceSourceFile, CreateSourceFileOptions,
|
||||
Debug, ensureScriptKind, firstDefinedIterator, forEachEntry, getCompilerOptionValue, getEmitScriptTarget,
|
||||
getImpliedNodeFormatForFile, getOrUpdate, getSetExternalModuleIndicator, hasProperty, identity, isArray,
|
||||
IScriptSnapshot, isDeclarationFileName, map, MinimalResolutionCacheHost, ModuleKind, Path, ScriptKind,
|
||||
IScriptSnapshot, isDeclarationFileName, map, MinimalResolutionCacheHost, Path, ResolutionMode, ScriptKind,
|
||||
ScriptTarget, SourceFile, sourceFileAffectingCompilerOptions, toPath, tracing, updateLanguageServiceSourceFile,
|
||||
} from "./_namespaces/ts";
|
||||
|
||||
@ -119,11 +119,11 @@ export interface DocumentRegistry {
|
||||
* @param scriptKind The script kind of the file to be released
|
||||
* @param impliedNodeFormat The implied source file format of the file to be released
|
||||
*/
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: SourceFile["impliedNodeFormat"]): void; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode): void; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
/**
|
||||
* @deprecated pass scriptKind for and impliedNodeFormat correctness */
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind?: ScriptKind): void;
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind: ScriptKind, impliedNodeFormat: SourceFile["impliedNodeFormat"]): void; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode): void; // eslint-disable-line @typescript-eslint/unified-signatures
|
||||
|
||||
/** @internal */
|
||||
getLanguageServiceRefCounts(path: Path, scriptKind: ScriptKind): [string, number | undefined][];
|
||||
@ -335,13 +335,13 @@ export function createDocumentRegistryInternal(useCaseSensitiveFileNames?: boole
|
||||
}
|
||||
}
|
||||
|
||||
function releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind?: ScriptKind, impliedNodeFormat?: SourceFile["impliedNodeFormat"]): void {
|
||||
function releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind?: ScriptKind, impliedNodeFormat?: ResolutionMode): void {
|
||||
const path = toPath(fileName, currentDirectory, getCanonicalFileName);
|
||||
const key = getKeyForCompilationSettings(compilationSettings);
|
||||
return releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat);
|
||||
}
|
||||
|
||||
function releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind?: ScriptKind, impliedNodeFormat?: SourceFile["impliedNodeFormat"]): void {
|
||||
function releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind?: ScriptKind, impliedNodeFormat?: ResolutionMode): void {
|
||||
const bucket = Debug.checkDefined(buckets.get(getDocumentRegistryBucketKeyWithMode(key, impliedNodeFormat)));
|
||||
const bucketEntry = bucket.get(path)!;
|
||||
const entry = getDocumentRegistryEntry(bucketEntry, scriptKind)!;
|
||||
@ -402,6 +402,6 @@ function getKeyForCompilationSettings(settings: CompilerOptions): DocumentRegist
|
||||
return sourceFileAffectingCompilerOptions.map(option => compilerOptionValueToString(getCompilerOptionValue(settings, option))).join("|") + (settings.pathsBasePath ? `|${settings.pathsBasePath}` : undefined) as DocumentRegistryBucketKey;
|
||||
}
|
||||
|
||||
function getDocumentRegistryBucketKeyWithMode(key: DocumentRegistryBucketKey, mode: ModuleKind.ESNext | ModuleKind.CommonJS | undefined) {
|
||||
function getDocumentRegistryBucketKeyWithMode(key: DocumentRegistryBucketKey, mode: ResolutionMode) {
|
||||
return (mode ? `${key}|${mode}` : key) as DocumentRegistryBucketKeyWithMode;
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ import {
|
||||
isStringLiteral, isStringLiteralLike, isTypeReferenceNode, isUrl, JsxAttribute, LanguageServiceHost,
|
||||
length, LiteralExpression, LiteralTypeNode, mapDefined, MapLike, ModuleKind, ModuleResolutionKind,
|
||||
moduleSpecifiers, Node, normalizePath, normalizeSlashes, ObjectLiteralExpression, Path, Program, PropertyAssignment,
|
||||
rangeContainsPosition, readJson, removeFileExtension, removePrefix, removeTrailingDirectorySeparator, resolvePath,
|
||||
rangeContainsPosition, readJson, removeFileExtension, removePrefix, removeTrailingDirectorySeparator, ResolutionMode, resolvePath,
|
||||
ScriptElementKind, ScriptElementKindModifier, ScriptTarget, Signature, signatureHasRestParameter, SignatureHelp,
|
||||
singleElementArray, skipConstraint, skipParentheses, SourceFile, startsWith, stringContains, StringLiteralLike,
|
||||
StringLiteralType, stripQuotes, Symbol, SyntaxKind, textPart, TextSpan, tryAndIgnoreErrors, tryDirectoryExists,
|
||||
@ -660,7 +660,7 @@ function addCompletionEntriesFromPathsOrExports(
|
||||
function getCompletionEntriesForNonRelativeModules(
|
||||
fragment: string,
|
||||
scriptPath: string,
|
||||
mode: SourceFile["impliedNodeFormat"],
|
||||
mode: ResolutionMode,
|
||||
compilerOptions: CompilerOptions,
|
||||
host: LanguageServiceHost,
|
||||
includeExtensionsOption: IncludeExtensionsOption,
|
||||
|
||||
@ -2,8 +2,8 @@ import {
|
||||
CancellationToken, CompilerHost, CompilerOptions, CustomTransformers, Diagnostic, DiagnosticWithLocation,
|
||||
DocumentHighlights, DocumentPositionMapper, EmitOutput, ExportInfoMap, FileReference,
|
||||
GetEffectiveTypeRootsHost, HasChangedAutomaticTypeDirectiveNames, HasInvalidatedResolutions, LineAndCharacter,
|
||||
MinimalResolutionCacheHost, ModuleKind, ModuleResolutionCache, ModuleResolutionInfo, ModuleSpecifierCache,
|
||||
ParsedCommandLine, Path, Program, ProjectReference, ResolvedModule, ResolvedModuleWithFailedLookupLocations,
|
||||
MinimalResolutionCacheHost, ModuleResolutionCache, ModuleResolutionInfo, ModuleSpecifierCache,
|
||||
ParsedCommandLine, Path, Program, ProjectReference, ResolutionMode, ResolvedModule, ResolvedModuleWithFailedLookupLocations,
|
||||
ResolvedProjectReference, ResolvedTypeReferenceDirective, ScriptKind, SourceFile, SourceFileLike, SourceMapper,
|
||||
Symbol, SymlinkCache, TextChangeRange, textChanges, TextRange, TextSpan, TypeReferenceDirectiveResolutionInfo, UserPreferences,
|
||||
} from "./_namespaces/ts";
|
||||
@ -324,8 +324,8 @@ export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalR
|
||||
* If this is implemented, `getResolvedModuleWithFailedLookupLocationsFromCache` should be too.
|
||||
*/
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile, resolutionInfo?: ModuleResolutionInfo): (ResolvedModule | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/** @internal */ hasInvalidatedResolutions?: HasInvalidatedResolutions;
|
||||
/** @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
|
||||
/** @internal */ getGlobalTypingsCacheLocation?(): string | undefined;
|
||||
|
||||
@ -3185,8 +3185,8 @@ declare namespace ts {
|
||||
fileExists(file: string): boolean;
|
||||
resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference, _options?: CompilerOptions, containingSourceFile?: SourceFile, resolutionInfo?: ModuleResolutionInfo): (ResolvedModuleFull | undefined)[];
|
||||
getModuleResolutionCache(): ModuleResolutionCache | undefined;
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference?: ResolvedProjectReference, _options?: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference?: ResolvedProjectReference, _options?: CompilerOptions, containingFileMode?: ResolutionMode, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
directoryExists(path: string): boolean;
|
||||
getDirectories(path: string): string[];
|
||||
log(s: string): void;
|
||||
@ -5761,7 +5761,7 @@ declare namespace ts {
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
fileName: string;
|
||||
resolutionMode?: SourceFile["impliedNodeFormat"];
|
||||
resolutionMode?: ResolutionMode;
|
||||
}
|
||||
interface CheckJsDirective extends TextRange {
|
||||
enabled: boolean;
|
||||
@ -6039,6 +6039,7 @@ declare namespace ts {
|
||||
interface SourceFileLike {
|
||||
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
|
||||
}
|
||||
type ResolutionMode = ModuleKind.ESNext | ModuleKind.CommonJS | undefined;
|
||||
interface SourceFile extends Declaration {
|
||||
readonly kind: SyntaxKind.SourceFile;
|
||||
readonly statements: NodeArray<Statement>;
|
||||
@ -6079,7 +6080,7 @@ declare namespace ts {
|
||||
* of `node`). If so, this field will be unset and source files will be considered to be
|
||||
* CommonJS-output-format by the node module transformer and type checker, regardless of extension or context.
|
||||
*/
|
||||
impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
}
|
||||
interface SourceFile {
|
||||
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
|
||||
@ -7343,7 +7344,7 @@ declare namespace ts {
|
||||
/**
|
||||
* This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
|
||||
*/
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getEnvironmentVariable?(name: string): string | undefined;
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
@ -9073,7 +9074,7 @@ declare namespace ts {
|
||||
* and files on disk, but needs to be done with a module resolution cache in scope to be performant.
|
||||
* This is usually `undefined` for compilations that do not have `moduleResolution` values of `node16` or `nodenext`.
|
||||
*/
|
||||
impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
/**
|
||||
* Controls how module-y-ness is set for the given file. Usually the result of calling
|
||||
* `getSetExternalModuleIndicator` on a valid `CompilerOptions` object. If not present, the default
|
||||
@ -9172,7 +9173,7 @@ declare namespace ts {
|
||||
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
||||
* is assumed to be the same as root directory of the project.
|
||||
*/
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, cache?: TypeReferenceDirectiveResolutionCache, resolutionMode?: SourceFile["impliedNodeFormat"]): ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, cache?: TypeReferenceDirectiveResolutionCache, resolutionMode?: ResolutionMode): ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
|
||||
/**
|
||||
* Given a set of options, returns the set of type directive names
|
||||
* that should be included for this program automatically.
|
||||
@ -9184,18 +9185,18 @@ declare namespace ts {
|
||||
function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[];
|
||||
function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache;
|
||||
function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): TypeReferenceDirectiveResolutionCache;
|
||||
function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations;
|
||||
function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations;
|
||||
function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;
|
||||
function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;
|
||||
interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>, PackageJsonInfoCache {
|
||||
}
|
||||
interface ModeAwareCache<T> {
|
||||
get(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): T | undefined;
|
||||
set(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, value: T): this;
|
||||
delete(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): this;
|
||||
has(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): boolean;
|
||||
forEach(cb: (elem: T, key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) => void): void;
|
||||
get(key: string, mode: ResolutionMode): T | undefined;
|
||||
set(key: string, mode: ResolutionMode, value: T): this;
|
||||
delete(key: string, mode: ResolutionMode): this;
|
||||
has(key: string, mode: ResolutionMode): boolean;
|
||||
forEach(cb: (elem: T, key: string, mode: ResolutionMode) => void): void;
|
||||
size(): number;
|
||||
}
|
||||
/**
|
||||
@ -9219,7 +9220,7 @@ declare namespace ts {
|
||||
* We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive.
|
||||
*/
|
||||
interface NonRelativeModuleNameResolutionCache extends PackageJsonInfoCache {
|
||||
getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache;
|
||||
getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ResolutionMode, redirectedReference?: ResolvedProjectReference): PerModuleNameCache;
|
||||
}
|
||||
interface PackageJsonInfoCache {
|
||||
clear(): void;
|
||||
@ -9327,7 +9328,7 @@ declare namespace ts {
|
||||
* Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly
|
||||
* provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file.
|
||||
*/
|
||||
function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined;
|
||||
function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode): ts.ResolutionMode;
|
||||
/**
|
||||
* Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly
|
||||
* defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm).
|
||||
@ -9335,7 +9336,7 @@ declare namespace ts {
|
||||
* @param file File to fetch the resolution mode within
|
||||
* @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations
|
||||
*/
|
||||
function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
|
||||
function getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
|
||||
/**
|
||||
* Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if
|
||||
* one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm).
|
||||
@ -9346,7 +9347,7 @@ declare namespace ts {
|
||||
* @returns The final resolution mode of the import
|
||||
*/
|
||||
function getModeForUsageLocation(file: {
|
||||
impliedNodeFormat?: SourceFile["impliedNodeFormat"];
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
}, usage: StringLiteralLike): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined;
|
||||
function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[];
|
||||
/**
|
||||
@ -9359,7 +9360,7 @@ declare namespace ts {
|
||||
* @param options The compiler options to perform the analysis under - relevant options are `moduleResolution` and `traceResolution`
|
||||
* @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
|
||||
*/
|
||||
function getImpliedNodeFormatForFile(fileName: Path, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ModuleKind.ESNext | ModuleKind.CommonJS | undefined;
|
||||
function getImpliedNodeFormatForFile(fileName: Path, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ResolutionMode;
|
||||
/**
|
||||
* Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions'
|
||||
* that represent a compilation unit.
|
||||
@ -9617,7 +9618,7 @@ declare namespace ts {
|
||||
/** If provided, used to resolve the module names, otherwise typescript's default module resolution */
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile, resolutionInfo?: ModuleResolutionInfo): (ResolvedModule | undefined)[];
|
||||
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
/**
|
||||
@ -9850,8 +9851,8 @@ declare namespace ts {
|
||||
fileExists(path: string): boolean;
|
||||
getTypeRootsVersion?(): number;
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile, resolutionInfo?: ModuleResolutionInfo): (ResolvedModule | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getDirectories?(directoryName: string): string[];
|
||||
/**
|
||||
* Gets a set of custom transformers to use during emit.
|
||||
@ -10982,11 +10983,11 @@ declare namespace ts {
|
||||
* @param scriptKind The script kind of the file to be released
|
||||
* @param impliedNodeFormat The implied source file format of the file to be released
|
||||
*/
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: SourceFile["impliedNodeFormat"]): void;
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode): void;
|
||||
/**
|
||||
* @deprecated pass scriptKind for and impliedNodeFormat correctness */
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind?: ScriptKind): void;
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind: ScriptKind, impliedNodeFormat: SourceFile["impliedNodeFormat"]): void;
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode): void;
|
||||
reportStats(): string;
|
||||
}
|
||||
type DocumentRegistryBucketKey = string & {
|
||||
|
||||
45
tests/baselines/reference/api/typescript.d.ts
vendored
45
tests/baselines/reference/api/typescript.d.ts
vendored
@ -1825,7 +1825,7 @@ declare namespace ts {
|
||||
}
|
||||
interface FileReference extends TextRange {
|
||||
fileName: string;
|
||||
resolutionMode?: SourceFile["impliedNodeFormat"];
|
||||
resolutionMode?: ResolutionMode;
|
||||
}
|
||||
interface CheckJsDirective extends TextRange {
|
||||
enabled: boolean;
|
||||
@ -2103,6 +2103,7 @@ declare namespace ts {
|
||||
interface SourceFileLike {
|
||||
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
|
||||
}
|
||||
type ResolutionMode = ModuleKind.ESNext | ModuleKind.CommonJS | undefined;
|
||||
interface SourceFile extends Declaration {
|
||||
readonly kind: SyntaxKind.SourceFile;
|
||||
readonly statements: NodeArray<Statement>;
|
||||
@ -2143,7 +2144,7 @@ declare namespace ts {
|
||||
* of `node`). If so, this field will be unset and source files will be considered to be
|
||||
* CommonJS-output-format by the node module transformer and type checker, regardless of extension or context.
|
||||
*/
|
||||
impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
}
|
||||
interface SourceFile {
|
||||
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
|
||||
@ -3407,7 +3408,7 @@ declare namespace ts {
|
||||
/**
|
||||
* This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
|
||||
*/
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getEnvironmentVariable?(name: string): string | undefined;
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
@ -5137,7 +5138,7 @@ declare namespace ts {
|
||||
* and files on disk, but needs to be done with a module resolution cache in scope to be performant.
|
||||
* This is usually `undefined` for compilations that do not have `moduleResolution` values of `node16` or `nodenext`.
|
||||
*/
|
||||
impliedNodeFormat?: ModuleKind.ESNext | ModuleKind.CommonJS;
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
/**
|
||||
* Controls how module-y-ness is set for the given file. Usually the result of calling
|
||||
* `getSetExternalModuleIndicator` on a valid `CompilerOptions` object. If not present, the default
|
||||
@ -5236,7 +5237,7 @@ declare namespace ts {
|
||||
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
|
||||
* is assumed to be the same as root directory of the project.
|
||||
*/
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, cache?: TypeReferenceDirectiveResolutionCache, resolutionMode?: SourceFile["impliedNodeFormat"]): ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
|
||||
function resolveTypeReferenceDirective(typeReferenceDirectiveName: string, containingFile: string | undefined, options: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference, cache?: TypeReferenceDirectiveResolutionCache, resolutionMode?: ResolutionMode): ResolvedTypeReferenceDirectiveWithFailedLookupLocations;
|
||||
/**
|
||||
* Given a set of options, returns the set of type directive names
|
||||
* that should be included for this program automatically.
|
||||
@ -5248,18 +5249,18 @@ declare namespace ts {
|
||||
function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[];
|
||||
function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache;
|
||||
function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): TypeReferenceDirectiveResolutionCache;
|
||||
function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations;
|
||||
function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations;
|
||||
function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;
|
||||
function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;
|
||||
interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>, PackageJsonInfoCache {
|
||||
}
|
||||
interface ModeAwareCache<T> {
|
||||
get(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): T | undefined;
|
||||
set(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, value: T): this;
|
||||
delete(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): this;
|
||||
has(key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined): boolean;
|
||||
forEach(cb: (elem: T, key: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined) => void): void;
|
||||
get(key: string, mode: ResolutionMode): T | undefined;
|
||||
set(key: string, mode: ResolutionMode, value: T): this;
|
||||
delete(key: string, mode: ResolutionMode): this;
|
||||
has(key: string, mode: ResolutionMode): boolean;
|
||||
forEach(cb: (elem: T, key: string, mode: ResolutionMode) => void): void;
|
||||
size(): number;
|
||||
}
|
||||
/**
|
||||
@ -5283,7 +5284,7 @@ declare namespace ts {
|
||||
* We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive.
|
||||
*/
|
||||
interface NonRelativeModuleNameResolutionCache extends PackageJsonInfoCache {
|
||||
getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ModuleKind.CommonJS | ModuleKind.ESNext | undefined, redirectedReference?: ResolvedProjectReference): PerModuleNameCache;
|
||||
getOrCreateCacheForModuleName(nonRelativeModuleName: string, mode: ResolutionMode, redirectedReference?: ResolvedProjectReference): PerModuleNameCache;
|
||||
}
|
||||
interface PackageJsonInfoCache {
|
||||
clear(): void;
|
||||
@ -5391,7 +5392,7 @@ declare namespace ts {
|
||||
* Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly
|
||||
* provided resolution mode in the reference, unless one is not present, in which case it is the mode of the containing file.
|
||||
*/
|
||||
function getModeForFileReference(ref: FileReference | string, containingFileMode: SourceFile["impliedNodeFormat"]): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined;
|
||||
function getModeForFileReference(ref: FileReference | string, containingFileMode: ResolutionMode): ts.ResolutionMode;
|
||||
/**
|
||||
* Calculates the final resolution mode for an import at some index within a file's imports list. This is generally the explicitly
|
||||
* defined mode of the import if provided, or, if not, the mode of the containing file (with some exceptions: import=require is always commonjs, dynamic import is always esm).
|
||||
@ -5399,7 +5400,7 @@ declare namespace ts {
|
||||
* @param file File to fetch the resolution mode within
|
||||
* @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations
|
||||
*/
|
||||
function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
|
||||
function getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
|
||||
/**
|
||||
* Calculates the final resolution mode for a given module reference node. This is generally the explicitly provided resolution mode, if
|
||||
* one exists, or the mode of the containing source file. (Excepting import=require, which is always commonjs, and dynamic import, which is always esm).
|
||||
@ -5410,7 +5411,7 @@ declare namespace ts {
|
||||
* @returns The final resolution mode of the import
|
||||
*/
|
||||
function getModeForUsageLocation(file: {
|
||||
impliedNodeFormat?: SourceFile["impliedNodeFormat"];
|
||||
impliedNodeFormat?: ResolutionMode;
|
||||
}, usage: StringLiteralLike): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined;
|
||||
function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[];
|
||||
/**
|
||||
@ -5423,7 +5424,7 @@ declare namespace ts {
|
||||
* @param options The compiler options to perform the analysis under - relevant options are `moduleResolution` and `traceResolution`
|
||||
* @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
|
||||
*/
|
||||
function getImpliedNodeFormatForFile(fileName: Path, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ModuleKind.ESNext | ModuleKind.CommonJS | undefined;
|
||||
function getImpliedNodeFormatForFile(fileName: Path, packageJsonInfoCache: PackageJsonInfoCache | undefined, host: ModuleResolutionHost, options: CompilerOptions): ResolutionMode;
|
||||
/**
|
||||
* Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions'
|
||||
* that represent a compilation unit.
|
||||
@ -5681,7 +5682,7 @@ declare namespace ts {
|
||||
/** If provided, used to resolve the module names, otherwise typescript's default module resolution */
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile, resolutionInfo?: ModuleResolutionInfo): (ResolvedModule | undefined)[];
|
||||
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
/**
|
||||
@ -5987,8 +5988,8 @@ declare namespace ts {
|
||||
fileExists(path: string): boolean;
|
||||
getTypeRootsVersion?(): number;
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile, resolutionInfo?: ModuleResolutionInfo): (ResolvedModule | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: ResolutionMode, resolutionInfo?: TypeReferenceDirectiveResolutionInfo): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getDirectories?(directoryName: string): string[];
|
||||
/**
|
||||
* Gets a set of custom transformers to use during emit.
|
||||
@ -7119,11 +7120,11 @@ declare namespace ts {
|
||||
* @param scriptKind The script kind of the file to be released
|
||||
* @param impliedNodeFormat The implied source file format of the file to be released
|
||||
*/
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: SourceFile["impliedNodeFormat"]): void;
|
||||
releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode): void;
|
||||
/**
|
||||
* @deprecated pass scriptKind for and impliedNodeFormat correctness */
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind?: ScriptKind): void;
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind: ScriptKind, impliedNodeFormat: SourceFile["impliedNodeFormat"]): void;
|
||||
releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode): void;
|
||||
reportStats(): string;
|
||||
}
|
||||
type DocumentRegistryBucketKey = string & {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user