Skip to content

Commit 18b525f

Browse files
committed
small cleanup refactor
1 parent 706dafd commit 18b525f

File tree

10 files changed

+30
-27
lines changed

10 files changed

+30
-27
lines changed

compiler/syntax/src/res_parens.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,7 @@ let ternary_operand expr =
301301
Nothing
302302
| {pexp_desc = Pexp_constraint _} -> Parenthesized
303303
| _ when Res_parsetree_viewer.is_fun_newtype expr -> (
304-
let _attrsOnArrow, _parameters, return_expr =
305-
ParsetreeViewer.fun_expr expr
306-
in
304+
let _parameters, return_expr = ParsetreeViewer.fun_expr expr in
307305
match return_expr.pexp_desc with
308306
| Pexp_constraint _ -> Parenthesized
309307
| _ -> Nothing)

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ let has_partial_attribute attrs =
8989
type function_attributes_info = {async: bool; attributes: Parsetree.attributes}
9090

9191
let process_function_attributes attrs =
92-
let rec process async bs acc attrs =
92+
let rec process async acc attrs =
9393
match attrs with
9494
| [] -> {async; attributes = List.rev acc}
95-
| ({Location.txt = "res.async"}, _) :: rest -> process true bs acc rest
96-
| attr :: rest -> process async bs (attr :: acc) rest
95+
| ({Location.txt = "res.async"}, _) :: rest -> process true acc rest
96+
| attr :: rest -> process async (attr :: acc) rest
9797
in
98-
process false false [] attrs
98+
process false [] attrs
9999

100100
let has_await_attribute attrs =
101101
List.exists
@@ -185,7 +185,7 @@ let fun_expr expr =
185185
collect_new_types (string_loc :: acc) return_expr
186186
| return_expr -> (List.rev acc, return_expr)
187187
in
188-
let rec collect ~n_fun attrs_before acc expr =
188+
let rec collect ~n_fun ~params expr =
189189
match expr with
190190
| {
191191
pexp_desc =
@@ -197,11 +197,11 @@ let fun_expr expr =
197197
rhs = {pexp_desc = Pexp_apply _};
198198
};
199199
} ->
200-
(attrs_before, List.rev acc, rewrite_underscore_apply expr)
200+
(List.rev params, rewrite_underscore_apply expr)
201201
| {pexp_desc = Pexp_newtype (string_loc, rest); pexp_attributes = attrs} ->
202202
let string_locs, return_expr = collect_new_types [string_loc] rest in
203203
let param = NewTypes {attrs; locs = string_locs} in
204-
collect ~n_fun attrs_before (param :: acc) return_expr
204+
collect ~n_fun ~params:(param :: params) return_expr
205205
| {
206206
pexp_desc =
207207
Pexp_fun
@@ -218,19 +218,17 @@ let fun_expr expr =
218218
let parameter =
219219
Parameter {attrs = []; lbl; default_expr; pat = pattern}
220220
in
221-
collect ~n_fun:(n_fun + 1) attrs_before (parameter :: acc) return_expr
221+
collect ~n_fun:(n_fun + 1) ~params:(parameter :: params) return_expr
222222
(* If a fun has an attribute, then it stops here and makes currying.
223223
i.e attributes outside of (...), uncurried `(.)` and `async` make currying *)
224-
| {pexp_desc = Pexp_fun _} -> (attrs_before, List.rev acc, expr)
224+
| {pexp_desc = Pexp_fun _} -> (List.rev params, expr)
225225
| expr when n_fun = 0 && Ast_uncurried.expr_is_uncurried_fun expr ->
226226
let expr = Ast_uncurried.expr_extract_uncurried_fun expr in
227-
collect ~n_fun attrs_before acc expr
228-
| expr -> (attrs_before, List.rev acc, expr)
227+
collect ~n_fun ~params expr
228+
| expr -> (List.rev params, expr)
229229
in
230230
match expr with
231-
| {pexp_desc = Pexp_fun _ | Pexp_newtype _} ->
232-
collect ~n_fun:0 expr.pexp_attributes [] {expr with pexp_attributes = []}
233-
| _ -> collect ~n_fun:0 [] [] expr
231+
| _ -> collect ~n_fun:0 ~params:[] {expr with pexp_attributes = []}
234232

235233
let process_braces_attr expr =
236234
match expr.pexp_attributes with

compiler/syntax/src/res_parsetree_viewer.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ type fun_param_kind =
5959
| NewTypes of {attrs: Parsetree.attributes; locs: string Asttypes.loc list}
6060

6161
val fun_expr :
62-
Parsetree.expression ->
63-
Parsetree.attributes * fun_param_kind list * Parsetree.expression
62+
Parsetree.expression -> fun_param_kind list * Parsetree.expression
6463

6564
(* example:
6665
* `makeCoordinate({

compiler/syntax/src/res_printer.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ and print_value_binding ~state ~rec_flag (vb : Parsetree.value_binding) cmt_tbl
19801980
};
19811981
pvb_expr = {pexp_desc = Pexp_newtype _} as expr;
19821982
} -> (
1983-
let _attrs, parameters, return_expr = ParsetreeViewer.fun_expr expr in
1983+
let parameters, return_expr = ParsetreeViewer.fun_expr expr in
19841984
let abstract_type =
19851985
match parameters with
19861986
| [NewTypes {locs = vars}] ->
@@ -2695,7 +2695,8 @@ and print_if_chain ~state pexp_attributes ifs else_expr cmt_tbl =
26952695

26962696
and print_expression ~state (e : Parsetree.expression) cmt_tbl =
26972697
let print_arrow e =
2698-
let attrs_on_arrow, parameters, return_expr = ParsetreeViewer.fun_expr e in
2698+
let parameters, return_expr = ParsetreeViewer.fun_expr e in
2699+
let attrs_on_arrow = e.pexp_attributes in
26992700
let ParsetreeViewer.{async; attributes = attrs} =
27002701
ParsetreeViewer.process_function_attributes attrs_on_arrow
27012702
in
@@ -3438,7 +3439,8 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
34383439
| _ -> expr_with_await
34393440

34403441
and print_pexp_fun ~state ~in_callback e cmt_tbl =
3441-
let attrs_on_arrow, parameters, return_expr = ParsetreeViewer.fun_expr e in
3442+
let parameters, return_expr = ParsetreeViewer.fun_expr e in
3443+
let attrs_on_arrow = e.pexp_attributes in
34423444
let ParsetreeViewer.{async; attributes = attrs} =
34433445
ParsetreeViewer.process_function_attributes attrs_on_arrow
34443446
in

tests/analysis_tests/tests-generic-jsx-transform/package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/analysis_tests/tests-incremental-typechecking/package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/analysis_tests/tests-reanalyze/deadcode/package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/analysis_tests/tests-reanalyze/termination/package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/analysis_tests/tests/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tools_tests/package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)