mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
* (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 <cpcallen+github@gmail.com> * refactor: added guard clause and rewrote comment Edited By Cpcallen Co-authored-by: Christopher Allen <cpcallen+github@gmail.com> * 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 <cpcallen+github@gmail.com>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
// 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.
|
|
*
|
|
* @param name The name of the function or property.
|
|
* @param deprecationDate The date of deprecation. Prefer 'version n.0.0'
|
|
* format, and fall back to 'month yyyy' or 'quarter yyyy' format.
|
|
* @param deletionDate The date of deletion. Prefer 'version n.0.0'
|
|
* format, and fall back to 'month yyyy' or 'quarter yyyy' format.
|
|
* @param opt_use The name of a function or property to use instead, if any.
|
|
* @internal
|
|
*/
|
|
export function warn(
|
|
name: string,
|
|
deprecationDate: string,
|
|
deletionDate: string,
|
|
opt_use?: string,
|
|
) {
|
|
let msg =
|
|
name +
|
|
' was deprecated in ' +
|
|
deprecationDate +
|
|
' and will be deleted in ' +
|
|
deletionDate +
|
|
'.';
|
|
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);
|
|
}
|