Visitar URL original
[autofix.ci] apply automated fixes · rolldown/rolldown@e4b5a7e · GitHub
Skip to content

Commit e4b5a7e

Browse files
autofix-ci[bot]IWANABETHATGUY
authored andcommitted
[autofix.ci] apply automated fixes
1 parent 1f01fe3 commit e4b5a7e

5 files changed

Lines changed: 33 additions & 38 deletions

File tree

‎chunk-visual‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit eb0e97baad1be63ae31e5019e36492d853884c8d

‎crates/rolldown_binding/src/types/binding_magic_string.rs‎

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl CharToByteMapper {
4242
Self { char_to_byte }
4343
}
4444

45+
#[inline]
4546
fn char_to_byte(&self, char_offset: u32) -> Option<u32> {
4647
self.char_to_byte.get(char_offset as usize).copied()
4748
}
@@ -283,32 +284,28 @@ impl BindingMagicString<'_> {
283284

284285
#[napi]
285286
pub fn prepend_left<'s>(&'s mut self, this: This<'s>, index: u32, content: String) -> This<'s> {
286-
let byte_index =
287-
self.char_to_byte_mapper.char_to_byte(index).expect("Invalid character index");
287+
let byte_index = self.char_to_byte_mapper.char_to_byte(index).expect("Invalid character index");
288288
self.inner.prepend_left(byte_index, content);
289289
this
290290
}
291291

292292
#[napi]
293293
pub fn prepend_right<'s>(&'s mut self, this: This<'s>, index: u32, content: String) -> This<'s> {
294-
let byte_index =
295-
self.char_to_byte_mapper.char_to_byte(index).expect("Invalid character index");
294+
let byte_index = self.char_to_byte_mapper.char_to_byte(index).expect("Invalid character index");
296295
self.inner.prepend_right(byte_index, content);
297296
this
298297
}
299298

300299
#[napi]
301300
pub fn append_left<'s>(&'s mut self, this: This<'s>, index: u32, content: String) -> This<'s> {
302-
let byte_index =
303-
self.char_to_byte_mapper.char_to_byte(index).expect("Invalid character index");
301+
let byte_index = self.char_to_byte_mapper.char_to_byte(index).expect("Invalid character index");
304302
self.inner.append_left(byte_index, content);
305303
this
306304
}
307305

308306
#[napi]
309307
pub fn append_right<'s>(&'s mut self, this: This<'s>, index: u32, content: String) -> This<'s> {
310-
let byte_index =
311-
self.char_to_byte_mapper.char_to_byte(index).expect("Invalid character index");
308+
let byte_index = self.char_to_byte_mapper.char_to_byte(index).expect("Invalid character index");
312309
self.inner.append_right(byte_index, content);
313310
this
314311
}
@@ -323,8 +320,7 @@ impl BindingMagicString<'_> {
323320
) -> napi::Result<This<'s>> {
324321
let start_byte =
325322
self.char_to_byte_mapper.char_to_byte(start).expect("Invalid start character index");
326-
let end_byte =
327-
self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
323+
let end_byte = self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
328324
self
329325
.inner
330326
.update_with(
@@ -349,10 +345,12 @@ impl BindingMagicString<'_> {
349345
}
350346

351347
#[napi]
352-
#[expect(clippy::cast_possible_truncation, reason = "files are < 4GB")]
353348
pub fn length(&self) -> u32 {
354349
// MagicString::len() returns usize (length of generated output)
355-
self.inner.len() as u32
350+
#[expect(clippy::cast_possible_truncation, reason = "files are < 4GB")]
351+
{
352+
self.inner.len() as u32
353+
}
356354
}
357355

