Skip to content

Commit 7f4baf6

Browse files
committed
Suppress resolvedUsingTsExtension during loadModuleFromDirectory
1 parent b0633c5 commit 7f4baf6

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/compiler/moduleNameResolver.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export interface ModuleResolutionState {
259259
requestContainingDirectory: string | undefined;
260260
reportDiagnostic: DiagnosticReporter;
261261
isConfigLookup: boolean;
262+
suppressResolvedUsingTsExtension: boolean;
262263
}
263264

264265
/** Just the fields that we use for module resolution.
@@ -526,6 +527,7 @@ export function resolveTypeReferenceDirective(typeReferenceDirectiveName: string
526527
requestContainingDirectory: containingDirectory,
527528
reportDiagnostic: diag => void diagnostics.push(diag),
528529
isConfigLookup: false,
530+
suppressResolvedUsingTsExtension: false,
529531
};
530532
let resolved = primaryLookup();
531533
let primary = true;
@@ -1652,6 +1654,7 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa
16521654
requestContainingDirectory: containingDirectory,
16531655
reportDiagnostic: diag => void diagnostics.push(diag),
16541656
isConfigLookup,
1657+
suppressResolvedUsingTsExtension: false,
16551658
};
16561659

16571660
if (traceEnabled && getEmitModuleResolutionKind(compilerOptions) >= ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) <= ModuleResolutionKind.NodeNext) {
@@ -1948,7 +1951,7 @@ function tryAddingExtensions(candidate: string, extensions: Extensions, original
19481951

19491952
function tryExtension(ext: string, resolvedUsingTsExtension?: boolean): PathAndExtension | undefined {
19501953
const path = tryFile(candidate + ext, onlyRecordFailures, state);
1951-
return path === undefined ? undefined : { path, ext, resolvedUsingTsExtension };
1954+
return path === undefined ? undefined : { path, ext, resolvedUsingTsExtension: !state.suppressResolvedUsingTsExtension && resolvedUsingTsExtension };
19521955
}
19531956
}
19541957

@@ -2111,6 +2114,7 @@ export function getTemporaryModuleResolutionState(packageJsonInfoCache: PackageJ
21112114
requestContainingDirectory: undefined,
21122115
reportDiagnostic: noop,
21132116
isConfigLookup: false,
2117+
suppressResolvedUsingTsExtension: false,
21142118
};
21152119
}
21162120

@@ -2232,11 +2236,14 @@ function loadNodeModuleFromDirectoryWorker(extensions: Extensions, candidate: st
22322236
// (technically it only emits a deprecation warning in esm packages right now, but that's probably
22332237
// enough to mean we don't need to support it)
22342238
const features = state.features;
2239+
const suppressResolvedUsingTsExtension = state.suppressResolvedUsingTsExtension;
2240+
state.suppressResolvedUsingTsExtension = true;
22352241
if (jsonContent?.type !== "module") {
22362242
state.features &= ~NodeResolutionFeatures.EsmMode;
22372243
}
22382244
const result = nodeLoadModuleByRelativeName(expandedExtensions, candidate, onlyRecordFailures, state, /*considerPackageJson*/ false);
22392245
state.features = features;
2246+
state.suppressResolvedUsingTsExtension = suppressResolvedUsingTsExtension;
22402247
return result;
22412248
};
22422249

@@ -2935,6 +2942,7 @@ export function classicNameResolver(moduleName: string, containingFile: string,
29352942
requestContainingDirectory: containingDirectory,
29362943
reportDiagnostic: diag => void diagnostics.push(diag),
29372944
isConfigLookup: false,
2945+
suppressResolvedUsingTsExtension: false,
29382946
};
29392947

29402948
const resolved =
@@ -3015,6 +3023,7 @@ export function loadModuleFromGlobalCache(moduleName: string, projectName: strin
30153023
requestContainingDirectory: undefined,
30163024
reportDiagnostic: diag => void diagnostics.push(diag),
30173025
isConfigLookup: false,
3026+
suppressResolvedUsingTsExtension: false,
30183027
};
30193028
const resolved = loadModuleFromImmediateNodeModulesDirectory(Extensions.Declaration, moduleName, globalCache, state, /*typesScopeOnly*/ false, /*cache*/ undefined, /*redirectedReference*/ undefined);
30203029
return createResolvedModuleWithFailedLookupLocations(
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/compiler/issue52182.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "@angular/core",
6+
"typings": "index.d.ts"
7+
}
8+
9+
//// [index.ts]
10+
export {};
11+
12+
//// [test.ts]
13+
import "@angular/core";
14+
15+
16+
//// [index.js]
17+
"use strict";
18+
Object.defineProperty(exports, "__esModule", { value: true });
19+
//// [test.js]
20+
"use strict";
21+
Object.defineProperty(exports, "__esModule", { value: true });
22+
require("@angular/core");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/@angular/core/index.ts ===
2+
3+
export {};
4+
5+
=== tests/cases/compiler/@angular/core/testing/test.ts ===
6+
7+
import "@angular/core";
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/@angular/core/index.ts ===
2+
3+
export {};
4+
5+
=== tests/cases/compiler/@angular/core/testing/test.ts ===
6+
7+
import "@angular/core";
8+

0 commit comments

Comments
 (0)