fix(codeframe): Added Math.max to prevent RangeError (#1807)

fix #1806
This commit is contained in:
Jacob Smith 2020-08-12 16:52:28 -03:00 committed by GitHub
parent b984d47ac4
commit b14f4a505b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,11 @@ export function generateCodeFrame(
for (let j = i - range; j <= i + range || end > count; j++) { for (let j = i - range; j <= i + range || end > count; j++) {
if (j < 0 || j >= lines.length) continue if (j < 0 || j >= lines.length) continue
const line = j + 1 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 const lineLength = lines[j].length
if (j === i) { if (j === i) {
// push underline // push underline