]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix: codeframe marker should have min width of 1
authorEvan You <yyx990803@gmail.com>
Thu, 19 Dec 2019 20:42:53 +0000 (15:42 -0500)
committerEvan You <yyx990803@gmail.com>
Thu, 19 Dec 2019 20:42:53 +0000 (15:42 -0500)
packages/compiler-core/src/index.ts
packages/shared/src/codeframe.ts

index b1304a498c5bcd093d80476a2c1325106dad7492..723fe8c3b21d01c4c9ef23cbd1fa9d556061b654 100644 (file)
@@ -36,7 +36,6 @@ import { generateCodeFrame as _genCodeFrame } from '@vue/shared'
 const generateCodeFrame = _genCodeFrame as (
   source: string,
   start?: number,
-  end?: number,
-  lineOffset?: number
+  end?: number
 ) => string
 export { generateCodeFrame }
index 22b283a23e6c42a31c46caddaeba5aca3db01fac..93cfa0718b1256e54ef52b1134e96622eed0a813 100644 (file)
@@ -3,8 +3,7 @@ const range: number = 2
 export function generateCodeFrame(
   source: string,
   start = 0,
-  end = source.length,
-  lineOffset = 0
+  end = source.length
 ): string {
   const lines = source.split(/\r?\n/)
   let count = 0
@@ -14,20 +13,20 @@ export function generateCodeFrame(
     if (count >= start) {
       for (let j = i - range; j <= i + range || end > count; j++) {
         if (j < 0 || j >= lines.length) continue
-        const line = j + 1 + lineOffset
+        const line = j + 1
         res.push(`${line}${' '.repeat(3 - String(line).length)}|  ${lines[j]}`)
         const lineLength = lines[j].length
         if (j === i) {
           // push underline
           const pad = start - (count - lineLength) + 1
           const length = Math.max(
-            0,
+            1,
             end > count ? lineLength - pad : end - start
           )
           res.push(`   |  ` + ' '.repeat(pad) + '^'.repeat(length))
         } else if (j > i) {
           if (end > count) {
-            const length = Math.min(end - count, lineLength)
+            const length = Math.max(Math.min(end - count, lineLength), 1)
             res.push(`   |  ` + '^'.repeat(length))
           }
           count += lineLength + 1