Skip to content

Commit

Permalink
Fix incorrect line in error messages
Browse files Browse the repository at this point in the history
Resolves #2605
  • Loading branch information
Gerrit0 committed Jun 22, 2024
1 parent c528c0a commit e300453
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

### Features

- Improved Korean translation coverage, #2602
- Improved Korean translation coverage, #2602.

### Bug Fixes

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

### Thanks!

Expand Down
5 changes: 3 additions & 2 deletions src/lib/converter/comments/textParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function textContent(
const data: TextParserData = {
sourcePath,
token,
pos: 0,
pos: 0, // relative to the token
i18n,
warning,
files: files,
Expand All @@ -77,7 +77,8 @@ export function textContent(
),
{
kind: TokenSyntaxKind.Text,
pos: ref.pos,
// ref.pos is relative to the token, but this pos is relative to the file.
pos: token.pos + ref.pos,
text: token.text.slice(ref.pos, ref.end),
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/minimalSourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class MinimalSourceFile implements SourceFileLike {
while (pos >= starts[starts.length - 1]) {
const nextStart = this.text.indexOf(
"\n",
starts[starts.length - 1] + 1,
starts[starts.length - 1],
);

if (nextStart === -1) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/utils/minimalSourceFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ describe("MinimalSourceFile", () => {
check("4", { line: 2, character: 0 });
check("5", { line: 3, character: 0 });
});

it("#2605 Should handle multiple consecutive newlines", () => {
const sf = new MinimalSourceFile("a\n\nb", "");

equal(sf.getLineAndCharacterOfPosition(0), { line: 0, character: 0 }); // a
equal(sf.getLineAndCharacterOfPosition(1), { line: 0, character: 1 }); // \n
equal(sf.getLineAndCharacterOfPosition(2), { line: 1, character: 0 }); // \n
equal(sf.getLineAndCharacterOfPosition(3), { line: 2, character: 0 }); // b
});
});

0 comments on commit e300453

Please sign in to comment.