source: trip-planner-front/node_modules/parse5/lib/extensions/position-tracking/preprocessor-mixin.js@ 76712b2

Last change on this file since 76712b2 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 Mixin = require('../../utils/mixin');
4
5class PositionTrackingPreprocessorMixin extends Mixin {
6 constructor(preprocessor) {
7 super(preprocessor);
8
9 this.preprocessor = preprocessor;
10 this.isEol = false;
11 this.lineStartPos = 0;
12 this.droppedBufferSize = 0;
13
14 this.offset = 0;
15 this.col = 0;
16 this.line = 1;
17 }
18
19 _getOverriddenMethods(mxn, orig) {
20 return {
21 advance() {
22 const pos = this.pos + 1;
23 const ch = this.html[pos];
24
25 //NOTE: LF should be in the last column of the line
26 if (mxn.isEol) {
27 mxn.isEol = false;
28 mxn.line++;
29 mxn.lineStartPos = pos;
30 }
31
32 if (ch === '\n' || (ch === '\r' && this.html[pos + 1] !== '\n')) {
33 mxn.isEol = true;
34 }
35
36 mxn.col = pos - mxn.lineStartPos + 1;
37 mxn.offset = mxn.droppedBufferSize + pos;
38
39 return orig.advance.call(this);
40 },
41
42 retreat() {
43 orig.retreat.call(this);
44
45 mxn.isEol = false;
46 mxn.col = this.pos - mxn.lineStartPos + 1;
47 },
48
49 dropParsedChunk() {
50 const prevPos = this.pos;
51
52 orig.dropParsedChunk.call(this);
53
54 const reduction = prevPos - this.pos;
55
56 mxn.lineStartPos -= reduction;
57 mxn.droppedBufferSize += reduction;
58 mxn.offset = mxn.droppedBufferSize + this.pos;
59 }
60 };
61 }
62}
63
64module.exports = PositionTrackingPreprocessorMixin;
Note: See TracBrowser for help on using the repository browser.