Skip to content

Commit c5e4f00

Browse files
authored
Switch to var in binder for top level variables (#52903)
1 parent 3471bd7 commit c5e4f00

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

src/compiler/binder.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -501,49 +501,53 @@ export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
501501
}
502502

503503
function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
504-
let file: SourceFile;
505-
let options: CompilerOptions;
506-
let languageVersion: ScriptTarget;
507-
let parent: Node;
508-
let container: IsContainer | EntityNameExpression;
509-
let thisParentContainer: IsContainer | EntityNameExpression; // Container one level up
510-
let blockScopeContainer: IsBlockScopedContainer;
511-
let lastContainer: HasLocals;
512-
let delayedTypeAliases: (JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag)[];
513-
let seenThisKeyword: boolean;
504+
/* eslint-disable no-var */
505+
var file: SourceFile;
506+
var options: CompilerOptions;
507+
var languageVersion: ScriptTarget;
508+
var parent: Node;
509+
var container: IsContainer | EntityNameExpression;
510+
var thisParentContainer: IsContainer | EntityNameExpression; // Container one level up
511+
var blockScopeContainer: IsBlockScopedContainer;
512+
var lastContainer: HasLocals;
513+
var delayedTypeAliases: (JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag)[];
514+
var seenThisKeyword: boolean;
514515

515516
// state used by control flow analysis
516-
let currentFlow: FlowNode;
517-
let currentBreakTarget: FlowLabel | undefined;
518-
let currentContinueTarget: FlowLabel | undefined;
519-
let currentReturnTarget: FlowLabel | undefined;
520-
let currentTrueTarget: FlowLabel | undefined;
521-
let currentFalseTarget: FlowLabel | undefined;
522-
let currentExceptionTarget: FlowLabel | undefined;
523-
let preSwitchCaseFlow: FlowNode | undefined;
524-
let activeLabelList: ActiveLabel | undefined;
525-
let hasExplicitReturn: boolean;
517+
var currentFlow: FlowNode;
518+
var currentBreakTarget: FlowLabel | undefined;
519+
var currentContinueTarget: FlowLabel | undefined;
520+
var currentReturnTarget: FlowLabel | undefined;
521+
var currentTrueTarget: FlowLabel | undefined;
522+
var currentFalseTarget: FlowLabel | undefined;
523+
var currentExceptionTarget: FlowLabel | undefined;
524+
var preSwitchCaseFlow: FlowNode | undefined;
525+
var activeLabelList: ActiveLabel | undefined;
526+
var hasExplicitReturn: boolean;
526527

527528
// state used for emit helpers
528-
let emitFlags: NodeFlags;
529+
var emitFlags: NodeFlags;
529530

530531
// If this file is an external module, then it is automatically in strict-mode according to
531532
// ES6. If it is not an external module, then we'll determine if it is in strict mode or
532533
// not depending on if we see "use strict" in certain places or if we hit a class/namespace
533534
// or if compiler options contain alwaysStrict.
534-
let inStrictMode: boolean;
535+
var inStrictMode: boolean;
535536

536537
// If we are binding an assignment pattern, we will bind certain expressions differently.
537-
let inAssignmentPattern = false;
538+
var inAssignmentPattern = false;
538539

539-
let symbolCount = 0;
540+
var symbolCount = 0;
540541

541-
let Symbol: new (flags: SymbolFlags, name: __String) => Symbol;
542-
let classifiableNames: Set<__String>;
542+
var Symbol: new (flags: SymbolFlags, name: __String) => Symbol;
543+
var classifiableNames: Set<__String>;
543544

544-
const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
545-
const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
546-
const bindBinaryExpressionFlow = createBindBinaryExpressionFlow();
545+
var unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
546+
var reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
547+
var bindBinaryExpressionFlow = createBindBinaryExpressionFlow();
548+
/* eslint-enable no-var */
549+
550+
return bindSourceFile;
547551

548552
/**
549553
* Inside the binder, we may create a diagnostic for an as-yet unbound node (with potentially no parent pointers, implying no accessible source file)
@@ -600,8 +604,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
600604
emitFlags = NodeFlags.None;
601605
}
602606

603-
return bindSourceFile;
604-
605607
function bindInStrictMode(file: SourceFile, opts: CompilerOptions): boolean {
606608
if (getStrictOptionValue(opts, "alwaysStrict") && !file.isDeclarationFile) {
607609
// bind in strict mode source files with alwaysStrict option

0 commit comments

Comments
 (0)