Skip to content

Commit e236e21

Browse files
committed
Store the label loc directly in the label, for application for now.
1 parent be89110 commit e236e21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+595
-697
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
268268
(* Transform away pipe with apply call *)
269269
exprToContextPath
270270
{
271-
pexp_desc =
272-
Pexp_apply {funct = d; args = (Nolabel, lhs) :: args; partial};
271+
pexp_desc = Pexp_apply {funct = d; args = (Nolbl, lhs) :: args; partial};
273272
pexp_loc;
274273
pexp_attributes;
275274
}
@@ -289,7 +288,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
289288
Pexp_apply
290289
{
291290
funct = {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes};
292-
args = [(Nolabel, lhs)];
291+
args = [(Nolbl, lhs)];
293292
partial;
294293
};
295294
pexp_loc;
@@ -298,7 +297,11 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
298297
| Pexp_apply {funct = e1; args} -> (
299298
match exprToContextPath e1 with
300299
| None -> None
301-
| Some contexPath -> Some (CPApply (contexPath, args |> List.map fst)))
300+
| Some contexPath ->
301+
Some
302+
(CPApply
303+
(contexPath, args |> List.map fst |> List.map Asttypes.to_arg_label))
304+
)
302305
| Pexp_tuple exprs ->
303306
let exprsAsContextPaths = exprs |> List.filter_map exprToContextPath in
304307
if List.length exprs = List.length exprsAsContextPaths then

analysis/src/CompletionJsx.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,20 +465,18 @@ let extractJsxProps ~(compName : Longident.t Location.loc) ~args =
465465
in
466466
let rec processProps ~acc args =
467467
match args with
468-
| (Asttypes.Labelled "children", {Parsetree.pexp_loc}) :: _ ->
468+
| (Asttypes.Lbl {txt = "children"}, {Parsetree.pexp_loc}) :: _ ->
469469
{
470470
compName;
471471
props = List.rev acc;
472472
childrenStart =
473473
(if pexp_loc.loc_ghost then None else Some (Loc.start pexp_loc));
474474
}
475-
| ((Labelled s | Optional s), (eProp : Parsetree.expression)) :: rest -> (
476-
let namedArgLoc =
477-
eProp.pexp_attributes
478-
|> List.find_opt (fun ({Asttypes.txt}, _) -> txt = "res.namedArgLoc")
479-
in
475+
| ((Lbl {txt = s; loc} | Opt {txt = s; loc}), (eProp : Parsetree.expression))
476+
:: rest -> (
477+
let namedArgLoc = if loc = Location.none then None else Some loc in
480478
match namedArgLoc with
481-
| Some ({loc}, _) ->
479+
| Some loc ->
482480
processProps
483481
~acc:
484482
({

analysis/src/SemanticTokens.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ let command ~debug ~emitter ~path =
266266

267267
let posOfGreatherthanAfterProps =
268268
let rec loop = function
269-
| (Asttypes.Labelled "children", {Parsetree.pexp_loc}) :: _ ->
269+
| (Asttypes.Lbl {txt = "children"}, {Parsetree.pexp_loc}) :: _ ->
270270
Loc.start pexp_loc
271271
| _ :: args -> loop args
272272
| [] -> (* should not happen *) (-1, -1)

analysis/src/SharedTypes.ml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -898,28 +898,26 @@ type arg = {label: label; exp: Parsetree.expression}
898898
let extractExpApplyArgs ~args =
899899
let rec processArgs ~acc args =
900900
match args with
901-
| (((Asttypes.Labelled s | Optional s) as label), (e : Parsetree.expression))
901+
| ( ((Asttypes.Lbl {txt = s; loc} | Opt {txt = s; loc}) as label),
902+
(e : Parsetree.expression) )
902903
:: rest -> (
903-
let namedArgLoc =
904-
e.pexp_attributes
905-
|> List.find_opt (fun ({Asttypes.txt}, _) -> txt = "res.namedArgLoc")
906-
in
904+
let namedArgLoc = if loc = Location.none then None else Some loc in
907905
match namedArgLoc with
908-
| Some ({loc}, _) ->
906+
| Some loc ->
909907
let labelled =
910908
{
911909
name = s;
912910
opt =
913911
(match label with
914-
| Optional _ -> true
912+
| Opt _ -> true
915913
| _ -> false);
916914
posStart = Loc.start loc;
917915
posEnd = Loc.end_ loc;
918916
}
919917
in
920918
processArgs ~acc:({label = Some labelled; exp = e} :: acc) rest
921919
| None -> processArgs ~acc rest)
922-
| (Asttypes.Nolabel, (e : Parsetree.expression)) :: rest ->
920+
| (Nolbl, (e : Parsetree.expression)) :: rest ->
923921
if e.pexp_loc.loc_ghost then processArgs ~acc rest
924922
else processArgs ~acc:({label = None; exp = e} :: acc) rest
925923
| [] -> List.rev acc

analysis/src/TypeUtils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ module Codegen = struct
941941
let mkFailWithExp () =
942942
Ast_helper.Exp.apply
943943
(Ast_helper.Exp.ident {txt = Lident "failwith"; loc = Location.none})
944-
[(Nolabel, Ast_helper.Exp.constant (Pconst_string ("TODO", None)))]
944+
[(Nolbl, Ast_helper.Exp.constant (Pconst_string ("TODO", None)))]
945945

946946
let mkConstructPat ?payload name =
947947
Ast_helper.Pat.construct

analysis/src/Xform.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module IfThenElse = struct
9595
Pexp_ident
9696
{txt = Longident.Lident (("==" | "!=") as op)};
9797
};
98-
args = [(Nolabel, arg1); (Nolabel, arg2)];
98+
args = [(Nolbl, arg1); (Nolbl, arg2)];
9999
};
100100
},
101101
e1,

compiler/frontend/ast_compatible.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let apply_simple ?(loc = default_loc) ?(attrs = []) (fn : expression)
4242
Pexp_apply
4343
{
4444
funct = fn;
45-
args = Ext_list.map args (fun x -> (Asttypes.Nolabel, x));
45+
args = Ext_list.map args (fun x -> (Asttypes.Nolbl, x));
4646
partial = false;
4747
};
4848
}
@@ -51,8 +51,7 @@ let app1 ?(loc = default_loc) ?(attrs = []) fn arg1 : expression =
5151
{
5252
pexp_loc = loc;
5353
pexp_attributes = attrs;
54-
pexp_desc =
55-
Pexp_apply {funct = fn; args = [(Nolabel, arg1)]; partial = false};
54+
pexp_desc = Pexp_apply {funct = fn; args = [(Nolbl, arg1)]; partial = false};
5655
}
5756

