Skip to content

Commit a98e3b8

Browse files
committed
Initial fragment support
1 parent a0c170f commit a98e3b8

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

compiler/core/js_dump.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,25 @@ and expression_desc cxt ~(level : int) f x : cxt =
540540
| _ -> Some (f, x))
541541
in
542542
match jsx_element with
543+
| Parsetree.Jsx_fragment {jsx_fragment_children = children} ->
544+
P.string f "<>";
545+
(let children =
546+
fields
547+
|> List.find_map (fun (n, e) ->
548+
if n = "children" then Some e else None)
549+
in
550+
children
551+
|> Option.iter (fun c ->
552+
P.string f "{";
553+
let _ = expression ~level:1 cxt f c in
554+
P.string f "}"));
555+
P.string f "</>";
556+
cxt
557+
| Parsetree.Jsx_unary_element
558+
{jsx_unary_element_tag_name = {txt = Longident.Lident tagName}} ->
559+
Printf.eprintf "Crazy Tag: %s\n" tagName;
560+
P.string f (Format.sprintf "<%s />" tagName);
561+
cxt
543562
| Parsetree.Jsx_container_element
544563
{
545564
jsx_container_element_tag_name_start =

compiler/core/jsx_help.ml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
let lambda_tag_info_to_string (e : Lambda.tag_info) =
2+
match e with
3+
| Lambda.Blk_constructor _ -> "Blk_constructor"
4+
| Lambda.Blk_record_inlined _ -> "Blk_record_inlined"
5+
| Lambda.Blk_tuple -> "Blk_tuple"
6+
| Lambda.Blk_poly_var _ -> "Blk_poly_var"
7+
| Lambda.Blk_record _ -> "Blk_record"
8+
| Lambda.Blk_module _ -> "Blk_module"
9+
| Lambda.Blk_module_export _ -> "Blk_module_export"
10+
| Lambda.Blk_extension -> "Blk_extension"
11+
| Lambda.Blk_some -> "Blk_some"
12+
| Lambda.Blk_some_not_nested -> "Blk_some_not_nested"
13+
| Lambda.Blk_record_ext _ -> "Blk_record_ext"
14+
| Lambda.Blk_lazy_general -> "Blk_lazy_general"
15+
116
let j_exp_to_string (e : J.expression) =
217
match e.J.expression_desc with
318
| J.Object _ -> "Object"
@@ -21,26 +36,12 @@ let j_exp_to_string (e : J.expression) =
2136
| J.Array_index _ -> "Array_index"
2237
| J.Static_index _ -> "Static_index"
2338
| J.Length _ -> "Length"
24-
| J.Caml_block _ -> "Caml_block"
39+
| J.Caml_block (_, _, _, tag) ->
40+
Format.sprintf "Caml_block (%s)" (lambda_tag_info_to_string tag)
2541
| J.Caml_block_tag _ -> "Caml_block_tag"
2642
| J.Tagged_template _ -> "Tagged_template"
2743
| J.Optional_block _ -> "Optional_block"
2844
| J.Spread _ -> "Spread"
2945
| J.Await _ -> "Await"
3046
| J.Raw_js_code _ -> "Raw_js_code"
3147
| _ -> "Other"
32-
33-
let lambda_tag_info_to_string (e : Lambda.tag_info) =
34-
match e with
35-
| Lambda.Blk_constructor _ -> "Blk_constructor"
36-
| Lambda.Blk_record_inlined _ -> "Blk_record_inlined"
37-
| Lambda.Blk_tuple -> "Blk_tuple"
38-
| Lambda.Blk_poly_var _ -> "Blk_poly_var"
39-
| Lambda.Blk_record _ -> "Blk_record"
40-
| Lambda.Blk_module _ -> "Blk_module"
41-
| Lambda.Blk_module_export _ -> "Blk_module_export"
42-
| Lambda.Blk_extension -> "Blk_extension"
43-
| Lambda.Blk_some -> "Blk_some"
44-
| Lambda.Blk_some_not_nested -> "Blk_some_not_nested"
45-
| Lambda.Blk_record_ext _ -> "Blk_record_ext"
46-
| Lambda.Blk_lazy_general -> "Blk_lazy_general"

compiler/ml/ast_mapper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ module E = struct
293293
fun_ ~loc ~attrs ~arity ~async lab
294294
(map_opt (sub.expr sub) def)
295295
(sub.pat sub p) (sub.expr sub e)
296-
| Pexp_apply {funct = e; args = l; partial} ->
297-
apply ~loc ~attrs ~partial (sub.expr sub e)
296+
| Pexp_apply {funct = e; args = l; partial; transformed_jsx} ->
297+
apply ~loc ~attrs ~partial ?transformed_jsx (sub.expr sub e)
298298
(List.map (map_snd (sub.expr sub)) l)
299299
| Pexp_match (e, pel) ->
300300
match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)

compiler/syntax/src/jsx_v4.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ let append_children_prop (config : Jsx_common.jsx_config) mapper
12081208
Exp.apply
12091209
(Exp.ident
12101210
{txt = Ldot (element_binding, "someElement"); loc = Location.none})
1211-
[(Nolabel, child)]
1211+
[(Nolabel, mapper.expr mapper child)]
12121212
in
12131213
let is_optional =
12141214
match component_description with

0 commit comments

Comments
 (0)