Skip to content

Commit 8a24fe7

Browse files
authored
Fix up code so we don't crash when TS itself is emitted with let/const (#50151)
1 parent b56483f commit 8a24fe7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/compiler/checker.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -27075,9 +27075,11 @@ namespace ts {
2707527075
case AssignmentDeclarationKind.ExportsProperty:
2707627076
case AssignmentDeclarationKind.Prototype:
2707727077
case AssignmentDeclarationKind.PrototypeProperty:
27078-
let valueDeclaration = binaryExpression.left.symbol?.valueDeclaration;
27079-
// falls through
2708027078
case AssignmentDeclarationKind.ModuleExports:
27079+
let valueDeclaration: Declaration | undefined;
27080+
if (kind !== AssignmentDeclarationKind.ModuleExports) {
27081+
valueDeclaration = binaryExpression.left.symbol?.valueDeclaration;
27082+
}
2708127083
valueDeclaration ||= binaryExpression.symbol?.valueDeclaration;
2708227084
const annotated = valueDeclaration && getEffectiveTypeAnnotationNode(valueDeclaration);
2708327085
return annotated ? getTypeFromTypeNode(annotated) : undefined;

src/services/services.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,11 @@ namespace ts {
13631363
onUnRecoverableConfigFileDiagnostic: noop,
13641364
};
13651365

1366+
// The call to isProgramUptoDate below may refer back to documentRegistryBucketKey;
1367+
// calculate this early so it's not undefined if downleveled to a var (or, if emitted
1368+
// as a const variable without downleveling, doesn't crash).
1369+
const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
1370+
13661371
// If the program is already up-to-date, we can reuse it
13671372
if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), fileName => compilerHost!.fileExists(fileName), hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
13681373
return;
@@ -1374,7 +1379,6 @@ namespace ts {
13741379
// the program points to old source files that have been invalidated because of
13751380
// incremental parsing.
13761381

1377-
const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
13781382
const options: CreateProgramOptions = {
13791383
rootNames: rootFileNames,
13801384
options: newSettings,

0 commit comments

Comments
 (0)