From c9a36d2f6ef32881c668d5502dc34430f027d88d Mon Sep 17 00:00:00 2001 From: Ebrahim Haji Date: Tue, 19 Dec 2023 17:52:12 -0600 Subject: [PATCH 1/6] (feat): added Set to prevent console logging multiple deprecation warnings #7719 --- core/utils/deprecation.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/utils/deprecation.ts b/core/utils/deprecation.ts index da7977c3e84..9b03ba17026 100644 --- a/core/utils/deprecation.ts +++ b/core/utils/deprecation.ts @@ -6,6 +6,9 @@ // Former goog.module ID: Blockly.utils.deprecation +// create a set variable to store messages +const checkMsg = new Set(); + /** * Warn developers that a function or property is deprecated. * @@ -33,5 +36,12 @@ export function warn( if (opt_use) { msg += '\nUse ' + opt_use + ' instead.'; } - console.warn(msg); + + // this will help prevent logging deprecation warnings multiple times + if (!checkMsg.has(msg)) { + checkMsg.add(msg); + console.warn(msg); + } else { + return; + } } From 5aa049756a4faecbcd53ba328740231985cdc77c Mon Sep 17 00:00:00 2001 From: Ebrahim Haji Date: Tue, 19 Dec 2023 17:52:12 -0600 Subject: [PATCH 2/6] feat!: added Set to prevent console logging multiple deprecation warnings #7719 --- core/utils/deprecation.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/utils/deprecation.ts b/core/utils/deprecation.ts index da7977c3e84..9b03ba17026 100644 --- a/core/utils/deprecation.ts +++ b/core/utils/deprecation.ts @@ -6,6 +6,9 @@ // Former goog.module ID: Blockly.utils.deprecation +// create a set variable to store messages +const checkMsg = new Set(); + /** * Warn developers that a function or property is deprecated. * @@ -33,5 +36,12 @@ export function warn( if (opt_use) { msg += '\nUse ' + opt_use + ' instead.'; } - console.warn(msg); + + // this will help prevent logging deprecation warnings multiple times + if (!checkMsg.has(msg)) { + checkMsg.add(msg); + console.warn(msg); + } else { + return; + } } From 466c00d87d3e75584a1da4d6f690d5a5975e6f2c Mon Sep 17 00:00:00 2001 From: Ebrahim Haji <14169174+ebrahim95@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:46:49 -0600 Subject: [PATCH 3/6] refactor: renamed variable and rewrote comment Edited By Cpcallen Co-authored-by: Christopher Allen --- core/utils/deprecation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/deprecation.ts b/core/utils/deprecation.ts index 9b03ba17026..615e742c1cb 100644 --- a/core/utils/deprecation.ts +++ b/core/utils/deprecation.ts @@ -6,8 +6,8 @@ // Former goog.module ID: Blockly.utils.deprecation -// create a set variable to store messages -const checkMsg = new Set(); +// Set of previously-emitted warnings. +const previousWarnings = new Set(); /** * Warn developers that a function or property is deprecated. From 4837ea18b55460ce16c98c1f07beabbffdbd2556 Mon Sep 17 00:00:00 2001 From: Ebrahim Haji <14169174+ebrahim95@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:47:36 -0600 Subject: [PATCH 4/6] refactor: added guard clause and rewrote comment Edited By Cpcallen Co-authored-by: Christopher Allen --- core/utils/deprecation.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/utils/deprecation.ts b/core/utils/deprecation.ts index 615e742c1cb..d0df9ab9c72 100644 --- a/core/utils/deprecation.ts +++ b/core/utils/deprecation.ts @@ -37,11 +37,11 @@ export function warn( msg += '\nUse ' + opt_use + ' instead.'; } - // this will help prevent logging deprecation warnings multiple times - if (!checkMsg.has(msg)) { - checkMsg.add(msg); - console.warn(msg); - } else { + // Don't log deprecation warnings multiple times. + if (checkMsg.has(msg)) { return; } + + checkMsg.add(msg); + console.warn(msg); } From 21f9017202e936e045595d62c7e3facc328cd7b6 Mon Sep 17 00:00:00 2001 From: Ebrahim Haji Date: Fri, 5 Jan 2024 15:16:39 -0600 Subject: [PATCH 5/6] refactor: removed checkMsg Variable name and replaced it with previousWarnings --- core/utils/deprecation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/deprecation.ts b/core/utils/deprecation.ts index d0df9ab9c72..c793b5f57dd 100644 --- a/core/utils/deprecation.ts +++ b/core/utils/deprecation.ts @@ -38,10 +38,10 @@ export function warn( } // Don't log deprecation warnings multiple times. - if (checkMsg.has(msg)) { + if (previousWarnings.has(msg)) { return; } - checkMsg.add(msg); + previousWarnings.add(msg); console.warn(msg); } From ed1ccc2b310f04a3bdabd36d15f31926ae9e707c Mon Sep 17 00:00:00 2001 From: Ebrahim Haji Date: Fri, 5 Jan 2024 15:16:39 -0600 Subject: [PATCH 6/6] refactor: removed checkMsg Variable name and replaced it with previousWarnings --- core/utils/deprecation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/deprecation.ts b/core/utils/deprecation.ts index d0df9ab9c72..c793b5f57dd 100644 --- a/core/utils/deprecation.ts +++ b/core/utils/deprecation.ts @@ -38,10 +38,10 @@ export function warn( } // Don't log deprecation warnings multiple times. - if (checkMsg.has(msg)) { + if (previousWarnings.has(msg)) { return; } - checkMsg.add(msg); + previousWarnings.add(msg); console.warn(msg); }