-
I am trying to write a program to replace the value of jsx className attribute. Right now I have the below code pub struct AttributeUpdater<'a> {
pub allocator: &'a Allocator,
pub ast_builder: AstBuilder<'a>,
}
impl<'a> VisitMut<'a> for AttributeUpdater<'a>
{
fn visit_jsx_attribute(&mut self, it: &mut oxc_ast::ast::JSXAttribute<'_>) {
if let JSXAttributeName::Identifier(ident) = &it.name {
if ident.name == "className" {
let value = it.value.as_ref().unwrap();
if let JSXAttributeValue::StringLiteral(string_value) = value {
let uppercased = string_value.value.to_uppercase();
let atom = self.allocator.alloc_str(&uppercased);
// Create new StringLiteral with proper JSX attribute value
let new_value =
self
.ast_builder
.jsx_attribute_value_string_literal(string_value.span, atom, None);
it.value = Some(new_value);
// lifetime may not live long enough
// assignment requires that `'a` must outlive `'1`
}
}
}
}
} However with the above code I am getting a lifetime error when assigning to |
Beta Was this translation helpful? Give feedback.
Answered by
camc314
Jun 26, 2025
Replies: 1 comment 3 replies
-
try
the implicit lifetime on |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
akzhy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try