pub struct LineOffsetTable { /* private fields */ }Expand description
Pre-computed line-start table for converting V8 source offsets into Istanbul line/column positions in O(log n) per lookup.
V8 reports offsets in JavaScript source positions: UTF-16 code units, not UTF-8 bytes. Istanbul columns use the same 0-indexed source-position model, so this table stores line starts in UTF-16 units.
The source is consumed once at construction; subsequent lookups are allocation-free.
Implementations§
Source§impl LineOffsetTable
impl LineOffsetTable
Sourcepub fn from_source(source: &str) -> Self
pub fn from_source(source: &str) -> Self
Build a table from the full source text. The source must be UTF-8 with LF, CRLF, or CR line endings (mixed endings are tolerated).
Sourcepub fn from_v8_line_lengths(line_lengths: &[u32]) -> Option<Self>
pub fn from_v8_line_lengths(line_lengths: &[u32]) -> Option<Self>
Build a table from V8’s source-map-cache.lineLengths data.
lineLengths are already measured in JavaScript source positions. The
cache does not carry line-ending widths, so this preserves the existing
Node fallback behavior and advances one source position between lines.
Sourcepub fn position(&self, source_offset: u32) -> IstanbulPosition
pub fn position(&self, source_offset: u32) -> IstanbulPosition
Convert a V8 source offset to a 1-indexed line + 0-indexed column.
Offsets at or past the end of the source clamp to the last line + remaining column.