Преглед изворни кода

fix: handle empty lines in codeframe

Evan You пре 6 година
родитељ
комит
4b2610c468
1 измењених фајлова са 4 додато и 1 уклоњено
  1. 4 1
      packages/shared/src/codeframe.ts

+ 4 - 1
packages/shared/src/codeframe.ts

@@ -20,7 +20,10 @@ export function generateCodeFrame(
         if (j === i) {
           // push underline
           const pad = start - (count - lineLength) + 1
-          const length = end > count ? lineLength - pad : end - start
+          const length = Math.max(
+            0,
+            end > count ? lineLength - pad : end - start
+          )
           res.push(`   |  ` + ' '.repeat(pad) + '^'.repeat(length))
         } else if (j > i) {
           if (end > count) {