MCPcopy Create free account
hub / github.com/rolldown/rolldown / optimized_replace

Method optimized_replace

crates/rolldown_plugin_replace/src/plugin.rs:107–132  ·  view source on GitHub ↗
(
    &'text self,
    code: &'text str,
    magic_string: &mut MagicString<'text>,
    regex: &regex::Regex,
  )

Source from the content-addressed store, hash-verified

105 }
106
107 fn optimized_replace<'text>(
108 &'text self,
109 code: &'text str,
110 magic_string: &mut MagicString<'text>,
111 regex: &regex::Regex,
112 ) -> bool {
113 let mut changed = false;
114 for captures in regex.captures_iter(code) {
115 let Some(matched) = captures.get(1) else {
116 break;
117 };
118 if self.look_around_assert(code, matched.range()) {
119 continue;
120 }
121 let Some(replacement) = self.values.get(matched.as_str()) else {
122 break;
123 };
124 changed = true;
125 #[expect(clippy::cast_possible_truncation)]
126 magic_string
127 .update(matched.start() as u32, matched.end() as u32, replacement)
128 .expect("update should not fail in replace plugin");
129 }
130
131 changed
132 }
133
134 fn look_around_assert(&self, code: &str, matched_range: Range<usize>) -> bool {
135 if self.prevent_assignment {

Callers 1

try_replaceMethod · 0.80

Calls 6

look_around_assertMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
updateMethod · 0.45
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected