Skip to content

Commit

Permalink
Don't hide error when diagnostic is malformed (#9283)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Oct 1, 2023
1 parent 830d755 commit 889ab9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/codeframe/src/codeframe.js
Expand Up @@ -260,6 +260,9 @@ export default function codeFrame(
characters += startCol - lastCol;
}

// Don't crash (and swallow the original message) if the diagnostic is malformed (end is before start).
characters = Math.max(1, characters);

// Append the highlight indicators
highlightLine += highlighter('^'.repeat(characters));

Expand Down
23 changes: 23 additions & 0 deletions packages/core/codeframe/test/codeframe.test.js
Expand Up @@ -796,4 +796,27 @@ describe('codeframe', () => {
assert.equal(lines[3], ' 9 | ');
assert.equal(lines[4], ' 10 | /**');
});

it('should still generate a codeframe when end is before start', () => {
let codeframeString = codeframe(
'hello world',
[
{
start: {
column: 5,
line: 1,
},
end: {
column: 1,
line: 1,
},
},
],
{useColor: false},
);

let lines = codeframeString.split(LINE_END);
assert.equal(lines[0], '> 1 | hello world');
assert.equal(lines[1], '> | ^');
});
});

0 comments on commit 889ab9d

Please sign in to comment.