Skip to content

Commit 2b1bfa9

Browse files
committed
Change snakecase to camelcase for prop
1 parent bece9c7 commit 2b1bfa9

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

compiler/core/js_dump.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,19 @@ and print_jsx cxt ?(spread_props : J.expression option)
11541154
in
11551155

11561156
let print_prop n x ctx =
1157+
let n =
1158+
(* turn aria-label to ariaLabel *)
1159+
if not (String.contains n '-') then n
1160+
else
1161+
let chars = String.to_seq n |> List.of_seq in
1162+
let rec visit chars acc =
1163+
match chars with
1164+
| [] -> List.rev acc
1165+
| '-' :: l :: rest -> visit rest (Char.uppercase_ascii l :: acc)
1166+
| c :: rest -> visit rest (c :: acc)
1167+
in
1168+
visit chars [] |> List.to_seq |> String.of_seq
1169+
in
11571170
let prop_name = Js_dump_property.property_key_string n in
11581171
P.string f prop_name;
11591172
P.string f "=";

tests/tests/src/jsx_preserve_test.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ let _optional_props = <Jsx_preserve_test$ComponentWithOptionalProps
203203
element={<div />}
204204
/>;
205205

206+
let _props_with_hypen = <label
207+
ariaLabel="close sidebar"
208+
/>;
209+
206210
export {
207211
Icon,
208212
_single_element_child,
@@ -228,5 +232,6 @@ export {
228232
_large_component,
229233
ComponentWithOptionalProps,
230234
_optional_props,
235+
_props_with_hypen,
231236
}
232237
/* _single_element_child Not a pure module */

tests/tests/src/jsx_preserve_test.res

Lines changed: 2 additions & 0 deletions
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_hypen = <label ariaLabel={"close sidebar"} />

0 commit comments

Comments
 (0)