Skip to content

Commit 019c31d

Browse files
committed
Correct location in mapping
1 parent 3b0018d commit 019c31d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

compiler/ml/ast_mapper_to0.ml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,6 @@ module E = struct
288288
let loc = sub.location sub loc in
289289
let attrs = sub.attributes sub attrs in
290290
match desc with
291-
| Pexp_jsx_fragment (_, xs, _) ->
292-
(* TODO: tweak location slightly *)
293-
let list_expr = Ast_helper.Exp.make_list_expression loc xs None in
294-
let mapped = sub.expr sub list_expr in
295-
let jsx_attr =
296-
sub.attribute sub (Location.mknoloc "JSX", Parsetree.PStr [])
297-
in
298-
{mapped with pexp_attributes = jsx_attr :: attrs}
299-
(* failwith "TODO Pexp_jsx_fragment 4" *)
300291
| Pexp_ident x -> ident ~loc ~attrs (map_loc sub x)
301292
| Pexp_constant x -> constant ~loc ~attrs (map_constant x)
302293
| Pexp_let (r, vbs, e) ->
@@ -416,6 +407,18 @@ module E = struct
416407
| Pexp_open (ovf, lid, e) ->
417408
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.expr sub e)
418409
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
410+
| Pexp_jsx_fragment (o, xs, c) ->
411+
(*
412+
The location of Pexp_jsx_fragment is from the start of < till the end of />.
413+
This is not the case in the old AST. There it is from >...</
414+
*)
415+
let loc = {loc with loc_start = o; loc_end = c} in
416+
let list_expr = Ast_helper.Exp.make_list_expression loc xs None in
417+
let mapped = sub.expr sub list_expr in
418+
let jsx_attr =
419+
sub.attribute sub (Location.mknoloc "JSX", Parsetree.PStr [])
420+
in
421+
{mapped with pexp_attributes = jsx_attr :: attrs}
419422
end
420423

421424
module P = struct

0 commit comments

Comments
 (0)