ReadonlyfilenameReadonlylineUTF-16 offsets of each line's first character. Always starts with 0,
and contains one entry per line. lineStarts.length equals the number
of lines. For a file ending in a newline, the final entry points just
past the end of text.
ReadonlytextNumber of lines in the file. Always at least 1.
0-based offset of the first character of line (1-based).
Returns the text of the given 1-based line, excluding the trailing line terminator. Works for the last line even if the file has no final newline.
Convert a UTF-16 offset to a full Position. Throws RangeError if the offset is outside [0, text.length]. An offset equal to text.length is valid and represents end-of-file.
Wraps a source string with a precomputed line-offset index so that
positionOf(offset)runs in O(log lines) amortized. Constructing a SourceFile is one linear pass over the text.Recognised line terminators: LF (
\n), CRLF (\r\n), and bare CR (\r). HCL2's spec only names LF and CRLF, but bare CR is accepted for robustness against files that crossed a Classic-Mac-era checkout.