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