Skip to content

Commit

Permalink
fix: structure item extensions in nested modules
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Sep 19, 2023
1 parent 81097f5 commit bfaf6f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
32 changes: 10 additions & 22 deletions src/reason-parser/reason_pprint_ast.ml
Expand Up @@ -5570,11 +5570,11 @@ let printer = object(self:'self)
* brace {} in the let sequence. *)
let layout = source_map ~loc:letModuleLoc letModuleLayout in
let (_, return) = self#curriedFunctorPatternsAndReturnStruct moduleExpr in
let loc = {
letModuleLoc with
loc_end = return.pmod_loc.loc_end
} in
processLetList ((loc, layout)::acc) e
let loc = {
letModuleLoc with
loc_end = return.pmod_loc.loc_end
} in
processLetList ((loc, layout)::acc) e
| ([], Pexp_letexception (extensionConstructor, expr)) ->
let exc = self#exception_declaration extensionConstructor in
let layout = source_map ~loc:extensionConstructor.pext_loc exc in
Expand Down Expand Up @@ -7548,20 +7548,7 @@ let printer = object(self:'self)
else
("({", "})")
else ("{", "}") in
let items =
groupAndPrint
~xf:self#structure_item
~getLoc:(fun x -> x.pstr_loc)
~comments:self#comments
s
in
makeList
~break:Layout.Always_rec
~inline:(true, false)
~wrap
~postSpace:true
~sep:(SepFinal (";", ";"))
items
self#structure ~indent:None ~wrap s
| _ ->
(* For example, functor application will be wrapped. *)
formatPrecedence ~wrap:("", "") (self#module_expr x)
Expand All @@ -7582,7 +7569,7 @@ let printer = object(self:'self)
| Pmod_constraint _
| Pmod_structure _ -> self#simple_module_expr x
method structure structureItems =
method structure ?(indent=Some 0) ?wrap structureItems =
(* We don't have any way to know if an extension is placed at the top level by the parsetree
while there's a difference syntactically (% for structure_items/expressons and %% for top_level).
This small fn detects this particular case (structure > structure_item > extension > value) and
Expand All @@ -7598,7 +7585,7 @@ let printer = object(self:'self)
| _ -> self#structure_item item
in
match structureItems with
| [] -> atom ""
| [] -> makeList ?wrap []
| first :: _ as structureItems ->
let last = match (List.rev structureItems) with | last::_ -> last | [] -> assert false in
let loc_start = first.pstr_loc.loc_start in
Expand All @@ -7614,7 +7601,8 @@ let printer = object(self:'self)
(makeList
~postSpace:true
~break:Always_rec
~indent:0
?wrap
?indent
~inline:(true, false)
~sep:(SepFinal (";", ";"))
items)
Expand Down
2 changes: 1 addition & 1 deletion test/extension-str-in-module.t
Expand Up @@ -12,6 +12,6 @@ Format extensions in modules
module X = {
/* No payload */
[%%someExtension];
[%someExtension "payload"];
[%%someExtension "payload"];
};

0 comments on commit bfaf6f2

Please sign in to comment.