PureAnnotationsWarning.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Alexander Akait @alexander-akait
  4. */
  5. "use strict";
  6. const WebpackError = require("./WebpackError");
  7. /**
  8. * @typedef {object} PureAnnotationDetails
  9. * @property {string} name the module, shortened for the report
  10. * @property {number} count how many of its annotations do nothing
  11. */
  12. class PureAnnotationsWarning extends WebpackError {
  13. /**
  14. * Creates an instance of PureAnnotationsWarning.
  15. * @param {PureAnnotationDetails[]} modules the worst offenders, most first
  16. * @param {number} total how many annotations do nothing in all
  17. */
  18. constructor(modules, total) {
  19. const list = modules
  20. .map((module) => `\n ${module.name} (${module.count})`)
  21. .join("");
  22. super(
  23. `pure annotations: ${total} '/*#__PURE__*/' ${total === 1 ? "annotation does" : "annotations do"} nothing:${list}\nThe annotation is read only where it sits directly before a call, a 'new', or a tagged template — anywhere else it is a comment, and the code it was meant to make droppable is kept.\nFor more info visit https://webpack.js.org/guides/tree-shaking/`
  24. );
  25. /** @type {string} */
  26. this.name = "PureAnnotationsWarning";
  27. }
  28. }
  29. module.exports = PureAnnotationsWarning;