mixin-base.js 970 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const Mixin = require('../../utils/mixin');
  3. class ErrorReportingMixinBase extends Mixin {
  4. constructor(host, opts) {
  5. super(host);
  6. this.posTracker = null;
  7. this.onParseError = opts.onParseError;
  8. }
  9. _setErrorLocation(err) {
  10. err.startLine = err.endLine = this.posTracker.line;
  11. err.startCol = err.endCol = this.posTracker.col;
  12. err.startOffset = err.endOffset = this.posTracker.offset;
  13. }
  14. _reportError(code) {
  15. const err = {
  16. code: code,
  17. startLine: -1,
  18. startCol: -1,
  19. startOffset: -1,
  20. endLine: -1,
  21. endCol: -1,
  22. endOffset: -1
  23. };
  24. this._setErrorLocation(err);
  25. this.onParseError(err);
  26. }
  27. _getOverriddenMethods(mxn) {
  28. return {
  29. _err(code) {
  30. mxn._reportError(code);
  31. }
  32. };
  33. }
  34. }
  35. module.exports = ErrorReportingMixinBase;