Skip to content

Commit 62bdfca

Browse files
sheetalkamatsnovader
authored andcommitted
Source files not affected by all module resolution options (microsoft#55790)
1 parent 0139a62 commit 62bdfca

26 files changed

+180
-214
lines changed

src/compiler/builderState.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ export namespace BuilderState {
238238
}
239239

240240
// Handle type reference directives
241-
if (sourceFile.resolvedTypeReferenceDirectiveNames) {
242-
sourceFile.resolvedTypeReferenceDirectiveNames.forEach(({ resolvedTypeReferenceDirective }) => {
241+
const resolvedTypeReferenceDirectiveNames = program.resolvedTypeReferenceDirectiveNames?.get(sourceFile.path);
242+
if (resolvedTypeReferenceDirectiveNames) {
243+
resolvedTypeReferenceDirectiveNames.forEach(({ resolvedTypeReferenceDirective }) => {
243244
if (!resolvedTypeReferenceDirective) {
244245
return;
245246
}

src/compiler/checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ import {
342342
getResolutionDiagnostic,
343343
getResolutionModeOverrideForClause,
344344
getResolvedExternalModuleName,
345-
getResolvedModule,
346345
getResolveJsonModule,
347346
getRestParameterElementType,
348347
getRootDeclaration,
@@ -4960,7 +4959,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
49604959
(isLiteralImportTypeNode(location) ? location : undefined)?.argument.literal;
49614960
const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat;
49624961
const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
4963-
const resolvedModule = getResolvedModule(currentSourceFile, moduleReference, mode);
4962+
const resolvedModule = host.resolvedModules?.get(currentSourceFile.path)?.get(moduleReference, mode)?.resolvedModule;
49644963
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile);
49654964
const sourceFile = resolvedModule
49664965
&& (!resolutionDiagnostic || resolutionDiagnostic === Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set)

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ export const moduleOptionDeclaration: CommandLineOptionOfCustomType = {
553553
node16: ModuleKind.Node16,
554554
nodenext: ModuleKind.NodeNext,
555555
})),
556+
affectsSourceFile: true,
556557
affectsModuleResolution: true,
557558
affectsEmit: true,
558559
affectsBuildInfo: true,
@@ -994,6 +995,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
994995
bundler: ModuleResolutionKind.Bundler,
995996
})),
996997
deprecatedKeys: new Set(["node"]),
998+
affectsSourceFile: true,
997999
affectsModuleResolution: true,
9981000
paramType: Diagnostics.STRATEGY,
9991001
category: Diagnostics.Modules,
@@ -1540,6 +1542,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
15401542
legacy: ModuleDetectionKind.Legacy,
15411543
force: ModuleDetectionKind.Force,
15421544
})),
1545+
affectsSourceFile: true,
15431546
affectsModuleResolution: true,
15441547
description: Diagnostics.Control_what_method_is_used_to_detect_module_format_JS_files,
15451548
category: Diagnostics.Language_and_Environment,
@@ -1571,7 +1574,7 @@ export const affectsDeclarationPathOptionDeclarations: readonly CommandLineOptio
15711574
export const moduleResolutionOptionDeclarations: readonly CommandLineOption[] = optionDeclarations.filter(option => !!option.affectsModuleResolution);
15721575

15731576
/** @internal */
1574-
export const sourceFileAffectingCompilerOptions: readonly CommandLineOption[] = optionDeclarations.filter(option => !!option.affectsSourceFile || !!option.affectsModuleResolution || !!option.affectsBindDiagnostics);
1577+
export const sourceFileAffectingCompilerOptions: readonly CommandLineOption[] = optionDeclarations.filter(option => !!option.affectsSourceFile || !!option.affectsBindDiagnostics);
15751578

15761579
/** @internal */
15771580
export const optionsAffectingProgramStructure: readonly CommandLineOption[] = optionDeclarations.filter(option => !!option.affectsProgramStructure);

src/compiler/factory/nodeFactory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6026,7 +6026,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
60266026
node.imports = undefined!;
60276027
node.moduleAugmentations = undefined!;
60286028
node.ambientModuleNames = undefined!;
6029-
node.resolvedModules = undefined;
60306029
node.classifiableNames = undefined;
60316030
node.impliedNodeFormat = undefined;
60326031
return node;

src/compiler/moduleNameResolver.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,12 @@ import {
9191
removeFileExtension,
9292
removePrefix,
9393
ResolutionMode,
94-
ResolutionNameAndModeGetter,
9594
ResolvedModuleWithFailedLookupLocations,
9695
ResolvedProjectReference,
9796
ResolvedTypeReferenceDirective,
9897
ResolvedTypeReferenceDirectiveWithFailedLookupLocations,
9998
some,
10099
sort,
101-
SourceFile,
102100
startsWith,
103101
supportedDeclarationExtensions,
104102
supportedJSExtensionsFlat,
@@ -1116,22 +1114,6 @@ export function createModeAwareCache<T>(): ModeAwareCache<T> {
11161114
}
11171115
}
11181116

1119-
/** @internal */
1120-
export function zipToModeAwareCache<K, V>(
1121-
file: SourceFile,
1122-
keys: readonly K[],
1123-
values: readonly V[],
1124-
nameAndModeGetter: ResolutionNameAndModeGetter<K, SourceFile>,
1125-
): ModeAwareCache<V> {
1126-
Debug.assert(keys.length === values.length);
1127-
const map = createModeAwareCache<V>();
1128-
for (let i = 0; i < keys.length; ++i) {
1129-
const entry = keys[i];
1130-
map.set(nameAndModeGetter.getName(entry), nameAndModeGetter.getMode(entry, file), values[i]);
1131-
}
1132-
return map;
1133-
}
1134-
11351117
function getOriginalOrResolvedModuleFileName(result: ResolvedModuleWithFailedLookupLocations) {
11361118
return result.resolvedModule && (result.resolvedModule.originalPath || result.resolvedModule.resolvedFileName);
11371119
}

0 commit comments

Comments
 (0)