-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
parser-mixin.js
48 lines (39 loc) · 1.64 KB
/
parser-mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { ErrorReportingMixinBase } from './mixin-base.js';
import { ErrorReportingTokenizerMixin } from './tokenizer-mixin.js';
import { LocationInfoTokenizerMixin } from '../location-info/tokenizer-mixin.js';
import { Mixin } from '../../utils/mixin.js';
export class ErrorReportingParserMixin extends ErrorReportingMixinBase {
constructor(parser, opts) {
super(parser, opts);
this.opts = opts;
this.ctLoc = null;
this.locBeforeToken = false;
}
_setErrorLocation(err) {
if (this.ctLoc) {
err.startLine = this.ctLoc.startLine;
err.startCol = this.ctLoc.startCol;
err.startOffset = this.ctLoc.startOffset;
err.endLine = this.locBeforeToken ? this.ctLoc.startLine : this.ctLoc.endLine;
err.endCol = this.locBeforeToken ? this.ctLoc.startCol : this.ctLoc.endCol;
err.endOffset = this.locBeforeToken ? this.ctLoc.startOffset : this.ctLoc.endOffset;
}
}
_getOverriddenMethods(mxn, orig) {
return {
_bootstrap(document, fragmentContext) {
orig._bootstrap.call(this, document, fragmentContext);
Mixin.install(this.tokenizer, ErrorReportingTokenizerMixin, mxn.opts);
Mixin.install(this.tokenizer, LocationInfoTokenizerMixin);
},
_processInputToken(token) {
mxn.ctLoc = token.location;
orig._processInputToken.call(this, token);
},
_err(code, options) {
mxn.locBeforeToken = options?.beforeToken;
mxn._reportError(code);
},
};
}
}