Skip to content

Commit d25bfbc

Browse files
authored
Merge branch 'main' into perf-replace-source-struct
2 parents 974d75c + 1c5d9f2 commit d25bfbc

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rspack_sources"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
edition = "2021"
55
authors = ["h-a-n-a <[email protected]>", "ahabhgk <[email protected]>"]
66
resolver = "2"

src/helpers.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
borrow::{BorrowMut, Cow},
33
cell::{OnceCell, RefCell},
4+
fmt::Debug,
45
marker::PhantomData,
56
ops::Range,
67
};
@@ -1243,7 +1244,7 @@ pub fn stream_and_get_source_and_map<'a, S: StreamChunks>(
12431244
}
12441245

12451246
/// Represents a text source that can be manipulated for source mapping purposes.
1246-
pub trait SourceText<'a>: Default + Clone + ToString {
1247+
pub trait SourceText<'a>: Default + Clone + ToString + Debug {
12471248
/// Splits the text into lines, returning an iterator over each line.
12481249
/// Each line includes its line ending character if present.
12491250
fn split_into_lines(&self) -> impl Iterator<Item = Self>;

src/with_indices.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ where
5050
let (last_char_index, last_byte_index) =
5151
self.last_char_index_to_byte_index.get();
5252
let byte_index = last_byte_index as usize;
53-
let mut char_index = last_char_index as usize;
5453

5554
if start_char_index >= last_char_index as usize
5655
|| end_char_index >= last_char_index as usize
5756
{
57+
let mut char_index = last_char_index as usize;
5858
#[allow(unsafe_code)]
5959
let slice = unsafe {
6060
// SAFETY: Since `indices` iterates over the `CharIndices` of `self`, we can guarantee
@@ -77,7 +77,12 @@ where
7777
}
7878
char_index += 1;
7979
}
80-
} else {
80+
}
81+
82+
if start_char_index < last_char_index as usize
83+
|| end_char_index < last_char_index as usize
84+
{
85+
let mut char_index = last_char_index as usize;
8186
#[allow(unsafe_code)]
8287
let slice = unsafe {
8388
// SAFETY: Since `indices` iterates over the `CharIndices` of `self`, we can guarantee
@@ -162,5 +167,11 @@ mod tests {
162167
assert_eq!(rope_with_indices.substring(10, 13), "d 你");
163168
assert_eq!(rope_with_indices.substring(13, 15), "好世");
164169
assert_eq!(rope_with_indices.substring(10, 13), "d 你");
170+
171+
let rope_with_indices =
172+
WithIndices::new(Rope::from("export const answer = 42;\n"));
173+
assert_eq!(rope_with_indices.substring(7, 13), "const ");
174+
assert_eq!(rope_with_indices.substring(13, 19), "answer");
175+
assert_eq!(rope_with_indices.substring(7, 22), "const answer = ");
165176
}
166177
}

0 commit comments

Comments
 (0)