|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | /**
|
|---|
| 9 | * @typedef {object} GeneratedSourceInfo
|
|---|
| 10 | * @property {number=} generatedLine generated line
|
|---|
| 11 | * @property {number=} generatedColumn generated column
|
|---|
| 12 | * @property {string=} source source
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * @param {string | undefined} source source
|
|---|
| 17 | * @returns {GeneratedSourceInfo} source info
|
|---|
| 18 | */
|
|---|
| 19 | const getGeneratedSourceInfo = (source) => {
|
|---|
| 20 | if (source === undefined) {
|
|---|
| 21 | return {};
|
|---|
| 22 | }
|
|---|
| 23 | const lastLineStart = source.lastIndexOf("\n");
|
|---|
| 24 | if (lastLineStart === -1) {
|
|---|
| 25 | return {
|
|---|
| 26 | generatedLine: 1,
|
|---|
| 27 | generatedColumn: source.length,
|
|---|
| 28 | source,
|
|---|
| 29 | };
|
|---|
| 30 | }
|
|---|
| 31 | // Use native indexOf to scan for newlines instead of charCodeAt loops.
|
|---|
| 32 | // This is significantly faster on large sources since indexOf uses
|
|---|
| 33 | // vectorized/native string scanning.
|
|---|
| 34 | let generatedLine = 2;
|
|---|
| 35 | let idx = source.indexOf("\n");
|
|---|
| 36 | while (idx !== -1 && idx < lastLineStart) {
|
|---|
| 37 | generatedLine++;
|
|---|
| 38 | idx = source.indexOf("\n", idx + 1);
|
|---|
| 39 | }
|
|---|
| 40 | return {
|
|---|
| 41 | generatedLine,
|
|---|
| 42 | generatedColumn: source.length - lastLineStart - 1,
|
|---|
| 43 | source,
|
|---|
| 44 | };
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | module.exports = getGeneratedSourceInfo;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.