Skip to content

Commit 26cee66

Browse files
committed
Correct fragment range, try and print comments
1 parent bd5d4f1 commit 26cee66

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,8 +2697,8 @@ and parse_jsx_fragment start_pos p =
26972697
if p.token = LessThan then p.token <- Scanner.reconsider_less_than p.scanner;
26982698
Parser.expect LessThanSlash p;
26992699
Scanner.pop_mode p.scanner Jsx;
2700+
let end_pos = p.Parser.end_pos in
27002701
Parser.expect GreaterThan p;
2701-
let end_pos = p.Parser.start_pos in
27022702
(* location is from starting < till closing > *)
27032703
let loc = mk_loc start_pos end_pos in
27042704
Ast_helper.Exp.jsx_fragment ~attrs:[] ~loc children_start_pos children

compiler/syntax/src/res_printer.ml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,8 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
27822782
| Pexp_fun _ | Pexp_newtype _ -> print_arrow e
27832783
| Parsetree.Pexp_constant c ->
27842784
print_constant ~template_literal:(ParsetreeViewer.is_template_literal e) c
2785-
| Pexp_jsx_fragment (_, xs, _) -> print_jsx_fragment ~state xs cmt_tbl
2785+
| Pexp_jsx_fragment (o, xs, c) ->
2786+
print_jsx_fragment ~state o xs c e.pexp_loc cmt_tbl
27862787
| Pexp_construct ({txt = Longident.Lident "()"}, _) -> Doc.text "()"
27872788
| Pexp_construct ({txt = Longident.Lident "[]"}, _) ->
27882789
Doc.concat
@@ -4401,9 +4402,20 @@ and print_jsx_expression ~state lident args cmt_tbl =
44014402
]);
44024403
])
44034404

4404-
and print_jsx_fragment ~state (children : Parsetree.expression list) cmt_tbl =
4405-
let opening = Doc.text "<>" in
4406-
let closing = Doc.text "</>" in
4405+
and print_jsx_fragment ~state (opening_greater_than : Lexing.position)
4406+
(children : Parsetree.expression list)
4407+
(closing_lesser_than : Lexing.position) (fragment_loc : Warnings.loc)
4408+
cmt_tbl =
4409+
let opening =
4410+
let loc : Location.t = {fragment_loc with loc_end = opening_greater_than} in
4411+
print_comments (Doc.text "<>") cmt_tbl loc
4412+
in
4413+
let closing =
4414+
let loc : Location.t =
4415+
{fragment_loc with loc_start = closing_lesser_than}
4416+
in
4417+
print_comments (Doc.text "</>") cmt_tbl loc
4418+
in
44074419
let line_sep =
44084420
if
44094421
List.length children > 0
@@ -4423,9 +4435,12 @@ and print_jsx_fragment ~state (children : Parsetree.expression list) cmt_tbl =
44234435
[
44244436
Doc.line;
44254437
Doc.join ~sep:line_sep
4426-
(List.map
4427-
(fun e ->
4428-
print_jsx_child ~spread:false ~state e ~cmt_tbl)
4438+
(List.map
4439+
(fun e ->
4440+
let doc =
4441+
print_jsx_child ~spread:false ~state e ~cmt_tbl
4442+
in
4443+
print_comments doc cmt_tbl e.pexp_loc)
44294444
children);
44304445
]));
44314446
line_sep;

0 commit comments

Comments
 (0)