358356
#[napi]
@@ -364,8 +362,7 @@ impl BindingMagicString<'_> {
364362
pub fn remove<'s>(&'s mut self, this: This<'s>, start: u32, end: u32) -> napi::Result<This<'s>> {
365363
let start_byte =
366364
self.char_to_byte_mapper.char_to_byte(start).expect("Invalid start character index");
367-
let end_byte =
368-
self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
365+
let end_byte = self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
369366
self.inner.remove(start_byte, end_byte).map_err(napi::Error::from_reason)?;
370367
Ok(this)
371368
}
@@ -380,8 +377,7 @@ impl BindingMagicString<'_> {
380377
) -> napi::Result<This<'s>> {
381378
let start_byte =
382379
self.char_to_byte_mapper.char_to_byte(start).expect("Invalid start character index");
383-
let end_byte =
384-
self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
380+
let end_byte = self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
385381
self.inner.update(start_byte, end_byte, content).map_err(napi::Error::from_reason)?;
386382
Ok(this)
387383
}
@@ -396,10 +392,8 @@ impl BindingMagicString<'_> {
396392
) -> napi::Result<This<'s>> {
397393
let start_byte =
398394
self.char_to_byte_mapper.char_to_byte(start).expect("Invalid start character index");
399-
let end_byte =
400-
self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
401-
let to_byte =
402-
self.char_to_byte_mapper.char_to_byte(to).expect("Invalid to character index");
395+
let end_byte = self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
396+
let to_byte = self.char_to_byte_mapper.char_to_byte(to).expect("Invalid to character index");
403397
self.inner.relocate(start_byte, end_byte, to_byte).map_err(napi::Error::from_reason)?;
404398
Ok(this)
405399
}
@@ -491,8 +485,7 @@ impl BindingMagicString<'_> {
491485
pub fn snip(&self, start: u32, end: u32) -> napi::Result<Self> {
492486
let start_byte =
493487
self.char_to_byte_mapper.char_to_byte(start).expect("Invalid start character index");
494-
let end_byte =
495-
self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
488+
let end_byte = self.char_to_byte_mapper.char_to_byte(end).expect("Invalid end character index");
496489
Ok(Self {
497490
inner: self.inner.snip(start_byte, end_byte).map_err(napi::Error::from_reason)?,
498491
char_to_byte_mapper: self.char_to_byte_mapper.clone(),
@@ -503,22 +496,20 @@ impl BindingMagicString<'_> {
503496
/// This undoes any modifications made to that range.
504497
/// Supports negative indices (counting from the end).
505498
#[napi]
506-
#[expect(
507-
clippy::cast_sign_loss,
508-
clippy::cast_possible_truncation,
509-
reason = "indices are non-negative after normalize_index and files are < 4GB"
510-
)]
511499
pub fn reset<'s>(&'s mut self, this: This<'s>, start: i64, end: i64) -> napi::Result<This<'s>> {
512500
// Handle negative indices (matching original magic-string behavior)
513501
let start = self.char_to_byte_mapper.normalize_index(start);
514502
let end = self.char_to_byte_mapper.normalize_index(end);
515503

516504
// Convert character indices to byte indices
505+
// indices are non-negative after normalize_index and files are < 4GB
506+
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
517507
let start_byte = self
518508
.char_to_byte_mapper
519509
.char_to_byte(start as u32)
520510
.ok_or_else(|| napi::Error::from_reason("Character is out of bounds"))?;
521511

512+
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
522513
let end_byte = self
523514
.char_to_byte_mapper
524515
.char_to_byte(end as u32)
@@ -531,11 +522,6 @@ impl BindingMagicString<'_> {
531522
/// Returns the content between the specified original character positions.
532523
/// Supports negative indices (counting from the end).
533524
#[napi]
534-
#[expect(
535-
clippy::cast_sign_loss,
536-
clippy::cast_possible_truncation,
537-
reason = "indices are non-negative after normalize_index and files are < 4GB"
538-
)]
539525
pub fn slice(&self, start: Option<i64>, end: Option<i64>) -> napi::Result<String> {
540526
let start = start.unwrap_or(0);
541527

@@ -547,8 +533,12 @@ impl BindingMagicString<'_> {
547533
let end = self.char_to_byte_mapper.normalize_index(end);
548534

549535
// Convert character indices to byte indices
536+
// indices are non-negative after normalize_index and files are < 4GB
537+
#[expect(clippy::cast_possible_truncation)]
550538
let source_len = self.inner.source().len() as u32;
539+
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
551540
let start_byte = self.char_to_byte_mapper.char_to_byte(start as u32).unwrap_or(source_len);
541+
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
552542
let end_byte = self.char_to_byte_mapper.char_to_byte(end as u32).unwrap_or(source_len);
553543

554544
self.inner.slice(start_byte, Some(end_byte)).map_err(napi::Error::from_reason)

‎crates/rolldown_plugin_vite_html/src/lib.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Plugin for ViteHtmlPlugin {
149149
}
150150
"vite-ignore" => {
151151
is_ignored = true;
152-
s.remove(attr.span.start, attr.span.end)
152+
s.remove(attr.span.start as u32, attr.span.end as u32)
153153
.expect("remove should not fail in html plugin");
154154
}
155155
_ => {}
@@ -262,7 +262,7 @@ impl Plugin for ViteHtmlPlugin {
262262
) {
263263
let attrs_borrowed = attrs.borrow();
264264
if let Some(attr) = attrs_borrowed.iter().find(|a| &*a.name == "vite-ignore") {
265-
s.remove(attr.span.start, attr.span.end)
265+
s.remove(attr.span.start as u32, attr.span.end as u32)
266266
.expect("remove should not fail in html plugin");
267267
} else {
268268
// Collect all attributes into a map for filtering
@@ -360,7 +360,7 @@ impl Plugin for ViteHtmlPlugin {
360360
}
361361

362362
if should_remove {
363-
s.remove(elem_span.start, elem_span.end)
363+
s.remove(elem_span.start as u32, elem_span.end as u32)
364364
.expect("remove should not fail in html plugin");
365365
}
366366
}

‎crates/string_wizard/src/magic_string/mod.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ impl<'text> MagicString<'text> {
5656

5757
pub fn with_options(source: impl Into<Cow<'text, str>>, options: MagicStringOptions) -> Self {
5858
let source = source.into();
59+
debug_assert!(
60+
source.len() <= u32::MAX as usize,
61+
"MagicString does not support sources larger than 4GB"
62+
);
5963
let source_len = source.len() as u32;
6064
let initial_chunk = Chunk::new(Span(0, source_len));
6165
let mut chunks = IndexChunks::with_capacity(1);
@@ -250,7 +254,7 @@ impl<'text> MagicString<'text> {
250254
/// Chunk{span: (3, 7)} => "defg"
251255
fn split_at(&mut self, at_index: u32) -> Result<(), String> {
252256
if at_index == 0
253-
|| at_index >= self.source.len() as u32
257+
|| (at_index as usize) >= self.source.len()
254258
|| self.chunk_by_end.contains_key(&at_index)
255259
{
256260
return Ok(());
@@ -300,7 +304,7 @@ impl<'text> MagicString<'text> {
300304
}
301305

302306
fn by_start_mut(&mut self, text_index: u32) -> Result<Option<&mut Chunk<'text>>, String> {
303-
if text_index == self.source.len() as u32 {
307+
if text_index as usize == self.source.len() {
304308
Ok(None)
305309
} else {
306310
self.split_at(text_index)?;

‎crates/string_wizard/src/magic_string/reset.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<'text> MagicString<'text> {
1616
return Err("end must be greater than start".to_string());
1717
}
1818

19-
if end > self.source.len() as u32 {
19+
if (end as usize) > self.source.len() {
2020
return Err("Character is out of bounds".to_string());
2121
}
2222

0 commit comments

Comments
 (0)