github
<a href="https://github.com/posthtml/posthtml-parser/commit/<a class=hub.com/posthtml/posthtml-parser/commit/<a class="double-link" href="https://git"><a class=hub.com/posthtml/posthtml-parser/commit/<a class="double-link" href="https://git"><a class=hub.com/posthtml/posthtml-parser/commit/<a class="double-link" href="https://git"><a class=hub.com/posthtml/posthtml-parser/commit/6048fa0a6a6ececf043e10d15a4a4498c0f2658f">6048fa0a6"><a href="https://github.com/posthtml/posthtml-parser/commit/</a><a class="double-link" href="https://github.com/posthtml/posthtml-parser/commit/<a class="double-link" href="https://git"><a class=</a>hub.com/posthtml/posthtml-parser/commit/<a class="double-link" href="https://git"><a class=</a>hub.com/posthtml/posthtml-parser/commit/<a class="double-link" href="https://git"><a class=</a>hub.com/posthtml/posthtml-parser/commit/<a class="double-link" href="https://git"><a class=</a>hub.com/posthtml/posthtml-parser/commit/6048fa0a6a6ececf043e10d15a4a4498c0f2658f">6048fa0a6</a><a href="https://github.com/posthtml/posthtml-parser/commit/6048fa0a6a6ececf043e10d15a4a4498c0f2658f">">&lt;a href=&quot;https://github.com/posthtml/posthtml-parser/commit/</a><a class="double-link" href="https://github.com/posthtml/posthtml-parser/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/posthtml/posthtml-parser/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/posthtml/posthtml-parser/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/posthtml/posthtml-parser/commit/&lt;a class=&quot;double-link&quot; href=&quot;https://git">&lt;a class=</a>hub.com/posthtml/posthtml-parser/commit/6048fa0a6a6ececf043e10d15a4a4498c0f2658f">6048fa0a6</a><a href="https://github.com/posthtml/posthtml-parser/commit/6048fa0a6a6ececf043e10d15a4a4498c0f2658f">&quot;&gt;&amp;lt;a href=&amp;quot;https://github.com/posthtml/posthtml-parser/commit/&lt;/a&gt;&lt;a... (continued)
43 of 46 branches covered (93.48%)
55 of 55 new or added lines in 2 files covered. (100.0%)
200 of 217 relevant lines covered (92.17%)
13.26 hits per line
|
import {Position} from '../types/index.d'; |
|
|
|
1✔ |
|
export class LocationTracker { |
|
|
private readonly source: string; |
1✔ |
|
private lastPosition: Position;
|
|
|
private lastIndex: number;
|
1✔ |
|
|
1✔ |
|
constructor(source: string) {
|
1✔ |
|
this.source = source;
|
1✔ |
|
this.lastPosition = {
|
1✔ |
|
line: 1, |
1✔ |
|
column: 1
|
1✔ |
|
}; |
1✔ |
|
|
1✔ |
|
this.lastIndex = 0; |
|
|
} |
26✔ |
|
|
26✔ |
|
getPosition(index: number): Position { |
|
|
if (index < this.lastIndex) { |
26✔ |
|
throw new Error('Source indices must be monotonic'); |
26✔ |
|
} |
26✔ |
|
|
26✔ |
|
while (this.lastIndex < index) { |
1✔ |
|
if (this.source.charCodeAt(this.lastIndex) === /* \n */ 10) { |
|
|
this.lastPosition.line++;
|
× |
|
this.lastPosition.column = 1; |
28✔ |
|
} else {
|
28✔ |
|
this.lastPosition.column++;
|
|
|
} |
154✔ |
|
|
154✔ |
|
this.lastIndex++;
|
|
|
} |
1✔ |
|
|
1✔ |
|
return {
|
1✔ |
|
line: this.lastPosition.line, |
1✔ |
|
column: this.lastPosition.column
|
|
|
}; |
153✔ |
|
} |
153✔ |
|
} |
153✔ |