From: Jacob Smith Date: Wed, 12 Aug 2020 19:52:28 +0000 (-0300) Subject: fix(codeframe): Added Math.max to prevent RangeError (#1807) X-Git-Tag: v3.0.0-rc.6~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b14f4a505b343b12be846f2455d461027a51641c;p=thirdparty%2Fvuejs%2Fcore.git fix(codeframe): Added Math.max to prevent RangeError (#1807) fix #1806 --- diff --git a/packages/shared/src/codeframe.ts b/packages/shared/src/codeframe.ts index 93cfa0718b..f11432cd92 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