5857
let app2 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 : expression =
@@ -61,7 +60,7 @@ let app2 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 : expression =
6160
pexp_attributes = attrs;
6261
pexp_desc =
6362
Pexp_apply
64-
{funct = fn; args = [(Nolabel, arg1); (Nolabel, arg2)]; partial = false};
63+
{funct = fn; args = [(Nolbl, arg1); (Nolbl, arg2)]; partial = false};
6564
}
6665

6766
let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
@@ -72,7 +71,7 @@ let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
7271
Pexp_apply
7372
{
7473
funct = fn;
75-
args = [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)];
74+
args = [(Nolbl, arg1); (Nolbl, arg2); (Nolbl, arg3)];
7675
partial = false;
7776
};
7877
}
@@ -118,7 +117,9 @@ let apply_labels ?(loc = default_loc) ?(attrs = []) fn
118117
Pexp_apply
119118
{
120119
funct = fn;
121-
args = Ext_list.map args (fun (l, a) -> (Asttypes.Labelled l, a));
120+
args =
121+
Ext_list.map args (fun (l, a) ->
122+
(Asttypes.Lbl {txt = l; loc = Location.none}, a));
122123
partial = false;
123124
};
124125
}
@@ -167,4 +168,4 @@ type object_field = Parsetree.object_field
167168

168169
let object_field l attrs ty = Parsetree.Otag (l, attrs, ty)
169170

170-
type args = (Asttypes.arg_label * Parsetree.expression) list
171+
type args = (Asttypes.arg_label_loc * Parsetree.expression) list

compiler/frontend/ast_compatible.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ type object_field = Parsetree.object_field
137137
val object_field :
138138
Asttypes.label Asttypes.loc -> attributes -> core_type -> object_field
139139

140-
type args = (Asttypes.arg_label * Parsetree.expression) list
140+
type args = (Asttypes.arg_label_loc * Parsetree.expression) list

compiler/frontend/ast_exp_apply.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
9191
| Pexp_apply {funct = fn1; args; partial} ->
9292
Bs_ast_invariant.warn_discarded_unused_attributes fn1.pexp_attributes;
9393
{
94-
pexp_desc =
95-
Pexp_apply {funct = fn1; args = (Nolabel, a) :: args; partial};
94+
pexp_desc = Pexp_apply {funct = fn1; args = (Nolbl, a) :: args; partial};
9695
pexp_loc = e.pexp_loc;
9796
pexp_attributes = e.pexp_attributes @ f.pexp_attributes;
9897
}
@@ -116,7 +115,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
116115
Pexp_apply
117116
{
118117
funct = fn;
119-
args = (Nolabel, bounded_obj_arg) :: args;
118+
args = (Nolbl, bounded_obj_arg) :: args;
120119
partial = false;
121120
};
122121
pexp_attributes = [];
@@ -170,7 +169,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
170169
let arg = self.expr self arg in
171170
let fn = Exp.send ~loc obj {txt = name ^ Literals.setter_suffix; loc} in
172171
Exp.constraint_ ~loc
173-
(Exp.apply ~loc fn [(Nolabel, arg)])
172+
(Exp.apply ~loc fn [(Nolbl, arg)])
174173
(Ast_literal.type_unit ~loc ())
175174
in
176175
match obj.pexp_desc with

compiler/frontend/ast_exp_extension.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
4545
Exp.apply ~loc
4646
(Exp.ident ~loc {txt = Longident.parse "Js.Exn.raiseError"; loc})
4747
[
48-
( Nolabel,
48+
( Nolbl,
4949
Exp.constant ~loc
5050
(Pconst_string
5151
( (pretext

0 commit comments

Comments
 (0)