From 2ebc6e14bcab2bce9a26916de898394eef10f016 Mon Sep 17 00:00:00 2001 From: Ebrahim Haji <14169174+ebrahim95@users.noreply.github.com> Date: Tue, 9 Jan 2024 15:20:41 -0600 Subject: [PATCH] fix: prevent console logging duplicate deprecation warnings (#7733) * (feat): added Set to prevent console logging multiple deprecation warnings #7719 * feat!: added Set to prevent console logging multiple deprecation warnings #7719 * refactor: renamed variable and rewrote comment Edited By Cpcallen Co-authored-by: Christopher Allen * refactor: added guard clause and rewrote comment Edited By Cpcallen Co-authored-by: Christopher Allen * refactor: removed checkMsg Variable name and replaced it with previousWarnings * refactor: removed checkMsg Variable name and replaced it with previousWarnings --------- Co-authored-by: Christopher Allen --- core/utils/deprecation.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/utils/deprecation.ts b/core/utils/deprecation.ts index da7977c3e..c793b5f57 100644 --- a/core/utils/deprecation.ts +++ b/core/utils/deprecation.ts @@ -6,6 +6,9 @@ // Former goog.module ID: Blockly.utils.deprecation +// Set of previously-emitted warnings. +const previousWarnings = 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.'; } + + // Don't log deprecation warnings multiple times. + if (previousWarnings.has(msg)) { + return; + } + + previousWarnings.add(msg); console.warn(msg); }