Error.js 796 B

12345678910111213141516171819202122232425262728293031
  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;