Skip to content

Commit 3c376bc

Browse files
committed
Merge branch 'master' into escape-json-control-characters
2 parents 841044e + 362a1da commit 3c376bc

File tree

7 files changed

+37
-19
lines changed

7 files changed

+37
-19
lines changed

compiler/core/js_dump.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,9 @@ and print_jsx cxt ?(spread_props : J.expression option)
11241124
else
11251125
(List.fold_left (fun acc (n, x) ->
11261126
P.space f;
1127-
P.string f n;
1127+
let prop_name = Js_dump_property.property_key_string n in
1128+
1129+
P.string f prop_name;
11281130
P.string f "=";
11291131
P.string f "{";
11301132
let next = expression ~level:0 acc f x in

compiler/core/js_dump_property.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ 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+
8488
let property_key (s : J.property_name) : string =
8589
match s with
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
90+
| Lit s -> property_key_string s
8991
| Symbol_name -> {|[Symbol.for("name")]|}

compiler/core/js_dump_property.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@
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

compiler/frontend/bs_syntaxerr.ml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ type error =
3333
| Expect_string_literal
3434
| Expect_int_or_string_or_json_literal
3535
| Unhandled_poly_type
36-
| Unregistered of string
3736
| Invalid_underscore_type_in_external
3837
| Invalid_bs_string_type
3938
| Invalid_bs_int_type
4039
| Invalid_bs_unwrap_type
4140
| Conflict_ffi_attribute of string
42-
| Not_supported_in_bs_deriving
43-
| Canot_infer_arity_by_syntax
4441
| Illegal_attribute
45-
| Inconsistent_arity of int * int
4642
(* we still rqeuire users to have explicit annotation to avoid
4743
{[ (((int -> int) -> int) -> int )]}
4844
*)
@@ -66,12 +62,6 @@ let pp_error fmt err =
6662
syntax wise `_ option` for safety"
6763
| Not_supported_directive_in_bs_return -> "Not supported return directive"
6864
| Illegal_attribute -> "Illegal attributes"
69-
| Canot_infer_arity_by_syntax ->
70-
"Cannot infer the arity through the syntax, either [%@uncurry n] or \n\
71-
write it in arrow syntax "
72-
| Inconsistent_arity (arity, n) ->
73-
Printf.sprintf "Inconsistent arity %d vs %d" arity n
74-
| Not_supported_in_bs_deriving -> "not supported in deriving"
7565
| Unsupported_predicates -> "unsupported predicates"
7666
| Conflict_bs_bs_this_bs_meth ->
7767
"%@this, %@bs, %@meth can not be applied at the same time"
@@ -82,7 +72,6 @@ let pp_error fmt err =
8272
| Expect_int_or_string_or_json_literal ->
8373
"expect int, string literal or json literal {json|text here|json} "
8474
| Unhandled_poly_type -> "Unhandled poly type"
85-
| Unregistered str -> "Unregistered " ^ str
8675
| Invalid_underscore_type_in_external ->
8776
"_ is not allowed in combination with external optional type"
8877
| Invalid_bs_string_type -> "Not a valid type for %@string"

compiler/frontend/bs_syntaxerr.mli

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ type error =
3333
| Expect_string_literal
3434
| Expect_int_or_string_or_json_literal
3535
| Unhandled_poly_type
36-
| Unregistered of string
3736
| Invalid_underscore_type_in_external
3837
| Invalid_bs_string_type
3938
| Invalid_bs_int_type
4039
| Invalid_bs_unwrap_type
4140
| Conflict_ffi_attribute of string
42-
| Not_supported_in_bs_deriving
43-
| Canot_infer_arity_by_syntax
4441
| Illegal_attribute
45-
| Inconsistent_arity of int * int
4642
(* we still rqeuire users to have explicit annotation to avoid
4743
{[ (((int -> int) -> int) -> int )]}
4844
*)

tests/tests/src/preserve_jsx_test.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ let _external_component_with_children = <QueryClientProvider>
111111
<Preserve_jsx_test$B/>
112112
</QueryClientProvider>;
113113

114+
function make(props) {
115+
return <p>
116+
{"foo"}
117+
{props["\\\"MyWeirdProp\""]}
118+
</p>;
119+
}
120+
121+
let MyWeirdComponent = {
122+
make: make
123+
};
124+
125+
let _escaped_jsx_prop = <make MyWeirdProp={"bar"}/>;
126+
114127
export {
115128
React,
116129
ReactDOM,
@@ -133,5 +146,7 @@ export {
133146
A,
134147
B,
135148
_external_component_with_children,
149+
MyWeirdComponent,
150+
_escaped_jsx_prop,
136151
}
137152
/* _single_element_child Not a pure module */

tests/tests/src/preserve_jsx_test.res

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,15 @@ let _external_component_with_children =
155155
<strong />
156156
<B />
157157
</A>
158+
159+
module MyWeirdComponent = {
160+
type props = {\"MyWeirdProp": string}
161+
162+
let make = props =>
163+
<p>
164+
{React.string("foo")}
165+
{React.string(props.\"MyWeirdProp")}
166+
</p>
167+
}
168+
169+
let _escaped_jsx_prop = <MyWeirdComponent \"MyWeirdProp"="bar" />

0 commit comments

Comments
 (0)