Skip to content

generateCodeFrame fails for files >= 1000 lines #1806

@jsmith

Description

@jsmith

Version

3.0.0-rc.5

Reproduction link

https://codesandbox.io/s/wonderful-shirley-8g3zu?file=/src/index.js

Steps to reproduce

Once you open this codesandbox, the error will show up right away! This is happening because the source file is 1000 lines long and the line # formatter only works for files < 1000 lines.

What is expected?

This prints a codeframe.

What is actually happening?

It fails due to a bad range (RangeError Invalid count value).


I ran into this bug when my vite build was trying to print out some kind of warning but my compiled js was > 10,000 lines long.The easiest solution would be to just add a Math.max here to catch this edge case. To be more specific, change:

res.push(`${line}${' '.repeat(3 - String(line).length)}|  ${lines[j]}`)

to:

res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}|  ${lines[j]}`)

Thanks for your help :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions