Skip to content

Commit 2e94032

Browse files
committed
fix
1 parent c60ce01 commit 2e94032

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/resolver-functions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,16 @@ export function createResolverFunctions(kwargs: {
9898
optionsOnlyWithNewerTsVersions: TSCommon.CompilerOptions,
9999
containingSourceFile?: TSCommon.SourceFile
100100
): (TSCommon.ResolvedModule | undefined)[] => {
101-
return moduleNames.map((moduleName) => {
101+
return moduleNames.map((moduleName, i) => {
102+
const mode = containingSourceFile ? (ts as any as TSInternal).getModeForResolutionAtIndex?.(containingSourceFile, i) : undefined;
102103
const { resolvedModule } = ts.resolveModuleName(
103104
moduleName,
104105
containingFile,
105106
config.options,
106107
host,
107108
moduleResolutionCache,
108109
redirectedReference,
109-
containingSourceFile?.impliedNodeFormat
110-
111-
// (ts as any as typeof import('typescript')).getModeForResolutionAtIndex(containingSourceFile)
110+
mode,
112111
);
113112
if (resolvedModule) {
114113
fixupResolvedModule(resolvedModule);

src/ts-compiler-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ export interface TSInternal {
117117
basePath: string,
118118
usage: 'files' | 'directories' | 'exclude'
119119
): string | undefined;
120+
// Added in TS 4.7
121+
getModeForResolutionAtIndex?(file: TSInternal.SourceFileImportsList, index: number): _ts.SourceFile['impliedNodeFormat'];
120122
}
121123
/** @internal */
122124
export namespace TSInternal {
@@ -127,4 +129,8 @@ export namespace TSInternal {
127129
getCurrentDirectory(): string;
128130
useCaseSensitiveFileNames: boolean;
129131
}
132+
// Note: is only a partial declaration, TS sources declare other fields
133+
export interface SourceFileImportsList {
134+
impliedNodeFormat?: TSCommon.SourceFile["impliedNodeFormat"];
135+
};
130136
}

0 commit comments

Comments
 (0)