Skip to content

Commit 02047cf

Browse files
committed
Fix conv_attr_name
1 parent cc14a4a commit 02047cf

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/reactpy/_console/rewrite_props.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,20 @@ def find_nodes_to_change(tree: ast.AST) -> list[ChangedNode]:
5454

5555
def conv_attr_name(name: str) -> str:
5656
"""Convert snake_case attribute name to camelCase"""
57+
# Return early if the value is a Python keyword
5758
if name in kwlist:
58-
return name # Return the name as is if it's a Python keyword
59-
# Convert snake_case to CamelCase
60-
result = name.replace("_", " ").title().replace(" ", "")
61-
# Ensure the first letter is lowercase
62-
result = name[0].lower() + name[1:]
63-
return result
59+
return name
60+
61+
# Return early if the value is not snake_case
62+
if "_" not in name:
63+
return name
64+
65+
# Split the string by underscores
66+
components = name.split("_")
67+
68+
# Capitalize the first letter of each component except the first one
69+
# and join them together
70+
return components[0] + "".join(x.title() for x in components[1:])
6471

6572

6673
def _construct_prop_item(key: str, value: ast.expr) -> tuple[str, ast.expr]:

0 commit comments

Comments
 (0)