@@ -171,6 +171,7 @@ type argument = {label: Asttypes.arg_label; expr: Parsetree.expression}
171171type type_parameter = {
172172 attrs : Ast_helper .attrs ;
173173 label : Asttypes .arg_label ;
174+ label_loc : Location .t ;
174175 typ : Parsetree .core_type ;
175176 start_pos : Lexing .position ;
176177}
@@ -4261,20 +4262,15 @@ and parse_type_parameter p =
42614262 | Tilde -> (
42624263 Parser. next p;
42634264 let name, loc = parse_lident p in
4264- let lbl_loc_attr =
4265- (Location. mkloc " res.namedArgLoc" loc, Parsetree. PStr [] )
4266- in
42674265 Parser. expect ~grammar: Grammar. TypeExpression Colon p;
4268- let typ =
4269- let typ = parse_typ_expr p in
4270- {typ with ptyp_attributes = lbl_loc_attr :: typ .ptyp_attributes}
4271- in
4266+ let typ = parse_typ_expr p in
42724267 match p.Parser. token with
42734268 | Equal ->
42744269 Parser. next p;
42754270 Parser. expect Question p;
4276- Some {attrs; label = Optional name; typ; start_pos}
4277- | _ -> Some {attrs; label = Labelled name; typ; start_pos})
4271+ Some {attrs; label = Optional name; label_loc = loc; typ; start_pos}
4272+ | _ ->
4273+ Some {attrs; label = Labelled name; label_loc = loc; typ; start_pos})
42784274 | Lident _ -> (
42794275 let name, loc = parse_lident p in
42804276 match p.token with
@@ -4292,8 +4288,9 @@ and parse_type_parameter p =
42924288 | Equal ->
42934289 Parser. next p;
42944290 Parser. expect Question p;
4295- Some {attrs; label = Optional name; typ; start_pos}
4296- | _ -> Some {attrs; label = Labelled name; typ; start_pos})
4291+ Some {attrs; label = Optional name; label_loc = loc; typ; start_pos}
4292+ | _ ->
4293+ Some {attrs; label = Labelled name; label_loc = loc; typ; start_pos})
42974294 | _ ->
42984295 let constr = Location. mkloc (Longident. Lident name) loc in
42994296 let args = parse_type_constructor_args ~constr_name: constr p in
@@ -4305,13 +4302,27 @@ and parse_type_parameter p =
43054302
43064303 let typ = parse_arrow_type_rest ~es6_arrow: true ~start_pos typ p in
43074304 let typ = parse_type_alias p typ in
4308- Some {attrs = [] ; label = Nolabel ; typ; start_pos})
4305+ Some
4306+ {
4307+ attrs = [] ;
4308+ label = Nolabel ;
4309+ label_loc = Location. none;
4310+ typ;
4311+ start_pos;
4312+ })
43094313 | _ ->
43104314 let typ = parse_typ_expr p in
43114315 let typ_with_attributes =
43124316 {typ with ptyp_attributes = List. concat [attrs; typ.ptyp_attributes]}
43134317 in
4314- Some {attrs = [] ; label = Nolabel ; typ = typ_with_attributes; start_pos}
4318+ Some
4319+ {
4320+ attrs = [] ;
4321+ label = Nolabel ;
4322+ label_loc = Location. none;
4323+ typ = typ_with_attributes;
4324+ start_pos;
4325+ }
43154326 else None
43164327
43174328(* (int, ~x:string, float) *)
@@ -4324,7 +4335,7 @@ and parse_type_parameters p =
43244335 let loc = mk_loc start_pos p.prev_end_pos in
43254336 let unit_constr = Location. mkloc (Longident. Lident " unit" ) loc in
43264337 let typ = Ast_helper.Typ. constr unit_constr [] in
4327- [{attrs = [] ; label = Nolabel ; typ; start_pos}]
4338+ [{attrs = [] ; label = Nolabel ; label_loc = Location. none; typ; start_pos}]
43284339 | _ ->
43294340 let params =
43304341 parse_comma_delimited_region ~grammar: Grammar. TypeParameters
@@ -4368,7 +4379,8 @@ and parse_es6_arrow_type ~attrs p =
43684379 let return_type_arity = 0 in
43694380 let _paramNum, typ, _arity =
43704381 List. fold_right
4371- (fun {attrs; label = arg_lbl ; typ; start_pos} (param_num , t , arity ) ->
4382+ (fun {attrs; label = arg_lbl ; label_loc; typ; start_pos}
4383+ (param_num , t , arity ) ->
43724384 let loc = mk_loc start_pos end_pos in
43734385 let arity =
43744386 (* Workaround for ~lbl: @as(json`false`) _, which changes the arity *)
@@ -4387,7 +4399,8 @@ and parse_es6_arrow_type ~attrs p =
43874399 | _ -> arity
43884400 in
43894401 let t_arg =
4390- Ast_helper.Typ. arrow ~loc ~attrs ~arity: None arg_lbl typ t
4402+ Ast_helper.Typ. arrow ~loc ~label_loc ~attrs ~arity: None arg_lbl typ
4403+ t
43914404 in
43924405 if param_num = 1 then
43934406 (param_num - 1 , Ast_uncurried. uncurried_type ~arity t_arg, 1 )
0 commit comments