1 | 'use strict';
|
---|
2 |
|
---|
3 | const ErrorReportingMixinBase = require('./mixin-base');
|
---|
4 | const ErrorReportingTokenizerMixin = require('./tokenizer-mixin');
|
---|
5 | const LocationInfoTokenizerMixin = require('../location-info/tokenizer-mixin');
|
---|
6 | const Mixin = require('../../utils/mixin');
|
---|
7 |
|
---|
8 | class ErrorReportingParserMixin extends ErrorReportingMixinBase {
|
---|
9 | constructor(parser, opts) {
|
---|
10 | super(parser, opts);
|
---|
11 |
|
---|
12 | this.opts = opts;
|
---|
13 | this.ctLoc = null;
|
---|
14 | this.locBeforeToken = false;
|
---|
15 | }
|
---|
16 |
|
---|
17 | _setErrorLocation(err) {
|
---|
18 | if (this.ctLoc) {
|
---|
19 | err.startLine = this.ctLoc.startLine;
|
---|
20 | err.startCol = this.ctLoc.startCol;
|
---|
21 | err.startOffset = this.ctLoc.startOffset;
|
---|
22 |
|
---|
23 | err.endLine = this.locBeforeToken ? this.ctLoc.startLine : this.ctLoc.endLine;
|
---|
24 | err.endCol = this.locBeforeToken ? this.ctLoc.startCol : this.ctLoc.endCol;
|
---|
25 | err.endOffset = this.locBeforeToken ? this.ctLoc.startOffset : this.ctLoc.endOffset;
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | _getOverriddenMethods(mxn, orig) {
|
---|
30 | return {
|
---|
31 | _bootstrap(document, fragmentContext) {
|
---|
32 | orig._bootstrap.call(this, document, fragmentContext);
|
---|
33 |
|
---|
34 | Mixin.install(this.tokenizer, ErrorReportingTokenizerMixin, mxn.opts);
|
---|
35 | Mixin.install(this.tokenizer, LocationInfoTokenizerMixin);
|
---|
36 | },
|
---|
37 |
|
---|
38 | _processInputToken(token) {
|
---|
39 | mxn.ctLoc = token.location;
|
---|
40 |
|
---|
41 | orig._processInputToken.call(this, token);
|
---|
42 | },
|
---|
43 |
|
---|
44 | _err(code, options) {
|
---|
45 | mxn.locBeforeToken = options && options.beforeToken;
|
---|
46 | mxn._reportError(code);
|
---|
47 | }
|
---|
48 | };
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | module.exports = ErrorReportingParserMixin;
|
---|