source: trip-planner-front/node_modules/parse5/lib/extensions/error-reporting/parser-mixin.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1'use strict';
2
3const ErrorReportingMixinBase = require('./mixin-base');
4const ErrorReportingTokenizerMixin = require('./tokenizer-mixin');
5const LocationInfoTokenizerMixin = require('../location-info/tokenizer-mixin');
6const Mixin = require('../../utils/mixin');
7
8class 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
52module.exports = ErrorReportingParserMixin;
Note: See TracBrowser for help on using the repository browser.