From e7c5b69ce03d4ce5c1ad710eccc4876d11903de5 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:11:33 -0800 Subject: [PATCH 1/2] Switch to var in binder for top level variables --- src/compiler/binder.ts | 60 ++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8b239802f0de8..24fce4d4c7076 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -501,49 +501,51 @@ export function bindSourceFile(file: SourceFile, options: CompilerOptions) { } function createBinder(): (file: SourceFile, options: CompilerOptions) => void { - let file: SourceFile; - let options: CompilerOptions; - let languageVersion: ScriptTarget; - let parent: Node; - let container: IsContainer | EntityNameExpression; - let thisParentContainer: IsContainer | EntityNameExpression; // Container one level up - let blockScopeContainer: IsBlockScopedContainer; - let lastContainer: HasLocals; - let delayedTypeAliases: (JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag)[]; - let seenThisKeyword: boolean; + /* eslint-disable no-var */ + var file: SourceFile; + var options: CompilerOptions; + var languageVersion: ScriptTarget; + var parent: Node; + var container: IsContainer | EntityNameExpression; + var thisParentContainer: IsContainer | EntityNameExpression; // Container one level up + var blockScopeContainer: IsBlockScopedContainer; + var lastContainer: HasLocals; + var delayedTypeAliases: (JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag)[]; + var seenThisKeyword: boolean; // state used by control flow analysis - let currentFlow: FlowNode; - let currentBreakTarget: FlowLabel | undefined; - let currentContinueTarget: FlowLabel | undefined; - let currentReturnTarget: FlowLabel | undefined; - let currentTrueTarget: FlowLabel | undefined; - let currentFalseTarget: FlowLabel | undefined; - let currentExceptionTarget: FlowLabel | undefined; - let preSwitchCaseFlow: FlowNode | undefined; - let activeLabelList: ActiveLabel | undefined; - let hasExplicitReturn: boolean; + var currentFlow: FlowNode; + var currentBreakTarget: FlowLabel | undefined; + var currentContinueTarget: FlowLabel | undefined; + var currentReturnTarget: FlowLabel | undefined; + var currentTrueTarget: FlowLabel | undefined; + var currentFalseTarget: FlowLabel | undefined; + var currentExceptionTarget: FlowLabel | undefined; + var preSwitchCaseFlow: FlowNode | undefined; + var activeLabelList: ActiveLabel | undefined; + var hasExplicitReturn: boolean; // state used for emit helpers - let emitFlags: NodeFlags; + var emitFlags: NodeFlags; // If this file is an external module, then it is automatically in strict-mode according to // ES6. If it is not an external module, then we'll determine if it is in strict mode or // not depending on if we see "use strict" in certain places or if we hit a class/namespace // or if compiler options contain alwaysStrict. - let inStrictMode: boolean; + var inStrictMode: boolean; // If we are binding an assignment pattern, we will bind certain expressions differently. - let inAssignmentPattern = false; + var inAssignmentPattern = false; - let symbolCount = 0; + var symbolCount = 0; - let Symbol: new (flags: SymbolFlags, name: __String) => Symbol; - let classifiableNames: Set<__String>; + var Symbol: new (flags: SymbolFlags, name: __String) => Symbol; + var classifiableNames: Set<__String>; - const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable }; - const reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable }; - const bindBinaryExpressionFlow = createBindBinaryExpressionFlow(); + var unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable }; + var reportedUnreachableFlow: FlowNode = { flags: FlowFlags.Unreachable }; + var bindBinaryExpressionFlow = createBindBinaryExpressionFlow(); + /* eslint-enable no-var */ /** * Inside the binder, we may create a diagnostic for an as-yet unbound node (with potentially no parent pointers, implying no accessible source file) From 8d63347a60b5be010f07647a8ccf4fcc541cafaf Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:47:35 -0800 Subject: [PATCH 2/2] Return earlier --- src/compiler/binder.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 24fce4d4c7076..a6e497fc8a414 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -547,6 +547,8 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { var bindBinaryExpressionFlow = createBindBinaryExpressionFlow(); /* eslint-enable no-var */ + return bindSourceFile; + /** * Inside the binder, we may create a diagnostic for an as-yet unbound node (with potentially no parent pointers, implying no accessible source file) * If so, the node _must_ be in the current file (as that's the only way anything could have traversed to it to yield it as the error node) @@ -602,8 +604,6 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { emitFlags = NodeFlags.None; } - return bindSourceFile; - function bindInStrictMode(file: SourceFile, opts: CompilerOptions): boolean { if (getStrictOptionValue(opts, "alwaysStrict") && !file.isDeclarationFile) { // bind in strict mode source files with alwaysStrict option