UNPKG

1.14 kBJavaScriptView Raw
1/**
2 * Track current position in code generation.
3 */
4
5"use strict";
6
7exports.__esModule = true;
8// istanbul ignore next
9
10function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
12var Position = (function () {
13 function Position() {
14 _classCallCheck(this, Position);
15
16 this.line = 1;
17 this.column = 0;
18 }
19
20 /**
21 * Push a string to the current position, mantaining the current line and column.
22 */
23
24 Position.prototype.push = function push(str) {
25 for (var i = 0; i < str.length; i++) {
26 if (str[i] === "\n") {
27 this.line++;
28 this.column = 0;
29 } else {
30 this.column++;
31 }
32 }
33 };
34
35 /**
36 * Unshift a string from the current position, mantaining the current line and column.
37 */
38
39 Position.prototype.unshift = function unshift(str) {
40 for (var i = 0; i < str.length; i++) {
41 if (str[i] === "\n") {
42 this.line--;
43 } else {
44 this.column--;
45 }
46 }
47 };
48
49 return Position;
50})();
51
52exports["default"] = Position;
53module.exports = exports["default"];
\No newline at end of file