Skip to content

Commit b14f4a5

Browse files
authored
fix(codeframe): Added Math.max to prevent RangeError (#1807)
fix #1806
1 parent b984d47 commit b14f4a5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/shared/src/codeframe.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export function generateCodeFrame(
1414
for (let j = i - range; j <= i + range || end > count; j++) {
1515
if (j < 0 || j >= lines.length) continue
1616
const line = j + 1
17-
res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`)
17+
res.push(
18+
`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${
19+
lines[j]
20+
}`
21+
)
1822
const lineLength = lines[j].length
1923
if (j === i) {
2024
// push underline

0 commit comments

Comments
 (0)