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

Method fallback_replace

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

Source from the content-addressed store, hash-verified

154 }
155
156 fn fallback_replace<'text>(
157 &'text self,
158 code: &'text str,
159 magic_string: &mut MagicString<'text>,
160 regex: &regress::Regex,
161 ) -> bool {
162 let mut changed = false;
163 for captures in regex.find_iter(code) {
164 // We expect the regex we used will always have one `Captures`.
165 let Some(Some(matched)) = captures.captures.first() else {
166 break;
167 };
168 if self.prevent_assignment && is_variable_declaration_prefix(&code[0..matched.start]) {
169 continue;
170 }
171 let Some(replacement) = self.values.get(&code[matched.clone()]) else {
172 break;
173 };
174 changed = true;
175 #[expect(clippy::cast_possible_truncation)]
176 magic_string
177 .update(matched.start as u32, matched.end as u32, replacement)
178 .expect("update should not fail in replace plugin");
179 }
180 changed
181 }
182}
183
184impl Plugin for ReplacePlugin {

Callers 1

try_replaceMethod · 0.80

Calls 4

cloneMethod · 0.80
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected