From 63308bc3f985113f70661bae74e938cf7bedec12 Mon Sep 17 00:00:00 2001 From: bohan Date: Mon, 2 Jun 2025 22:29:14 +0800 Subject: [PATCH 1/2] refactor(common): rm Input/find --- crates/swc_common/src/input.rs | 55 +++++++--------------------------- 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/crates/swc_common/src/input.rs b/crates/swc_common/src/input.rs index 45cffd67397b..b1e069cfc286 100644 --- a/crates/swc_common/src/input.rs +++ b/crates/swc_common/src/input.rs @@ -177,34 +177,6 @@ impl<'a> Input<'a> for StringInput<'a> { ret } - fn find(&mut self, mut pred: F) -> Option - where - F: FnMut(char) -> bool, - { - let last = { - let mut last = 0; - for c in self.iter.clone() { - last += c.len_utf8(); - if pred(c) { - break; - } - } - last - }; - - if last == 0 { - return None; - } - - let s = self.iter.as_str(); - debug_assert!(last <= s.len()); - - self.last_pos = self.last_pos + BytePos(last as _); - self.iter = unsafe { s.get_unchecked(last..) }.chars(); - - Some(self.last_pos) - } - #[inline] unsafe fn reset_to(&mut self, to: BytePos) { let orig = self.orig; @@ -284,11 +256,6 @@ pub trait Input<'a>: Clone { where F: FnMut(char) -> bool; - /// This method modifies [last_pos()] and [cur_pos()]. - fn find(&mut self, f: F) -> Option - where - F: FnMut(char) -> bool; - /// # Safety /// /// - `to` be in the valid range of input. @@ -397,17 +364,17 @@ mod tests { }); } - #[test] - fn src_input_find_01() { - with_test_sess("foo/d", |mut i| { - assert_eq!(i.cur_pos(), BytePos(1)); - assert_eq!(i.last_pos, BytePos(1)); - - assert_eq!(i.find(|c| c == '/'), Some(BytePos(5))); - assert_eq!(i.last_pos, BytePos(5)); - assert_eq!(i.cur(), Some('d')); - }); - } + // #[test] + // fn src_input_find_01() { + // with_test_sess("foo/d", |mut i| { + // assert_eq!(i.cur_pos(), BytePos(1)); + // assert_eq!(i.last_pos, BytePos(1)); + + // assert_eq!(i.find(|c| c == '/'), Some(BytePos(5))); + // assert_eq!(i.last_pos, BytePos(5)); + // assert_eq!(i.cur(), Some('d')); + // }); + // } // #[test] // fn src_input_smoke_02() { From 6a93a5e3184aee378ed39de6a1ac86ac21156ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 3 Jun 2025 08:44:45 -0700 Subject: [PATCH 2/2] Create wet-clouds-develop.md --- .changeset/wet-clouds-develop.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wet-clouds-develop.md diff --git a/.changeset/wet-clouds-develop.md b/.changeset/wet-clouds-develop.md new file mode 100644 index 000000000000..64efb5a72a64 --- /dev/null +++ b/.changeset/wet-clouds-develop.md @@ -0,0 +1,5 @@ +--- +swc_common: major +--- + +refactor(common): rm Input/find