aboutsummaryrefslogtreecommitdiff
path: root/node_modules/babylon/lib/util/location.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
commitabd94a7f5a50f43c797a11b53549ae48fff667c3 (patch)
treeab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/babylon/lib/util/location.js
parenta0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff)
add node_modules to address #4364
Diffstat (limited to 'node_modules/babylon/lib/util/location.js')
-rw-r--r--node_modules/babylon/lib/util/location.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/node_modules/babylon/lib/util/location.js b/node_modules/babylon/lib/util/location.js
new file mode 100644
index 000000000..9188f9a95
--- /dev/null
+++ b/node_modules/babylon/lib/util/location.js
@@ -0,0 +1,45 @@
+"use strict";
+
+exports.__esModule = true;
+exports.SourceLocation = exports.Position = undefined;
+exports.getLineInfo = getLineInfo;
+
+var _whitespace = require("./whitespace");
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+// These are used when `options.locations` is on, for the
+// `startLoc` and `endLoc` properties.
+
+var Position = exports.Position = function Position(line, col) {
+ _classCallCheck(this, Position);
+
+ this.line = line;
+ this.column = col;
+};
+
+var SourceLocation = exports.SourceLocation = function SourceLocation(start, end) {
+ _classCallCheck(this, SourceLocation);
+
+ this.start = start;
+ this.end = end;
+};
+
+// The `getLineInfo` function is mostly useful when the
+// `locations` option is off (for performance reasons) and you
+// want to find the line/column position for a given character
+// offset. `input` should be the code string that the offset refers
+// into.
+
+function getLineInfo(input, offset) {
+ for (var line = 1, cur = 0;;) {
+ _whitespace.lineBreakG.lastIndex = cur;
+ var match = _whitespace.lineBreakG.exec(input);
+ if (match && match.index < offset) {
+ ++line;
+ cur = match.index + match[0].length;
+ } else {
+ return new Position(line, offset - cur);
+ }
+ }
+} \ No newline at end of file