diff --git a/x-pack/plugins/code/server/utils/composite_source_merger.test.ts b/x-pack/plugins/code/server/utils/composite_source_merger.test.ts index ea774c1de97bc..91adfd6372e0e 100644 --- a/x-pack/plugins/code/server/utils/composite_source_merger.test.ts +++ b/x-pack/plugins/code/server/utils/composite_source_merger.test.ts @@ -39,4 +39,5 @@ test('extract source by ranges', () => { const expectedLineNumbers = ['1', '2', '3', '...', '8', '9', '10', '11']; expect(lineMappings.toStringArray('...')).toEqual(expectedLineNumbers); expect(lineMappings.lineNumber(7)).toBe(5); + expect(lineMappings.lineNumber(0)).toBe(1); }); diff --git a/x-pack/plugins/code/server/utils/composite_source_merger.ts b/x-pack/plugins/code/server/utils/composite_source_merger.ts index 9e7dfbb05550c..982e77a28cd93 100644 --- a/x-pack/plugins/code/server/utils/composite_source_merger.ts +++ b/x-pack/plugins/code/server/utils/composite_source_merger.ts @@ -119,8 +119,12 @@ export class LineMapping { } public lineNumber(originLineNumber: number, startAtLine: number = 1) { - const n = this.reverseMap.get(originLineNumber) || Number.NaN; - return n + startAtLine; + const n = this.reverseMap.get(originLineNumber); + if (n === undefined) { + return Number.NaN; + } else { + return n + startAtLine; + } } public hasLine(line: number) {