Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Apr 11, 2024
1 parent f4f472f commit 85c7b20
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/oxc_transformer/src/react/display_name/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ impl<'a> ReactDisplayName<'a> {
/// Add key value `displayName: name` to the `React.createClass` object.
fn add_display_name(&self, obj_expr: &mut ObjectExpression<'a>, name: Atom<'a>) {
const DISPLAY_NAME: &str = "displayName";
// Not safe with existing display name.
let not_safe = obj_expr.properties.iter().any(|prop| {
matches!(prop, ObjectPropertyKind::ObjectProperty(p) if p.key.static_name().is_some_and(|name| name == DISPLAY_NAME))
});
if not_safe {
return;
}
let prop = {
let object_property = {
let kind = PropertyKind::Init;
let identifier_name = IdentifierName::new(SPAN, self.ctx.ast.new_atom(DISPLAY_NAME));
let key = self.ctx.ast.property_key_identifier(identifier_name);
let string_literal = StringLiteral::new(SPAN, name);
let value = self.ctx.ast.literal_string_expression(string_literal);
self.ctx.ast.object_property(SPAN, kind, key, value, None, false, false, false)
};
obj_expr.properties.insert(0, ObjectPropertyKind::ObjectProperty(prop));
obj_expr.properties.insert(0, ObjectPropertyKind::ObjectProperty(object_property));
}
}

0 comments on commit 85c7b20

Please sign in to comment.