ParseError.js 719 B

1234567891011121314
  1. // https://stackoverflow.com/a/46971044/970769
  2. // "Breaking changes in Typescript 2.1"
  3. // "Extending built-ins like Error, Array, and Map may no longer work."
  4. // "As a recommendation, you can manually adjust the prototype immediately after any super(...) calls."
  5. // https://github.com/Microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
  6. export default class ParseError extends Error {
  7. constructor(code) {
  8. super(code)
  9. // Set the prototype explicitly.
  10. // Any subclass of FooError will have to manually set the prototype as well.
  11. Object.setPrototypeOf(this, ParseError.prototype)
  12. this.name = this.constructor.name
  13. }
  14. }