Skip to content

Commit 46bf066

Browse files
committed
more dotted removal
1 parent ecc9428 commit 46bf066

File tree

2 files changed

+33
-85
lines changed

2 files changed

+33
-85
lines changed

jscomp/syntax/src/res_core.ml

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,13 @@ type typ_def_or_ext =
200200

201201
type labelled_parameter =
202202
| TermParameter of {
203-
dotted: bool;
204203
attrs: Parsetree.attributes;
205204
label: Asttypes.arg_label;
206205
expr: Parsetree.expression option;
207206
pat: Parsetree.pattern;
208207
pos: Lexing.position;
209208
}
210209
| TypeParameter of {
211-
dotted: bool;
212210
attrs: Parsetree.attributes;
213211
locs: string Location.loc list;
214212
pos: Lexing.position;
@@ -1527,14 +1525,11 @@ and parse_es6_arrow_expression ?(arrow_attrs = []) ?(arrow_start_pos = None)
15271525
(* Propagate any dots from type parameters to the first term *)
15281526
let rec loop ~dot_in_type params =
15291527
match params with
1530-
| (TypeParameter {dotted} as p) :: _ ->
1528+
| (TypeParameter _ as p) :: _ ->
15311529
let rest = LoopProgress.list_rest params in
15321530
(* Tell termination checker about progress *)
1533-
p :: loop ~dot_in_type:(dot_in_type || dotted) rest
1534-
| TermParameter term_param :: rest ->
1535-
TermParameter
1536-
{term_param with dotted = dot_in_type || term_param.dotted}
1537-
:: rest
1531+
p :: loop ~dot_in_type rest
1532+
| (TermParameter _ as p) :: rest -> p :: rest
15381533
| [] -> []
15391534
in
15401535
loop ~dot_in_type:false parameters
@@ -1579,7 +1574,7 @@ and parse_es6_arrow_expression ?(arrow_attrs = []) ?(arrow_start_pos = None)
15791574
Ast_uncurried.uncurried_fun ~loc ~arity fun_expr,
15801575
1 )
15811576
else (term_param_num - 1, fun_expr, arity + 1)
1582-
| TypeParameter {dotted = _; attrs; locs = newtypes; pos = start_pos} ->
1577+
| TypeParameter {attrs; locs = newtypes; pos = start_pos} ->
15831578
( term_param_num,
15841579
make_newtypes ~attrs ~loc:(mk_loc start_pos end_pos) newtypes expr,
15851580
arity ))
@@ -1613,12 +1608,12 @@ and parse_parameter p =
16131608
|| Grammar.is_pattern_start p.token
16141609
then
16151610
let start_pos = p.Parser.start_pos in
1616-
let dotted = Parser.optional p Token.Dot in
1611+
let _ = Parser.optional p Token.Dot (* dot is ignored *) in
16171612
let attrs = parse_attributes p in
16181613
if p.Parser.token = Typ then (
16191614
Parser.next p;
16201615
let lidents = parse_lident_list p in
1621-
Some (TypeParameter {dotted; attrs; locs = lidents; pos = start_pos}))
1616+
Some (TypeParameter {attrs; locs = lidents; pos = start_pos}))
16221617
else
16231618
let attrs, lbl, pat =
16241619
match p.Parser.token with
@@ -1692,23 +1687,15 @@ and parse_parameter p =
16921687
Parser.next p;
16931688
Some
16941689
(TermParameter
1695-
{dotted; attrs; label = lbl; expr = None; pat; pos = start_pos})
1690+
{attrs; label = lbl; expr = None; pat; pos = start_pos})
16961691
| _ ->
16971692
let expr = parse_constrained_or_coerced_expr p in
16981693
Some
16991694
(TermParameter
1700-
{
1701-
dotted;
1702-
attrs;
1703-
label = lbl;
1704-
expr = Some expr;
1705-
pat;
1706-
pos = start_pos;
1707-
}))
1695+
{attrs; label = lbl; expr = Some expr; pat; pos = start_pos}))
17081696
| _ ->
17091697
Some
1710-
(TermParameter
1711-
{dotted; attrs; label = lbl; expr = None; pat; pos = start_pos})
1698+
(TermParameter {attrs; label = lbl; expr = None; pat; pos = start_pos})
17121699
else None
17131700

