aboutsummaryrefslogtreecommitdiff
path: root/node_modules/parse5/lib/extensions/position-tracking/preprocessor-mixin.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-02-09 17:58:07 +0100
committerMinteck <contact@minteck.org>2022-02-09 17:58:07 +0100
commit22a25ded9f7d9c9a96cce8d1bc12475ca0434201 (patch)
tree0e33d0650fe58f41c00bbc4b8047956905766823 /node_modules/parse5/lib/extensions/position-tracking/preprocessor-mixin.js
parent8f54d903fb3470823a5e4d6ff4655de009836245 (diff)
downloadyoutoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.gz
youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.bz2
youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.zip
Major update
Diffstat (limited to 'node_modules/parse5/lib/extensions/position-tracking/preprocessor-mixin.js')
-rw-r--r--node_modules/parse5/lib/extensions/position-tracking/preprocessor-mixin.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/node_modules/parse5/lib/extensions/position-tracking/preprocessor-mixin.js b/node_modules/parse5/lib/extensions/position-tracking/preprocessor-mixin.js
new file mode 100644
index 0000000..3a07d78
--- /dev/null
+++ b/node_modules/parse5/lib/extensions/position-tracking/preprocessor-mixin.js
@@ -0,0 +1,64 @@
+'use strict';
+
+const Mixin = require('../../utils/mixin');
+
+class PositionTrackingPreprocessorMixin extends Mixin {
+ constructor(preprocessor) {
+ super(preprocessor);
+
+ this.preprocessor = preprocessor;
+ this.isEol = false;
+ this.lineStartPos = 0;
+ this.droppedBufferSize = 0;
+
+ this.offset = 0;
+ this.col = 0;
+ this.line = 1;
+ }
+
+ _getOverriddenMethods(mxn, orig) {
+ return {
+ advance() {
+ const pos = this.pos + 1;
+ const ch = this.html[pos];
+
+ //NOTE: LF should be in the last column of the line
+ if (mxn.isEol) {
+ mxn.isEol = false;
+ mxn.line++;
+ mxn.lineStartPos = pos;
+ }
+
+ if (ch === '\n' || (ch === '\r' && this.html[pos + 1] !== '\n')) {
+ mxn.isEol = true;
+ }
+
+ mxn.col = pos - mxn.lineStartPos + 1;
+ mxn.offset = mxn.droppedBufferSize + pos;
+
+ return orig.advance.call(this);
+ },
+
+ retreat() {
+ orig.retreat.call(this);
+
+ mxn.isEol = false;
+ mxn.col = this.pos - mxn.lineStartPos + 1;
+ },
+
+ dropParsedChunk() {
+ const prevPos = this.pos;
+
+ orig.dropParsedChunk.call(this);
+
+ const reduction = prevPos - this.pos;
+
+ mxn.lineStartPos -= reduction;
+ mxn.droppedBufferSize += reduction;
+ mxn.offset = mxn.droppedBufferSize + this.pos;
+ }
+ };
+ }
+}
+
+module.exports = PositionTrackingPreprocessorMixin;