From b14f4a505b343b12be846f2455d461027a51641c Mon Sep 17 00:00:00 2001 From: Jacob Smith Date: Wed, 12 Aug 2020 16:52:28 -0300 Subject: [PATCH] fix(codeframe): Added Math.max to prevent RangeError (#1807) fix #1806 --- packages/shared/src/codeframe.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/codeframe.ts b/packages/shared/src/codeframe.ts index 93cfa071..f11432cd 100644 --- a/packages/shared/src/codeframe.ts +++ b/packages/shared/src/codeframe.ts @@ -14,7 +14,11 @@ export function generateCodeFrame( for (let j = i - range; j <= i + range || end > count; j++) { if (j < 0 || j >= lines.length) continue const line = j + 1 - res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`) + res.push( + `${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${ + lines[j] + }` + ) const lineLength = lines[j].length if (j === i) { // push underline