From bb42b5c1a65669acf19668b3993bf51786d6787b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 6 Dec 2022 10:41:39 -0800 Subject: [PATCH] Unconditionally use WeakMap in debug (#51785) --- src/compiler/debug.ts | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index 9bd8471f531..ffbef3ef157 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -588,23 +588,8 @@ export namespace Debug { if (isDebugInfoEnabled) return; // avoid recomputing - let weakTypeTextMap: WeakMap | undefined; - let weakNodeTextMap: WeakMap | undefined; - - function getWeakTypeTextMap() { - if (weakTypeTextMap === undefined) { - if (typeof WeakMap === "function") weakTypeTextMap = new WeakMap(); - } - return weakTypeTextMap; - } - - function getWeakNodeTextMap() { - if (weakNodeTextMap === undefined) { - if (typeof WeakMap === "function") weakNodeTextMap = new WeakMap(); - } - return weakNodeTextMap; - } - + const weakTypeTextMap = new WeakMap(); + const weakNodeTextMap = new WeakMap(); // Add additional properties in debug mode to assist with debugging. Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, { @@ -658,11 +643,10 @@ export namespace Debug { __debugTypeToString: { value(this: Type) { // avoid recomputing - const map = getWeakTypeTextMap(); - let text = map?.get(this); + let text = weakTypeTextMap.get(this); if (text === undefined) { text = this.checker.typeToString(this); - map?.set(this, text); + weakTypeTextMap.set(this, text); } return text; } @@ -738,13 +722,12 @@ export namespace Debug { value(this: Node, includeTrivia?: boolean) { if (nodeIsSynthesized(this)) return ""; // avoid recomputing - const map = getWeakNodeTextMap(); - let text = map?.get(this); + let text = weakNodeTextMap.get(this); if (text === undefined) { const parseNode = getParseTreeNode(this); const sourceFile = parseNode && getSourceFileOfNode(parseNode); text = sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; - map?.set(this, text); + weakNodeTextMap.set(this, text); } return text; }