Skip to content

Commit e300453

Browse files
committed
Fix incorrect line in error messages
Resolves #2605
1 parent c528c0a commit e300453

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
### Features
44

5-
- Improved Korean translation coverage, #2602
5+
- Improved Korean translation coverage, #2602.
66

77
### Bug Fixes
88

99
- Added `@author` to the default list of recognized tags, #2603.
10-
- Anchor links are no longer incorrectly checked for relative paths, #2604
10+
- Anchor links are no longer incorrectly checked for relative paths, #2604.
11+
- Fixed an issue where line numbers reported in error messages could be incorrect, #2605.
1112

1213
### Thanks!
1314

src/lib/converter/comments/textParser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function textContent(
5151
const data: TextParserData = {
5252
sourcePath,
5353
token,
54-
pos: 0,
54+
pos: 0, // relative to the token
5555
i18n,
5656
warning,
5757
files: files,
@@ -77,7 +77,8 @@ export function textContent(
7777
),
7878
{
7979
kind: TokenSyntaxKind.Text,
80-
pos: ref.pos,
80+
// ref.pos is relative to the token, but this pos is relative to the file.
81+
pos: token.pos + ref.pos,
8182
text: token.text.slice(ref.pos, ref.end),
8283
},
8384
);

src/lib/utils/minimalSourceFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class MinimalSourceFile implements SourceFileLike {
2323
while (pos >= starts[starts.length - 1]) {
2424
const nextStart = this.text.indexOf(
2525
"\n",
26-
starts[starts.length - 1] + 1,
26+
starts[starts.length - 1],
2727
);
2828

2929
if (nextStart === -1) {

src/test/utils/minimalSourceFile.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ describe("MinimalSourceFile", () => {
2424
check("4", { line: 2, character: 0 });
2525
check("5", { line: 3, character: 0 });
2626
});
27+
28+
it("#2605 Should handle multiple consecutive newlines", () => {
29+
const sf = new MinimalSourceFile("a\n\nb", "");
30+
31+
equal(sf.getLineAndCharacterOfPosition(0), { line: 0, character: 0 }); // a
32+
equal(sf.getLineAndCharacterOfPosition(1), { line: 0, character: 1 }); // \n
33+
equal(sf.getLineAndCharacterOfPosition(2), { line: 1, character: 0 }); // \n
34+
equal(sf.getLineAndCharacterOfPosition(3), { line: 2, character: 0 }); // b
35+
});
2736
});

0 commit comments

Comments
 (0)