Skip to content

Commit 0d532eb

Browse files
Copilotandrewbranch
andcommitted
Apply getEmitModuleFormatOfFile only for project reference declaration files
Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
1 parent 5a2ac97 commit 0d532eb

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/compiler/checker.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,12 +3794,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37943794
// are ESM, there cannot be a synthetic default.
37953795
return false;
37963796
}
3797-
// For declaration files from project references, check if the referenced project's
3798-
// emit format is ESM, in which case there cannot be a synthetic default
3799-
if (file.isDeclarationFile && host.getRedirectFromSourceFile(file.path)) {
3800-
const targetModuleKind = host.getEmitModuleFormatOfFile(file);
3801-
if (usageMode === ModuleKind.ESNext && targetModuleKind >= ModuleKind.ES2015) {
3802-
return false;
3797+
// For other files (not node16/nodenext with impliedNodeFormat), check if we can determine
3798+
// the module format from project references
3799+
if (!targetMode && file.isDeclarationFile) {
3800+
const redirect = host.getRedirectFromSourceFile(file.path);
3801+
if (redirect) {
3802+
// This is a declaration file from a project reference, so we can determine
3803+
// its module format from the referenced project's options
3804+
const targetModuleKind = host.getEmitModuleFormatOfFile(file);
3805+
if (usageMode === ModuleKind.ESNext && targetModuleKind >= ModuleKind.ES2015) {
3806+
return false;
3807+
}
38033808
}
38043809
}
38053810
}

0 commit comments

Comments
 (0)