deprecated.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(exports, definition) {
  11. /******/ for(var key in definition) {
  12. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14. /******/ }
  15. /******/ }
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  20. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /************************************************************************/
  25. var __webpack_exports__ = {};
  26. // EXPORTS
  27. __webpack_require__.d(__webpack_exports__, {
  28. "default": function() { return /* binding */ deprecated; }
  29. });
  30. // UNUSED EXPORTS: logged
  31. ;// CONCATENATED MODULE: external ["wp","hooks"]
  32. var external_wp_hooks_namespaceObject = window["wp"]["hooks"];
  33. ;// CONCATENATED MODULE: ./node_modules/@wordpress/deprecated/build-module/index.js
  34. /**
  35. * WordPress dependencies
  36. */
  37. /**
  38. * Object map tracking messages which have been logged, for use in ensuring a
  39. * message is only logged once.
  40. *
  41. * @type {Record<string, true | undefined>}
  42. */
  43. const logged = Object.create(null);
  44. /**
  45. * Logs a message to notify developers about a deprecated feature.
  46. *
  47. * @param {string} feature Name of the deprecated feature.
  48. * @param {Object} [options] Personalisation options
  49. * @param {string} [options.since] Version in which the feature was deprecated.
  50. * @param {string} [options.version] Version in which the feature will be removed.
  51. * @param {string} [options.alternative] Feature to use instead
  52. * @param {string} [options.plugin] Plugin name if it's a plugin feature
  53. * @param {string} [options.link] Link to documentation
  54. * @param {string} [options.hint] Additional message to help transition away from the deprecated feature.
  55. *
  56. * @example
  57. * ```js
  58. * import deprecated from '@wordpress/deprecated';
  59. *
  60. * deprecated( 'Eating meat', {
  61. * since: '2019.01.01'
  62. * version: '2020.01.01',
  63. * alternative: 'vegetables',
  64. * plugin: 'the earth',
  65. * hint: 'You may find it beneficial to transition gradually.',
  66. * } );
  67. *
  68. * // Logs: 'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
  69. * ```
  70. */
  71. function deprecated(feature) {
  72. let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  73. const {
  74. since,
  75. version,
  76. alternative,
  77. plugin,
  78. link,
  79. hint
  80. } = options;
  81. const pluginMessage = plugin ? ` from ${plugin}` : '';
  82. const sinceMessage = since ? ` since version ${since}` : '';
  83. const versionMessage = version ? ` and will be removed${pluginMessage} in version ${version}` : '';
  84. const useInsteadMessage = alternative ? ` Please use ${alternative} instead.` : '';
  85. const linkMessage = link ? ` See: ${link}` : '';
  86. const hintMessage = hint ? ` Note: ${hint}` : '';
  87. const message = `${feature} is deprecated${sinceMessage}${versionMessage}.${useInsteadMessage}${linkMessage}${hintMessage}`; // Skip if already logged.
  88. if (message in logged) {
  89. return;
  90. }
  91. /**
  92. * Fires whenever a deprecated feature is encountered
  93. *
  94. * @param {string} feature Name of the deprecated feature.
  95. * @param {?Object} options Personalisation options
  96. * @param {string} options.since Version in which the feature was deprecated.
  97. * @param {?string} options.version Version in which the feature will be removed.
  98. * @param {?string} options.alternative Feature to use instead
  99. * @param {?string} options.plugin Plugin name if it's a plugin feature
  100. * @param {?string} options.link Link to documentation
  101. * @param {?string} options.hint Additional message to help transition away from the deprecated feature.
  102. * @param {?string} message Message sent to console.warn
  103. */
  104. (0,external_wp_hooks_namespaceObject.doAction)('deprecated', feature, options, message); // eslint-disable-next-line no-console
  105. console.warn(message);
  106. logged[message] = true;
  107. }
  108. /** @typedef {import('utility-types').NonUndefined<Parameters<typeof deprecated>[1]>} DeprecatedOptions */
  109. (window.wp = window.wp || {}).deprecated = __webpack_exports__["default"];
  110. /******/ })()
  111. ;