Skip to content

Commit 150c981

Browse files
committed
Merge branch 'main' into aggregateTimes
2 parents cdf2962 + 2f7ecc6 commit 150c981

File tree

615 files changed

+46315
-8826
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

615 files changed

+46315
-8826
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

Lines changed: 83 additions & 179 deletions
Large diffs are not rendered by default.

src/compiler/moduleNameResolver.ts

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,24 @@ namespace ts {
8686
return { fileName: resolved.path, packageId: resolved.packageId };
8787
}
8888

89-
function createResolvedModuleWithFailedLookupLocations(resolved: Resolved | undefined, isExternalLibraryImport: boolean | undefined, failedLookupLocations: string[], diagnostics: Diagnostic[], resultFromCache: ResolvedModuleWithFailedLookupLocations | undefined): ResolvedModuleWithFailedLookupLocations {
89+
function createResolvedModuleWithFailedLookupLocations(
90+
resolved: Resolved | undefined,
91+
isExternalLibraryImport: boolean | undefined,
92+
failedLookupLocations: string[],
93+
affectingLocations: string[],
94+
diagnostics: Diagnostic[],
95+
resultFromCache: ResolvedModuleWithFailedLookupLocations | undefined
96+
): ResolvedModuleWithFailedLookupLocations {
9097
if (resultFromCache) {
9198
resultFromCache.failedLookupLocations.push(...failedLookupLocations);
99+
resultFromCache.affectingLocations.push(...affectingLocations);
92100
return resultFromCache;
93101
}
94102
return {
95103
resolvedModule: resolved && { resolvedFileName: resolved.path, originalPath: resolved.originalPath === true ? undefined : resolved.originalPath, extension: resolved.extension, isExternalLibraryImport, packageId: resolved.packageId },
96104
failedLookupLocations,
97-
resolutionDiagnostics: diagnostics
105+
affectingLocations,
106+
resolutionDiagnostics: diagnostics,
98107
};
99108
}
100109

@@ -104,6 +113,7 @@ namespace ts {
104113
compilerOptions: CompilerOptions;
105114
traceEnabled: boolean;
106115
failedLookupLocations: Push<string>;
116+
affectingLocations: Push<string>;
107117
resultFromCache?: ResolvedModuleWithFailedLookupLocations;
108118
packageJsonInfoCache: PackageJsonInfoCache | undefined;
109119
features: NodeResolutionFeatures;
@@ -345,6 +355,7 @@ namespace ts {
345355
}
346356

347357
const failedLookupLocations: string[] = [];
358+
const affectingLocations: string[] = [];
348359
let features = getDefaultNodeResolutionFeatures(options);
349360
// Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution
350361
// setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being
@@ -363,6 +374,7 @@ namespace ts {
363374
host,
364375
traceEnabled,
365376
failedLookupLocations,
377+
affectingLocations,
366378
packageJsonInfoCache: cache,
367379
features,
368380
conditions,
@@ -388,7 +400,7 @@ namespace ts {
388400
isExternalLibraryImport: pathContainsNodeModules(fileName),
389401
};
390402
}
391-
result = { resolvedTypeReferenceDirective, failedLookupLocations, resolutionDiagnostics: diagnostics };
403+
result = { resolvedTypeReferenceDirective, failedLookupLocations, affectingLocations, resolutionDiagnostics: diagnostics };
392404
perFolderCache?.set(typeReferenceDirectiveName, /*mode*/ resolutionMode, result);
393405
if (traceEnabled) traceResult(result);
394406
return result;
@@ -479,6 +491,7 @@ namespace ts {
479491
host,
480492
traceEnabled: isTraceEnabled(options, host),
481493
failedLookupLocations: [],
494+
affectingLocations: [],
482495
packageJsonInfoCache: cache?.getPackageJsonInfoCache(),
483496
conditions: emptyArray,
484497
features: NodeResolutionFeatures.None,
@@ -1330,6 +1343,7 @@ namespace ts {
13301343
const traceEnabled = isTraceEnabled(compilerOptions, host);
13311344

13321345
const failedLookupLocations: string[] = [];
1346+
const affectingLocations: string[] = [];
13331347
// conditions are only used by the node16/nodenext resolver - there's no priority order in the list,
13341348
//it's essentially a set (priority is determined by object insertion order in the object we look at).
13351349
const conditions = features & NodeResolutionFeatures.EsmMode ? ["node", "import", "types"] : ["node", "require", "types"];
@@ -1343,6 +1357,7 @@ namespace ts {
13431357
host,
13441358
traceEnabled,
13451359
failedLookupLocations,
1360+
affectingLocations,
13461361
packageJsonInfoCache: cache,
13471362
features,
13481363
conditions,
@@ -1351,7 +1366,14 @@ namespace ts {
13511366
};
13521367

13531368
const result = forEach(extensions, ext => tryResolve(ext));
1354-
return createResolvedModuleWithFailedLookupLocations(result?.value?.resolved, result?.value?.isExternalLibraryImport, failedLookupLocations, diagnostics, state.resultFromCache);
1369+
return createResolvedModuleWithFailedLookupLocations(
1370+
result?.value?.resolved,
1371+
result?.value?.isExternalLibraryImport,
1372+
failedLookupLocations,
1373+
affectingLocations,
1374+
diagnostics,
1375+
state.resultFromCache
1376+
);
13551377

13561378
function tryResolve(extensions: Extensions): SearchResult<{ resolved: Resolved, isExternalLibraryImport: boolean }> {
13571379
const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ true);
@@ -1675,6 +1697,7 @@ namespace ts {
16751697
host,
16761698
traceEnabled: isTraceEnabled(options, host),
16771699
failedLookupLocations: [],
1700+
affectingLocations: [],
16781701
packageJsonInfoCache: cache?.getPackageJsonInfoCache(),
16791702
conditions: ["node", "require", "types"],
16801703
features,
@@ -1785,6 +1808,7 @@ namespace ts {
17851808
compilerOptions: CompilerOptions;
17861809
traceEnabled: boolean;
17871810
failedLookupLocations: Push<string>;
1811+
affectingLocations: Push<string>;
17881812
resultFromCache?: ResolvedModuleWithFailedLookupLocations;
17891813
packageJsonInfoCache: PackageJsonInfoCache | undefined;
17901814
features: number;
@@ -1796,6 +1820,7 @@ namespace ts {
17961820
compilerOptions: options,
17971821
traceEnabled: isTraceEnabled(options, host),
17981822
failedLookupLocations: [],
1823+
affectingLocations: [],
17991824
packageJsonInfoCache,
18001825
features: 0,
18011826
conditions: [],
@@ -1827,6 +1852,7 @@ namespace ts {
18271852
if (existing !== undefined) {
18281853
if (typeof existing !== "boolean") {
18291854
if (traceEnabled) trace(host, Diagnostics.File_0_exists_according_to_earlier_cached_lookups, packageJsonPath);
1855+
state.affectingLocations.push(packageJsonPath);
18301856
return existing;
18311857
}
18321858
else {
@@ -1844,6 +1870,7 @@ namespace ts {
18441870
const versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state);
18451871
const result = { packageDirectory, packageJsonContent, versionPaths, resolvedEntrypoints: undefined };
18461872
state.packageJsonInfoCache?.setPackageJsonInfo(packageJsonPath, result);
1873+
state.affectingLocations.push(packageJsonPath);
18471874
return result;
18481875
}
18491876
else {
@@ -2550,13 +2577,31 @@ namespace ts {
25502577
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations {
25512578
const traceEnabled = isTraceEnabled(compilerOptions, host);
25522579
const failedLookupLocations: string[] = [];
2580+
const affectingLocations: string[] = [];
25532581
const containingDirectory = getDirectoryPath(containingFile);
25542582
const diagnostics: Diagnostic[] = [];
2555-
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache: cache, features: NodeResolutionFeatures.None, conditions: [], requestContainingDirectory: containingDirectory, reportDiagnostic: diag => void diagnostics.push(diag) };
2583+
const state: ModuleResolutionState = {
2584+
compilerOptions,
2585+
host,
2586+
traceEnabled,
2587+
failedLookupLocations,
2588+
affectingLocations, packageJsonInfoCache: cache,
2589+
features: NodeResolutionFeatures.None,
2590+
conditions: [],
2591+
requestContainingDirectory: containingDirectory,
2592+
reportDiagnostic: diag => void diagnostics.push(diag),
2593+
};
25562594

25572595
const resolved = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
25582596
// No originalPath because classic resolution doesn't resolve realPath
2559-
return createResolvedModuleWithFailedLookupLocations(resolved && resolved.value, /*isExternalLibraryImport*/ false, failedLookupLocations, diagnostics, state.resultFromCache);
2597+
return createResolvedModuleWithFailedLookupLocations(
2598+
resolved && resolved.value,
2599+
/*isExternalLibraryImport*/ false,
2600+
failedLookupLocations,
2601+
affectingLocations,
2602+
diagnostics,
2603+
state.resultFromCache
2604+
);
25602605

25612606
function tryResolve(extensions: Extensions): SearchResult<Resolved> {
25622607
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loadModuleFromFileNoPackageId, state);
@@ -2601,10 +2646,29 @@ namespace ts {
26012646
trace(host, Diagnostics.Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2, projectName, moduleName, globalCache);
26022647
}
26032648
const failedLookupLocations: string[] = [];
2649+
const affectingLocations: string[] = [];
26042650
const diagnostics: Diagnostic[] = [];
2605-
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache, features: NodeResolutionFeatures.None, conditions: [], requestContainingDirectory: undefined, reportDiagnostic: diag => void diagnostics.push(diag) };
2651+
const state: ModuleResolutionState = {
2652+
compilerOptions,
2653+
host,
2654+
traceEnabled,
2655+
failedLookupLocations,
2656+
affectingLocations,
2657+
packageJsonInfoCache,
2658+
features: NodeResolutionFeatures.None,
2659+
conditions: [],
2660+
requestContainingDirectory: undefined,
2661+
reportDiagnostic: diag => void diagnostics.push(diag),
2662+
};
26062663
const resolved = loadModuleFromImmediateNodeModulesDirectory(Extensions.DtsOnly, moduleName, globalCache, state, /*typesScopeOnly*/ false, /*cache*/ undefined, /*redirectedReference*/ undefined);
2607-
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations, diagnostics, state.resultFromCache);
2664+
return createResolvedModuleWithFailedLookupLocations(
2665+
resolved,
2666+
/*isExternalLibraryImport*/ true,
2667+
failedLookupLocations,
2668+
affectingLocations,
2669+
diagnostics,
2670+
state.resultFromCache
2671+
);
26082672
}
26092673

26102674
/**

0 commit comments

Comments
 (0)