ScopeHoistingBailoutsWarning.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. /** @typedef {{ reason: string, count: number, names: string[] }} ScopeHoistingBailoutGroup */
  8. /**
  9. * @param {ScopeHoistingBailoutGroup} group one reason and what it applied to
  10. * @returns {string} one printed line
  11. */
  12. const formatGroup = ({ reason, count, names }) => {
  13. const shown = names.join(", ");
  14. const rest = count - names.length;
  15. return ` ${count} × ${reason}\n ${shown}${rest > 0 ? ` and ${rest} more` : ""}`;
  16. };
  17. class ScopeHoistingBailoutsWarning extends WebpackError {
  18. /**
  19. * Creates an instance of ScopeHoistingBailoutsWarning.
  20. * @param {ScopeHoistingBailoutGroup[]} groups the reasons, most modules first
  21. * @param {number} total how many modules were left out
  22. */
  23. constructor(groups, total) {
  24. super(
  25. `scope hoisting: ${total} ${total === 1 ? "module was" : "modules were"} not merged into the scope of ${total === 1 ? "its importer" : "their importers"}, so each keeps its own wrapper:
  26. ${groups.map(formatGroup).join("\n")}
  27. Concatenation needs a module to be ESM and statically analyzable. For more info visit https://webpack.js.org/plugins/module-concatenation-plugin/`
  28. );
  29. this.name = "ScopeHoistingBailoutsWarning";
  30. }
  31. }
  32. module.exports = ScopeHoistingBailoutsWarning;