feat(compiler): accept line offset in codeframe
This commit is contained in:
parent
d6acb9c073
commit
49a50d3c9c
@ -36,6 +36,7 @@ import { generateCodeFrame as _genCodeFrame } from '@vue/shared'
|
|||||||
const generateCodeFrame = _genCodeFrame as (
|
const generateCodeFrame = _genCodeFrame as (
|
||||||
source: string,
|
source: string,
|
||||||
start?: number,
|
start?: number,
|
||||||
end?: number
|
end?: number,
|
||||||
|
lineOffset?: number
|
||||||
) => string
|
) => string
|
||||||
export { generateCodeFrame }
|
export { generateCodeFrame }
|
||||||
|
@ -2,8 +2,9 @@ const range: number = 2
|
|||||||
|
|
||||||
export function generateCodeFrame(
|
export function generateCodeFrame(
|
||||||
source: string,
|
source: string,
|
||||||
start: number = 0,
|
start = 0,
|
||||||
end: number = source.length
|
end = source.length,
|
||||||
|
lineOffset = 0
|
||||||
): string {
|
): string {
|
||||||
const lines = source.split(/\r?\n/)
|
const lines = source.split(/\r?\n/)
|
||||||
let count = 0
|
let count = 0
|
||||||
@ -13,9 +14,8 @@ export function generateCodeFrame(
|
|||||||
if (count >= start) {
|
if (count >= start) {
|
||||||
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
|
||||||
res.push(
|
const line = j + 1 + lineOffset
|
||||||
`${j + 1}${' '.repeat(3 - String(j + 1).length)}| ${lines[j]}`
|
res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`)
|
||||||
)
|
|
||||||
const lineLength = lines[j].length
|
const lineLength = lines[j].length
|
||||||
if (j === i) {
|
if (j === i) {
|
||||||
// push underline
|
// push underline
|
||||||
|
Loading…
x
Reference in New Issue
Block a user