17141701
and parse_parameter_list p =
@@ -1735,7 +1722,6 @@ and parse_parameters p =
17351722
[
17361723
TermParameter
17371724
{
1738-
dotted = false;
17391725
attrs = [];
17401726
label = Asttypes.Nolabel;
17411727
expr = None;
@@ -1749,7 +1735,6 @@ and parse_parameters p =
17491735
[
17501736
TermParameter
17511737
{
1752-
dotted = false;
17531738
attrs = [];
17541739
label = Asttypes.Nolabel;
17551740
expr = None;
@@ -1771,7 +1756,6 @@ and parse_parameters p =
17711756
[
17721757
TermParameter
17731758
{
1774-
dotted = false;
17751759
attrs = [];
17761760
label = Asttypes.Nolabel;
17771761
expr = None;
@@ -1793,7 +1777,6 @@ and parse_parameters p =
17931777
[
17941778
TermParameter
17951779
{
1796-
dotted = true;
17971780
attrs = [];
17981781
label = Asttypes.Nolabel;
17991782
expr = None;
@@ -1804,9 +1787,9 @@ and parse_parameters p =
18041787
| _ -> (
18051788
match parse_parameter_list p with
18061789
| TermParameter p :: rest ->
1807-
TermParameter {p with dotted = true; pos = start_pos} :: rest
1790+
TermParameter {p with pos = start_pos} :: rest
18081791
| TypeParameter p :: rest ->
1809-
TypeParameter {p with dotted = true; pos = start_pos} :: rest
1792+
TypeParameter {p with pos = start_pos} :: rest
18101793
| parameters -> parameters))
18111794
| _ -> parse_parameter_list p)
18121795
| token ->
@@ -2995,7 +2978,6 @@ and parse_braced_or_record_expr p =
29952978
[
29962979
TermParameter
29972980
{
2998-
dotted = false;
29992981
attrs = [];
30002982
label = Asttypes.Nolabel;
30012983
expr = None;

jscomp/syntax/src/res_printer.ml

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,7 +4152,6 @@ and print_pexp_apply ~state expr cmt_tbl =
41524152
args @ [(Asttypes.Labelled "...", dummy)]
41534153
else args
41544154
in
4155-
let dotted = false in
41564155
let call_expr_doc =
41574156
let doc = print_expression_with_comments ~state call_expr cmt_tbl in
41584157
match Parens.call_expr call_expr with
@@ -4162,16 +4161,14 @@ and print_pexp_apply ~state expr cmt_tbl =
41624161
in
41634162
if ParsetreeViewer.requires_special_callback_printing_first_arg args then
41644163
let args_doc =
4165-
print_arguments_with_callback_in_first_position ~dotted ~state args
4166-
cmt_tbl
4164+
print_arguments_with_callback_in_first_position ~state args cmt_tbl
41674165
in
41684166
Doc.concat
41694167
[print_attributes ~state attrs cmt_tbl; call_expr_doc; args_doc]
41704168
else if ParsetreeViewer.requires_special_callback_printing_last_arg args
41714169
then
41724170
let args_doc =
4173-
print_arguments_with_callback_in_last_position ~state ~dotted args
4174-
cmt_tbl
4171+
print_arguments_with_callback_in_last_position ~state args cmt_tbl
41754172
in
41764173
(*
41774174
* Fixes the following layout (the `[` and `]` should break):
@@ -4198,7 +4195,7 @@ and print_pexp_apply ~state expr cmt_tbl =
41984195
args_doc;
41994196
]
42004197
else
4201-
let args_doc = print_arguments ~state ~dotted ~partial args cmt_tbl in
4198+
let args_doc = print_arguments ~state ~partial args cmt_tbl in
42024199
Doc.concat
42034200
[print_attributes ~state attrs cmt_tbl; call_expr_doc; args_doc]
42044201
| _ -> assert false
@@ -4534,8 +4531,7 @@ and print_jsx_name {txt = lident} =
45344531
let segments = flatten [] lident in
45354532
Doc.join ~sep:Doc.dot segments
45364533

4537-
and print_arguments_with_callback_in_first_position ~dotted ~state args cmt_tbl
4538-
=
4534+
and print_arguments_with_callback_in_first_position ~state args cmt_tbl =
45394535
(* Because the same subtree gets printed twice, we need to copy the cmtTbl.
45404536
* consumed comments need to be marked not-consumed and reprinted…
45414537
* Cheng's different comment algorithm will solve this. *)
@@ -4579,7 +4575,7 @@ and print_arguments_with_callback_in_first_position ~dotted ~state args cmt_tbl
45794575
lazy
45804576
(Doc.concat
45814577
[
4582-
(if dotted then Doc.text "(. " else Doc.lparen);
4578+
Doc.lparen;
45834579
Lazy.force callback;
45844580
Doc.comma;
45854581
Doc.line;
@@ -4595,9 +4591,7 @@ and print_arguments_with_callback_in_first_position ~dotted ~state args cmt_tbl
45954591
* arg3,
45964592
* )
45974593
*)
4598-
let break_all_args =
4599-
lazy (print_arguments ~state ~dotted args cmt_tbl_copy)
4600-
in
4594+
let break_all_args = lazy (print_arguments ~state args cmt_tbl_copy) in
46014595

46024596
(* Sometimes one of the non-callback arguments will break.
46034597
* There might be a single line comment in there, or a multiline string etc.
@@ -4620,7 +4614,7 @@ and print_arguments_with_callback_in_first_position ~dotted ~state args cmt_tbl
46204614
else
46214615
Doc.custom_layout [Lazy.force fits_on_one_line; Lazy.force break_all_args]
46224616

4623-
and print_arguments_with_callback_in_last_position ~state ~dotted args cmt_tbl =
4617+
and print_arguments_with_callback_in_last_position ~state args cmt_tbl =
46244618
(* Because the same subtree gets printed twice, we need to copy the cmtTbl.
46254619
* consumed comments need to be marked not-consumed and reprinted…
46264620
* Cheng's different comment algorithm will solve this. *)
@@ -4669,12 +4663,7 @@ and print_arguments_with_callback_in_last_position ~state ~dotted args cmt_tbl =
46694663
let fits_on_one_line =
46704664
lazy
46714665
(Doc.concat
4672-
[
4673-
(if dotted then Doc.text "(." else Doc.lparen);
4674-
Lazy.force printed_args;
4675-
Lazy.force callback;
4676-
Doc.rparen;
4677-
])
4666+
[Doc.lparen; Lazy.force printed_args; Lazy.force callback; Doc.rparen])
46784667
in
46794668

46804669
(* Thing.map(longArgumet, veryLooooongArgument, (arg1, arg2) =>
@@ -4685,7 +4674,7 @@ and print_arguments_with_callback_in_last_position ~state ~dotted args cmt_tbl =
46854674
lazy
46864675
(Doc.concat
46874676
[
4688-
(if dotted then Doc.text "(." else Doc.lparen);
4677+
Doc.lparen;
46894678
Lazy.force printed_args;
46904679
Doc.breakable_group ~force_break:true (Lazy.force callback2);
46914680
Doc.rparen;
@@ -4699,9 +4688,7 @@ and print_arguments_with_callback_in_last_position ~state ~dotted args cmt_tbl =
46994688
* (param1, parm2) => doStuff(param1, parm2)
47004689
* )
47014690
*)
4702-
let break_all_args =
4703-
lazy (print_arguments ~state ~dotted args cmt_tbl_copy2)
4704-
in
4691+
let break_all_args = lazy (print_arguments ~state args cmt_tbl_copy2) in
47054692

47064693
(* Sometimes one of the non-callback arguments will break.
47074694
* There might be a single line comment in there, or a multiline string etc.
@@ -4729,23 +4716,12 @@ and print_arguments_with_callback_in_last_position ~state ~dotted args cmt_tbl =
47294716
Lazy.force break_all_args;
47304717
]
47314718

4732-
and print_arguments ~state ~dotted ?(partial = false)
4719+
and print_arguments ~state ?(partial = false)
47334720
(args : (Asttypes.arg_label * Parsetree.expression) list) cmt_tbl =
47344721
match args with
4735-
| [
4736-
( Nolabel,
4737-
{
4738-
pexp_desc = Pexp_construct ({txt = Longident.Lident "()"}, _);
4739-
pexp_loc = loc;
4740-
} );
4741-
] -> (
4742-
(* See "parseCallExpr", ghost unit expression is used the implement
4743-
* arity zero vs arity one syntax.
4744-
* Related: https://github.com/rescript-lang/syntax/issues/138 *)
4745-
match (dotted, loc.loc_ghost) with
4746-
| true, true -> Doc.text "(.)" (* arity zero *)
4747-
| true, false -> Doc.text "(. ())" (* arity one *)
4748-
| _ -> Doc.text "()")
4722+
| [(Nolabel, {pexp_desc = Pexp_construct ({txt = Longident.Lident "()"}, _)})]
4723+
->
4724+
Doc.text "()"
47494725
| [(Nolabel, arg)] when ParsetreeViewer.is_huggable_expression arg ->
47504726
let arg_doc =
47514727
let doc = print_expression_with_comments ~state arg cmt_tbl in
@@ -4754,17 +4730,16 @@ and print_arguments ~state ~dotted ?(partial = false)
47544730
| Braced braces -> print_braces doc arg braces
47554731
| Nothing -> doc
47564732
in
4757-
Doc.concat
4758-
[(if dotted then Doc.text "(. " else Doc.lparen); arg_doc; Doc.rparen]
4733+
Doc.concat [Doc.lparen; arg_doc; Doc.rparen]
47594734
| args ->
47604735
Doc.group
47614736
(Doc.concat
47624737
[
4763-
(if dotted then Doc.text "(." else Doc.lparen);
4738+
Doc.lparen;
47644739
Doc.indent
47654740
(Doc.concat
47664741
[
4767-
(if dotted then Doc.line else Doc.soft_line);
4742+
Doc.soft_line;
47684743
Doc.join
47694744
~sep:(Doc.concat [Doc.comma; Doc.line])
47704745
(List.map
@@ -4967,7 +4942,6 @@ and print_case ~state (case : Parsetree.case) cmt_tbl =
49674942

49684943
and print_expr_fun_parameters ~state ~in_callback ~async ~has_constraint
49694944
parameters cmt_tbl =
4970-
let dotted = false in
49714945
match parameters with
49724946
(* let f = _ => () *)
49734947
| [
@@ -4978,8 +4952,7 @@ and print_expr_fun_parameters ~state ~in_callback ~async ~has_constraint
49784952
default_expr = None;
49794953
pat = {Parsetree.ppat_desc = Ppat_any; ppat_loc};
49804954
};
4981-
]
4982-
when not dotted ->
4955+
] ->
49834956
let any =
49844957
let doc = if has_constraint then Doc.text "(_)" else Doc.text "_" in
49854958
print_comments doc cmt_tbl ppat_loc
@@ -4998,8 +4971,7 @@ and print_expr_fun_parameters ~state ~in_callback ~async ~has_constraint
49984971
Parsetree.ppat_attributes = attrs;
49994972
};
50004973
};
5001-
]
5002-
when not dotted ->
4974+
] ->
50034975
let txt_doc =
50044976
let var = print_ident_like string_loc.txt in
50054977
let var =
@@ -5022,8 +4994,7 @@ and print_expr_fun_parameters ~state ~in_callback ~async ~has_constraint
50224994
pat =
50234995
{ppat_desc = Ppat_construct ({txt = Longident.Lident "()"; loc}, None)};
50244996
};
5025-
]
5026-
when not dotted ->
4997+
] ->
50274998
let doc =
50284999
let lparen_rparen = Doc.text "()" in
50295000
if async then add_async lparen_rparen else lparen_rparen
@@ -5037,7 +5008,7 @@ and print_expr_fun_parameters ~state ~in_callback ~async ~has_constraint
50375008
| _ -> false
50385009
in
50395010
let maybe_async_lparen =
5040-
let lparen = if dotted then Doc.text "(. " else Doc.lparen in
5011+
let lparen = Doc.lparen in
50415012
if async then add_async lparen else lparen
50425013
in
50435014
let should_hug = ParsetreeViewer.parameters_should_hug parameters in
@@ -5142,12 +5113,7 @@ and print_exp_fun_parameter ~state parameter cmt_tbl =
51425113
let doc =
51435114
Doc.group
51445115
(Doc.concat
5145-
[
5146-
attrs;
5147-
label_with_pattern;
5148-
default_expr_doc;
5149-
optional_label_suffix;
5150-
])
5116+
[attrs; label_with_pattern; default_expr_doc; optional_label_suffix])
51515117
in
51525118
let cmt_loc =
51535119
match default_expr with

0 commit comments

Comments
 (0)