UNPKG

787 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const File_1 = require("../../project/File");
4/**
5 * Find the given source location within this project
6 * @param {string} f file info: Path or File
7 * @param {string} content
8 * @param {number} offset
9 * @return {SourceLocation}
10 */
11function toSourceLocation(f, content, offset) {
12 if (!content || offset < 0 || offset > content.length - 1) {
13 return undefined;
14 }
15 const lines = content.substr(0, offset)
16 .split("\n");
17 return {
18 path: File_1.isFile(f) ? f.path : f,
19 lineFrom1: lines.length,
20 columnFrom1: lines[lines.length - 1].length + 1,
21 offset,
22 };
23}
24exports.toSourceLocation = toSourceLocation;
25//# sourceMappingURL=sourceLocationUtils.js.map
\No newline at end of file