main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
692 bytes
|
Rev | Line | |
---|
[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const CHAR_CODE_NEW_LINE = "\n".charCodeAt(0);
|
---|
| 9 |
|
---|
| 10 | const getGeneratedSourceInfo = source => {
|
---|
| 11 | if (source === undefined) {
|
---|
| 12 | return {};
|
---|
| 13 | }
|
---|
| 14 | const lastLineStart = source.lastIndexOf("\n");
|
---|
| 15 | if (lastLineStart === -1) {
|
---|
| 16 | return {
|
---|
| 17 | generatedLine: 1,
|
---|
| 18 | generatedColumn: source.length,
|
---|
| 19 | source
|
---|
| 20 | };
|
---|
| 21 | }
|
---|
| 22 | let generatedLine = 2;
|
---|
| 23 | for (let i = 0; i < lastLineStart; i++) {
|
---|
| 24 | if (source.charCodeAt(i) === CHAR_CODE_NEW_LINE) generatedLine++;
|
---|
| 25 | }
|
---|
| 26 | return {
|
---|
| 27 | generatedLine,
|
---|
| 28 | generatedColumn: source.length - lastLineStart - 1,
|
---|
| 29 | source
|
---|
| 30 | };
|
---|
| 31 | };
|
---|
| 32 |
|
---|
| 33 | module.exports = getGeneratedSourceInfo;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.