pub struct SourceTextInfo { /* private fields */ }
Expand description

Stores the source text along with other data such as where all the lines occur in the text.

Note: This struct is cheap to clone.

Implementations

Creates a new SourceTextInfo from the provided source text.

Creates a new SourceTextInfo from the provided source start position and source text.

Note: When bundling swc will keep increasing the start position for each source file.

Creates a new SourceTextInfo from the provided start position, source text, and indentation width.

The indentation width determines the number of columns to use when going over a tab character. For example, an indent width of 2 will mean each tab character will represent 2 columns. The default indentation width used in the other methods is 2 to match the default indentation used by deno fmt.

Creates a new SourceTextInfo from the provided source text.

Generally, prefer using SourceTextInfo::new to provide a string already in an std::sync::Arc.

Gets an swc StringInput for this text information that can be used with parsing.

Gets the source text.

Gets a reference to the source text.

Gets the range—start and end byte position—of the source text.

Gets the number of lines in the source text.

Gets the 0-indexed line index at the provided byte position.

Note that this will panic when providing a byte position outside the range of the source text.

Gets the line start byte position of the provided 0-indexed line index.

Note that this will panic if providing a line index outside the bounds of the number of lines.

Gets the line end byte position of the provided 0-indexed line index.

Note that this will panic if providing a line index outside the bounds of the number of lines.

Gets the 0-indexed line and column index of the provided byte position.

Note that this will panic when providing a byte position outside the range of the source text.

Gets the 1-indexed line and column index of the provided byte position taking into account the default indentation width.

Note that this will panic when providing a byte position outside the range of the source text.

Gets the 1-indexed line and column index of the provided byte position with a custom indentation width.

Note that this will panic when providing a byte position outside the range of the source text.

Gets the source position of the provided line and column index.

Note that this will panic if providing a line index outside the bounds of the number of lines, but will clip the the line end byte index when exceeding the line length.

Gets a reference to the text slice of the line at the provided 0-based index.

Note that this will panic if providing a line index outside the bounds of the number of lines.

Gets the source text located within the provided range.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more