Skip to content

Commit d825723

Browse files
authored
Change snakecase to camelcase for prop (#7460)
* Change snakecase to camelcase for prop * Format test * Preserve snake case for area labels * Only unwrap uppercase exotic ident in prop name * hyphen
1 parent bece9c7 commit d825723

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

compiler/core/js_dump.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ and print_jsx cxt ?(spread_props : J.expression option)
11541154
in
11551155

11561156
let print_prop n x ctx =
1157-
let prop_name = Js_dump_property.property_key_string n in
1157+
let prop_name = Ext_ident.unwrap_uppercase_exotic n in
11581158
P.string f prop_name;
11591159
P.string f "=";
11601160
print_prop_value x ctx

compiler/core/js_dump_property.ml

+3-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,9 @@ let property_access f s =
8181
| _ -> Js_dump_string.pp_string f s
8282
| exception _ -> Js_dump_string.pp_string f s)
8383

84-
let property_key_string (s : string) : string =
85-
let s = Ext_ident.unwrap_uppercase_exotic s in
86-
if obj_property_no_need_quot s then s else Js_dump_string.escape_to_string s
87-
8884
let property_key (s : J.property_name) : string =
8985
match s with
90-
| Lit s -> property_key_string s
86+
| Lit s ->
87+
let s = Ext_ident.unwrap_uppercase_exotic s in
88+
if obj_property_no_need_quot s then s else Js_dump_string.escape_to_string s
9189
| Symbol_name -> {|[Symbol.for("name")]|}

compiler/core/js_dump_property.mli

-2
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@
2525
val property_access : Ext_pp.t -> string -> unit
2626

2727
val property_key : J.property_name -> string
28-
29-
val property_key_string : string -> string

tests/tests/src/jsx_preserve_test.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ let _optional_props = <Jsx_preserve_test$ComponentWithOptionalProps
203203
element={<div />}
204204
/>;
205205

206+
let _props_with_hyphen = <label
207+
aria-label="close sidebar"
208+
data-testid="test"
209+
/>;
210+
206211
export {
207212
Icon,
208213
_single_element_child,
@@ -228,5 +233,6 @@ export {
228233
_large_component,
229234
ComponentWithOptionalProps,
230235
_optional_props,
236+
_props_with_hyphen,
231237
}
232238
/* _single_element_child Not a pure module */

tests/tests/src/jsx_preserve_test.res

+2
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,5 @@ module ComponentWithOptionalProps = {
126126
}
127127

128128
let _optional_props = <ComponentWithOptionalProps i=1 s="test" element={<div />} />
129+
130+
let _props_with_hyphen = <label ariaLabel={"close sidebar"} dataTestId="test" />

0 commit comments

Comments
 (0)