You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
801 B

4 years ago
  1. "use strict";
  2. const STRIP_FILENAME_RE = /^[^:]+: /;
  3. const format = err => {
  4. if (err instanceof SyntaxError) {
  5. err.name = "SyntaxError";
  6. err.message = err.message.replace(STRIP_FILENAME_RE, "");
  7. err.hideStack = true;
  8. } else if (err instanceof TypeError) {
  9. err.name = null;
  10. err.message = err.message.replace(STRIP_FILENAME_RE, "");
  11. err.hideStack = true;
  12. }
  13. return err;
  14. };
  15. class LoaderError extends Error {
  16. constructor(err) {
  17. super();
  18. const {
  19. name,
  20. message,
  21. codeFrame,
  22. hideStack
  23. } = format(err);
  24. this.name = "BabelLoaderError";
  25. this.message = `${name ? `${name}: ` : ""}${message}\n\n${codeFrame}\n`;
  26. this.hideStack = hideStack;
  27. Error.captureStackTrace(this, this.constructor);
  28. }
  29. }
  30. module.exports = LoaderError;