]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(codeframe): Added Math.max to prevent RangeError (#1807)
authorJacob Smith <jsmith@hey.com>
Wed, 12 Aug 2020 19:52:28 +0000 (16:52 -0300)
committerGitHub <noreply@github.com>
Wed, 12 Aug 2020 19:52:28 +0000 (15:52 -0400)
fix #1806

packages/shared/src/codeframe.ts

index 93cfa0718b1256e54ef52b1134e96622eed0a813..f11432cd92dfdfaed55eb0a31d60ab9a9ffc786c 100644 (file)
@@ -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