Skip to content

Commit

Permalink
fix: prevent console logging duplicate deprecation warnings (#7733)
Browse files Browse the repository at this point in the history
* (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 <[email protected]>

* refactor: added guard clause and rewrote comment

  Edited By Cpcallen
  Co-authored-by: Christopher Allen <[email protected]>

* 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 <[email protected]>
  • Loading branch information
ebrahim95 and cpcallen authored Jan 9, 2024
1 parent a5fafd7 commit 2ebc6e1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/utils/deprecation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}

0 comments on commit 2ebc6e1

Please sign in to comment.