Skip to content

Commit a6bfdaa

Browse files
committed
Try using var, like in Parser namespace
1 parent f2c6bb4 commit a6bfdaa

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/compiler/debug.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,22 @@ export interface LoggingHost {
106106

107107
/** @internal */
108108
export namespace Debug {
109-
/* eslint-disable prefer-const */
110-
let currentAssertionLevel = AssertionLevel.None;
111-
export let currentLogLevel = LogLevel.Warning;
112-
export let isDebugging = false;
113-
export let loggingHost: LoggingHost | undefined;
114-
/* eslint-enable prefer-const */
109+
// Why var? It avoids TDZ checks in the runtime which can be costly.
110+
// See: https://github.com/microsoft/TypeScript/issues/52924
111+
// TODO(jakebailey): restore to let/const once Debug is no longer a namespace.
112+
/* eslint-disable no-var */
113+
var currentAssertionLevel = AssertionLevel.None;
114+
export var currentLogLevel = LogLevel.Warning;
115+
export var isDebugging = false;
116+
export var loggingHost: LoggingHost | undefined;
117+
118+
var enumMemberCache = new Map<any, SortedReadonlyArray<[number, string]>>();
119+
120+
var isDebugInfoEnabled = false;
121+
122+
var flowNodeProto: FlowNodeBase | undefined;
123+
var nodeArrayProto: NodeArray<Node> | undefined;
124+
/* eslint-enable no-var */
115125

116126
export function shouldLog(level: LogLevel): boolean {
117127
return currentLogLevel <= level;
@@ -373,7 +383,6 @@ export namespace Debug {
373383
return value.toString();
374384
}
375385

376-
const enumMemberCache = new Map<any, SortedReadonlyArray<[number, string]>>();
377386

378387
function getEnumMembers(enumObject: any) {
379388
// Assuming enum objects do not change at runtime, we can cache the enum members list
@@ -457,9 +466,7 @@ export namespace Debug {
457466
return formatEnum(facts, (ts as any).TypeFacts, /*isFlags*/ true);
458467
}
459468

460-
let isDebugInfoEnabled = false;
461469

462-
let flowNodeProto: FlowNodeBase | undefined;
463470

464471
function attachFlowNodeDebugInfoWorker(flowNode: FlowNodeBase) {
465472
if (!("__debugFlowFlags" in flowNode)) { // eslint-disable-line local/no-in-operator
@@ -508,7 +515,7 @@ export namespace Debug {
508515
}
509516
}
510517

511-
let nodeArrayProto: NodeArray<Node> | undefined;
518+
512519

513520
function attachNodeArrayDebugInfoWorker(array: NodeArray<Node>) {
514521
if (!("__tsDebuggerDisplay" in array)) { // eslint-disable-line local/no-in-operator

0 commit comments

Comments
 (0)