diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe07dfdbb..06ce26d7dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,9 +33,9 @@ - AST cleanup: represent concatenation (`++`) and (dis)equality operators (`==`, `===`, `!=`, `!==`) just like in the syntax. https://github.com/rescript-lang/rescript/pull/7248 - AST cleanup: use inline record for `Ptyp_arrow`. https://github.com/rescript-lang/rescript/pull/7250 - Playground: Bundle stdlib runtime so that the playground can execute functions from Core/Belt/Js. (#7255) +- AST cleanup: Remove `res.namedArgLoc` attribute and store the location information directly into the label. https://github.com/rescript-lang/rescript/pull/7247 #### :nail_care: Polish - - Rewatch 1.0.10. https://github.com/rescript-lang/rescript/pull/7259 # 12.0.0-alpha.7 diff --git a/analysis/reanalyze/src/Arnold.ml b/analysis/reanalyze/src/Arnold.ml index 70d1f97924..9b31743603 100644 --- a/analysis/reanalyze/src/Arnold.ml +++ b/analysis/reanalyze/src/Arnold.ml @@ -582,7 +582,7 @@ module ExtendFunctionTable = struct Texp_apply {funct = {exp_desc = Texp_ident (path, {loc}, _)}; args}; } when kindOpt <> None -> - let checkArg ((argLabel : Asttypes.arg_label), _argOpt) = + let checkArg ((argLabel : Asttypes.Noloc.arg_label), _argOpt) = match (argLabel, kindOpt) with | (Labelled l | Optional l), Some kind -> kind |> List.for_all (fun {Kind.label} -> label <> l) @@ -624,7 +624,7 @@ module ExtendFunctionTable = struct when callee |> FunctionTable.isInFunctionInTable ~functionTable -> let functionName = Path.name callee in args - |> List.iter (fun ((argLabel : Asttypes.arg_label), argOpt) -> + |> List.iter (fun ((argLabel : Asttypes.Noloc.arg_label), argOpt) -> match (argLabel, argOpt |> extractLabelledArgument) with | Labelled label, Some (path, loc) when path |> FunctionTable.isInFunctionInTable ~functionTable @@ -672,7 +672,7 @@ module CheckExpressionWellFormed = struct -> let functionName = Path.name functionPath in args - |> List.iter (fun ((argLabel : Asttypes.arg_label), argOpt) -> + |> List.iter (fun ((argLabel : Asttypes.Noloc.arg_label), argOpt) -> match argOpt |> ExtendFunctionTable.extractLabelledArgument with | Some (path, loc) -> ( match argLabel with @@ -761,7 +761,7 @@ module Compile = struct let argsFromKind = innerFunctionDefinition.kind |> List.map (fun (entry : Kind.entry) -> - ( Asttypes.Labelled entry.label, + ( Asttypes.Noloc.Labelled entry.label, Some { expr with @@ -785,7 +785,7 @@ module Compile = struct args |> List.find_opt (fun arg -> match arg with - | Asttypes.Labelled s, Some _ -> s = label + | Asttypes.Noloc.Labelled s, Some _ -> s = label | _ -> false) in let argOpt = diff --git a/analysis/reanalyze/src/DeadValue.ml b/analysis/reanalyze/src/DeadValue.ml index 9c07e696ae..57ddeccd26 100644 --- a/analysis/reanalyze/src/DeadValue.ml +++ b/analysis/reanalyze/src/DeadValue.ml @@ -104,7 +104,7 @@ let processOptionalArgs ~expType ~(locFrom : Location.t) ~locTo ~path args = | None -> Some false in match lbl with - | Asttypes.Optional s when not locFrom.loc_ghost -> + | Asttypes.Noloc.Optional s when not locFrom.loc_ghost -> if argIsSupplied <> Some false then supplied := s :: !supplied; if argIsSupplied = None then suppliedMaybe := s :: !suppliedMaybe | _ -> ()); diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 3982783510..3becd1cecf 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -952,7 +952,8 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact (* compute the application of the first label, then the next ones *) let args = processApply args [label] in processApply args nextLabels - | (Asttypes.Nolabel, _) :: nextArgs, [Asttypes.Nolabel] -> nextArgs + | (Asttypes.Noloc.Nolabel, _) :: nextArgs, [Asttypes.Noloc.Nolabel] -> + nextArgs | ((Labelled _, _) as arg) :: nextArgs, [Nolabel] -> arg :: processApply nextArgs labels | (Optional _, _) :: nextArgs, [Nolabel] -> processApply nextArgs labels @@ -1007,9 +1008,9 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact synthetic = true; contextPath = (match cp with - | CPApply (c, args) -> CPApply (c, args @ [Asttypes.Nolabel]) + | CPApply (c, args) -> CPApply (c, args @ [Asttypes.Noloc.Nolabel]) | CPId _ when TypeUtils.isFunctionType ~env ~package typ -> - CPApply (cp, [Asttypes.Nolabel]) + CPApply (cp, [Asttypes.Noloc.Nolabel]) | _ -> cp); id = fieldName; inJsx = false; diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index dc5fd62a47..4ca35778a8 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -298,7 +298,10 @@ let rec exprToContextPathInner (e : Parsetree.expression) = | Pexp_apply {funct = e1; args} -> ( match exprToContextPath e1 with | None -> None - | Some contexPath -> Some (CPApply (contexPath, args |> List.map fst))) + | Some contexPath -> + Some + (CPApply (contexPath, args |> List.map fst |> List.map Asttypes.to_noloc)) + ) | Pexp_tuple exprs -> let exprsAsContextPaths = exprs |> List.filter_map exprToContextPath in if List.length exprs = List.length exprsAsContextPaths then @@ -1446,8 +1449,8 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor (match lbl with | Nolabel -> Unlabelled {argumentPosition = currentUnlabelledCount} - | Optional name -> Optional name - | Labelled name -> Labelled name); + | Optional {txt = name} -> Optional name + | Labelled {txt = name} -> Labelled name); }) in (match defaultExpOpt with diff --git a/analysis/src/CompletionJsx.ml b/analysis/src/CompletionJsx.ml index b68c06ad1a..5014a665c8 100644 --- a/analysis/src/CompletionJsx.ml +++ b/analysis/src/CompletionJsx.ml @@ -465,20 +465,19 @@ let extractJsxProps ~(compName : Longident.t Location.loc) ~args = in let rec processProps ~acc args = match args with - | (Asttypes.Labelled "children", {Parsetree.pexp_loc}) :: _ -> + | (Asttypes.Labelled {txt = "children"}, {Parsetree.pexp_loc}) :: _ -> { compName; props = List.rev acc; childrenStart = (if pexp_loc.loc_ghost then None else Some (Loc.start pexp_loc)); } - | ((Labelled s | Optional s), (eProp : Parsetree.expression)) :: rest -> ( - let namedArgLoc = - eProp.pexp_attributes - |> List.find_opt (fun ({Asttypes.txt}, _) -> txt = "res.namedArgLoc") - in + | ( (Labelled {txt = s; loc} | Optional {txt = s; loc}), + (eProp : Parsetree.expression) ) + :: rest -> ( + let namedArgLoc = if loc = Location.none then None else Some loc in match namedArgLoc with - | Some ({loc}, _) -> + | Some loc -> processProps ~acc: ({ diff --git a/analysis/src/CreateInterface.ml b/analysis/src/CreateInterface.ml index 962ea4469c..6aa1ea1993 100644 --- a/analysis/src/CreateInterface.ml +++ b/analysis/src/CreateInterface.ml @@ -170,7 +170,7 @@ let printSignature ~extractor ~signature = in let lblName = labelDecl.ld_id |> Ident.name in let lbl = - if labelDecl.ld_optional then Asttypes.Optional lblName + if labelDecl.ld_optional then Asttypes.Noloc.Optional lblName else Labelled lblName in { diff --git a/analysis/src/DumpAst.ml b/analysis/src/DumpAst.ml index b017a39e66..627cd8106e 100644 --- a/analysis/src/DumpAst.ml +++ b/analysis/src/DumpAst.ml @@ -219,8 +219,8 @@ and printExprItem expr ~pos ~indentation = ^ "arg: " ^ (match arg with | Nolabel -> "Nolabel" - | Labelled name -> "Labelled(" ^ name ^ ")" - | Optional name -> "Optional(" ^ name ^ ")") + | Labelled {txt = name} -> "Labelled(" ^ name ^ ")" + | Optional {txt = name} -> "Optional(" ^ name ^ ")") ^ ",\n" ^ addIndentation (indentation + 2) ^ "pattern: " diff --git a/analysis/src/SemanticTokens.ml b/analysis/src/SemanticTokens.ml index b1215e154d..cbd435a5c4 100644 --- a/analysis/src/SemanticTokens.ml +++ b/analysis/src/SemanticTokens.ml @@ -266,7 +266,7 @@ let command ~debug ~emitter ~path = let posOfGreatherthanAfterProps = let rec loop = function - | (Asttypes.Labelled "children", {Parsetree.pexp_loc}) :: _ -> + | (Asttypes.Labelled {txt = "children"}, {Parsetree.pexp_loc}) :: _ -> Loc.start pexp_loc | _ :: args -> loop args | [] -> (* should not happen *) (-1, -1) diff --git a/analysis/src/SharedTypes.ml b/analysis/src/SharedTypes.ml index 59675f1811..600c39a867 100644 --- a/analysis/src/SharedTypes.ml +++ b/analysis/src/SharedTypes.ml @@ -4,7 +4,7 @@ let ident l = l |> List.map str |> String.concat "." type path = string list -type typedFnArg = Asttypes.arg_label * Types.type_expr +type typedFnArg = Asttypes.Noloc.arg_label * Types.type_expr let pathToString (path : path) = path |> String.concat "." @@ -605,7 +605,7 @@ module Completable = struct | CPFloat | CPBool | CPOption of contextPath - | CPApply of contextPath * Asttypes.arg_label list + | CPApply of contextPath * Asttypes.Noloc.arg_label list | CPId of { path: string list; completionContext: completionContext; @@ -692,7 +692,7 @@ module Completable = struct contextPathToString cp ^ "(" ^ (labels |> List.map (function - | Asttypes.Nolabel -> "Nolabel" + | Asttypes.Noloc.Nolabel -> "Nolabel" | Labelled s -> "~" ^ s | Optional s -> "?" ^ s) |> String.concat ", ") @@ -898,14 +898,12 @@ type arg = {label: label; exp: Parsetree.expression} let extractExpApplyArgs ~args = let rec processArgs ~acc args = match args with - | (((Asttypes.Labelled s | Optional s) as label), (e : Parsetree.expression)) + | ( ((Asttypes.Labelled {txt = s; loc} | Optional {txt = s; loc}) as label), + (e : Parsetree.expression) ) :: rest -> ( - let namedArgLoc = - e.pexp_attributes - |> List.find_opt (fun ({Asttypes.txt}, _) -> txt = "res.namedArgLoc") - in + let namedArgLoc = if loc = Location.none then None else Some loc in match namedArgLoc with - | Some ({loc}, _) -> + | Some loc -> let labelled = { name = s; @@ -919,7 +917,7 @@ let extractExpApplyArgs ~args = in processArgs ~acc:({label = Some labelled; exp = e} :: acc) rest | None -> processArgs ~acc rest) - | (Asttypes.Nolabel, (e : Parsetree.expression)) :: rest -> + | (Nolabel, (e : Parsetree.expression)) :: rest -> if e.pexp_loc.loc_ghost then processArgs ~acc rest else processArgs ~acc:({label = None; exp = e} :: acc) rest | [] -> List.rev acc diff --git a/analysis/src/SignatureHelp.ml b/analysis/src/SignatureHelp.ml index 0b7b91b5b5..edc2807de0 100644 --- a/analysis/src/SignatureHelp.ml +++ b/analysis/src/SignatureHelp.ml @@ -154,14 +154,14 @@ let findActiveParameter ~argAtCursor ~args = (* If a function only has one, unlabelled argument, we can safely assume that's active whenever we're in the signature help for that function, even if we technically didn't find anything at the cursor (which we don't for empty expressions). *) match args with - | [(Asttypes.Nolabel, _)] -> Some 0 + | [(Asttypes.Noloc.Nolabel, _)] -> Some 0 | _ -> None) | Some (Unlabelled unlabelledArgumentIndex) -> let index = ref 0 in args |> List.find_map (fun (label, _) -> match label with - | Asttypes.Nolabel when !index = unlabelledArgumentIndex -> + | Asttypes.Noloc.Nolabel when !index = unlabelledArgumentIndex -> Some !index | _ -> index := !index + 1; @@ -171,7 +171,7 @@ let findActiveParameter ~argAtCursor ~args = args |> List.find_map (fun (label, _) -> match label with - | (Asttypes.Labelled labelName | Optional labelName) + | (Asttypes.Noloc.Labelled labelName | Optional labelName) when labelName = name -> Some !index | _ -> @@ -474,6 +474,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads = parameters = parameters |> List.map (fun (argLabel, start, end_) -> + let argLabel = Asttypes.to_noloc argLabel in let paramArgCount = !paramUnlabelledArgCount in paramUnlabelledArgCount := paramArgCount + 1; let unlabelledArgCount = ref 0 in @@ -486,8 +487,8 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads = let argCount = !unlabelledArgCount in unlabelledArgCount := argCount + 1; match (lbl, argLabel) with - | ( Asttypes.Optional l1, - Asttypes.Optional l2 ) + | ( Asttypes.Noloc.Optional l1, + Asttypes.Noloc.Optional l2 ) when l1 = l2 -> true | Labelled l1, Labelled l2 diff --git a/analysis/src/TypeUtils.ml b/analysis/src/TypeUtils.ml index 3942aae2fe..ffeca9ae40 100644 --- a/analysis/src/TypeUtils.ml +++ b/analysis/src/TypeUtils.ml @@ -1123,7 +1123,7 @@ let getFirstFnUnlabelledArgType ~env ~full t = in let rec findFirstUnlabelledArgType labels = match labels with - | (Asttypes.Nolabel, t) :: _ -> Some t + | (Asttypes.Noloc.Nolabel, t) :: _ -> Some t | _ :: rest -> findFirstUnlabelledArgType rest | [] -> None in diff --git a/compiler/frontend/ast_compatible.ml b/compiler/frontend/ast_compatible.ml index 8fb72e457c..04a1be4f4a 100644 --- a/compiler/frontend/ast_compatible.ml +++ b/compiler/frontend/ast_compatible.ml @@ -117,22 +117,29 @@ let apply_labels ?(loc = default_loc) ?(attrs = []) fn Pexp_apply { funct = fn; - args = Ext_list.map args (fun (l, a) -> (Asttypes.Labelled l, a)); + args = + Ext_list.map args (fun (l, a) -> + (Asttypes.Labelled {txt = l; loc = Location.none}, a)); partial = false; }; } -let label_arrow ?(loc = default_loc) ?(attrs = []) ~arity s arg ret : core_type - = +let label_arrow ?(loc = default_loc) ?(attrs = []) ~arity txt arg ret : + core_type = { - ptyp_desc = Ptyp_arrow {lbl = Labelled s; arg; ret; arity}; + ptyp_desc = + Ptyp_arrow + {lbl = Asttypes.Labelled {txt; loc = default_loc}; arg; ret; arity}; ptyp_loc = loc; ptyp_attributes = attrs; } -let opt_arrow ?(loc = default_loc) ?(attrs = []) ~arity s arg ret : core_type = +let opt_arrow ?(loc = default_loc) ?(attrs = []) ~arity txt arg ret : core_type + = { - ptyp_desc = Ptyp_arrow {lbl = Asttypes.Optional s; arg; ret; arity}; + ptyp_desc = + Ptyp_arrow + {lbl = Asttypes.Optional {txt; loc = default_loc}; arg; ret; arity}; ptyp_loc = loc; ptyp_attributes = attrs; } diff --git a/compiler/frontend/ast_external_process.ml b/compiler/frontend/ast_external_process.ml index 3e73b4fd2c..4753594c55 100644 --- a/compiler/frontend/ast_external_process.ml +++ b/compiler/frontend/ast_external_process.ml @@ -471,7 +471,7 @@ let process_obj (loc : Location.t) (st : external_desc) (prim_name : string) | _ -> Location.raise_errorf ~loc "expect label, optional, or unit here") - | Labelled label -> ( + | Labelled {txt = label} -> ( let field_name = match Ast_attributes.iter_process_bs_string_as param_type.attr @@ -530,7 +530,7 @@ let process_obj (loc : Location.t) (st : external_desc) (prim_name : string) | Unwrap -> Location.raise_errorf ~loc "%@obj label %s does not support %@unwrap arguments" label) - | Optional label -> ( + | Optional {txt = label} -> ( let field_name = match Ast_attributes.iter_process_bs_string_as param_type.attr @@ -983,7 +983,7 @@ let handle_attributes (loc : Bs_loc.t) (type_annotation : Parsetree.core_type) arg_type, new_arg_types ) = match arg_label with - | Optional s -> ( + | Optional {txt = s} -> ( let arg_type = get_opt_arg_type ~nolabel:false ty in match arg_type with | Poly_var _ -> diff --git a/compiler/gentype/TranslateCoreType.ml b/compiler/gentype/TranslateCoreType.ml index f2486af0b3..fe6354aaf5 100644 --- a/compiler/gentype/TranslateCoreType.ml +++ b/compiler/gentype/TranslateCoreType.ml @@ -1,7 +1,7 @@ open GenTypeCommon open! TranslateTypeExprFromTypes -let remove_option ~(label : Asttypes.arg_label) +let remove_option ~(label : Asttypes.Noloc.arg_label) (core_type : Typedtree.core_type) = match (core_type.ctyp_desc, label) with | Ttyp_constr (Path.Pident id, _, [t]), Optional lbl diff --git a/compiler/gentype/TranslateTypeExprFromTypes.ml b/compiler/gentype/TranslateTypeExprFromTypes.ml index 100c42dc2a..75615bcdef 100644 --- a/compiler/gentype/TranslateTypeExprFromTypes.ml +++ b/compiler/gentype/TranslateTypeExprFromTypes.ml @@ -2,7 +2,7 @@ open GenTypeCommon type translation = {dependencies: dep list; type_: type_} -let rec remove_option ~(label : Asttypes.arg_label) +let rec remove_option ~(label : Asttypes.Noloc.arg_label) (type_expr : Types.type_expr) = match (type_expr.desc, label) with | Tconstr (Path.Pident id, [t], _), Optional lbl when Ident.name id = "option" diff --git a/compiler/ml/ast_helper.ml b/compiler/ml/ast_helper.ml index e65a39faa1..aa0c66dbfc 100644 --- a/compiler/ml/ast_helper.ml +++ b/compiler/ml/ast_helper.ml @@ -82,8 +82,8 @@ module Typ = struct | Ptyp_var x -> check_variable var_names t.ptyp_loc x; Ptyp_var x - | Ptyp_arrow {lbl = label; arg; ret; arity = a} -> - Ptyp_arrow {lbl = label; arg = loop arg; ret = loop ret; arity = a} + | Ptyp_arrow ({arg; ret} as arr) -> + Ptyp_arrow {arr with arg = loop arg; ret = loop ret} | Ptyp_tuple lst -> Ptyp_tuple (List.map loop lst) | Ptyp_constr ({txt = Longident.Lident s}, []) when List.mem s var_names -> diff --git a/compiler/ml/ast_mapper_from0.ml b/compiler/ml/ast_mapper_from0.ml index f36bea1f0d..1e3e3687b7 100644 --- a/compiler/ml/ast_mapper_from0.ml +++ b/compiler/ml/ast_mapper_from0.ml @@ -99,6 +99,7 @@ module T = struct | Ptyp_any -> any ~loc ~attrs () | Ptyp_var s -> var ~loc ~attrs s | Ptyp_arrow (lab, t1, t2) -> + let lab = Asttypes.to_arg_label lab in arrow ~loc ~attrs ~arity:None lab (sub.typ sub t1) (sub.typ sub t2) | Ptyp_tuple tyl -> tuple ~loc ~attrs (List.map (sub.typ sub) tyl) | Ptyp_constr (lid, tl) -> ( @@ -304,6 +305,7 @@ module E = struct | Pexp_let (r, vbs, e) -> let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) (sub.expr sub e) | Pexp_fun (lab, def, p, e) -> + let lab = Asttypes.to_arg_label lab in let async = Ext_list.exists attrs (fun ({txt}, _) -> txt = "res.async") in fun_ ~loc ~attrs ~async ~arity:None lab (map_opt (sub.expr sub) def) @@ -349,7 +351,9 @@ module E = struct in let partial, attrs = process_partial_app_attribute attrs in apply ~loc ~attrs ~partial (sub.expr sub e) - (List.map (map_snd (sub.expr sub)) l) + (List.map + (fun (lbl, e) -> (Asttypes.to_arg_label lbl, sub.expr sub e)) + l) | Pexp_match (e, pel) -> match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) | Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) diff --git a/compiler/ml/ast_mapper_to0.ml b/compiler/ml/ast_mapper_to0.ml index 0014af48a0..7ed4eab6d0 100644 --- a/compiler/ml/ast_mapper_to0.ml +++ b/compiler/ml/ast_mapper_to0.ml @@ -99,6 +99,7 @@ module T = struct | Ptyp_any -> any ~loc ~attrs () | Ptyp_var s -> var ~loc ~attrs s | Ptyp_arrow {lbl; arg; ret; arity} -> ( + let lbl = Asttypes.to_noloc lbl in let typ0 = arrow ~loc ~attrs lbl (sub.typ sub arg) (sub.typ sub ret) in match arity with | None -> typ0 @@ -293,6 +294,7 @@ module E = struct let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) (sub.expr sub e) | Pexp_fun {arg_label = lab; default = def; lhs = p; rhs = e; arity; async} -> ( + let lab = Asttypes.to_noloc lab in let attrs = if async then ({txt = "res.async"; loc = Location.none}, Pt.PStr []) :: attrs @@ -349,7 +351,9 @@ module E = struct else attrs in apply ~loc ~attrs (sub.expr sub e) - (List.map (map_snd (sub.expr sub)) args) + (List.map + (fun (lbl, e) -> (Asttypes.to_noloc lbl, sub.expr sub e)) + args) | Pexp_match (e, pel) -> match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) | Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) diff --git a/compiler/ml/asttypes.ml b/compiler/ml/asttypes.ml index cd5379cb8e..d969740e7b 100644 --- a/compiler/ml/asttypes.ml +++ b/compiler/ml/asttypes.ml @@ -41,25 +41,59 @@ type closed_flag = Closed | Open type label = string -type arg_label = - | Nolabel - | Labelled of string (* label:T -> ... *) - | Optional of string (* ?label:T -> ... *) - type arity = int option type 'a loc = 'a Location.loc = {txt: 'a; loc: Location.t} type variance = Covariant | Contravariant | Invariant +type arg_label = + | Nolabel (* x => ...*) + | Labelled of string loc (* ~label => ... *) + | Optional of string loc (* ~(label=e) => ... *) + +module Noloc = struct + type arg_label = + | Nolabel (* x => ...*) + | Labelled of string (* ~label => ... *) + | Optional of string (* ~(label=e) => ... *) + + let same_arg_label (x : arg_label) y = + match x with + | Nolabel -> y = Nolabel + | Labelled s -> ( + match y with + | Labelled s0 -> s = s0 + | _ -> false) + | Optional s -> ( + match y with + | Optional s0 -> s = s0 + | _ -> false) +end + +let to_arg_label ?(loc = Location.none) lbl = + match lbl with + | Noloc.Nolabel -> Nolabel + | Labelled s -> Labelled {loc; txt = s} + | Optional s -> Optional {loc; txt = s} + +let to_noloc = function + | Nolabel -> Noloc.Nolabel + | Labelled {txt} -> Labelled txt + | Optional {txt} -> Optional txt + let same_arg_label (x : arg_label) y = match x with | Nolabel -> y = Nolabel - | Labelled s -> ( + | Labelled {txt = s} -> ( match y with - | Labelled s0 -> s = s0 + | Labelled {txt = s0} -> s = s0 | _ -> false) - | Optional s -> ( + | Optional {txt = s} -> ( match y with - | Optional s0 -> s = s0 + | Optional {txt = s0} -> s = s0 | _ -> false) + +let get_lbl_loc = function + | Nolabel -> Location.none + | Labelled {loc} | Optional {loc} -> loc diff --git a/compiler/ml/btype.ml b/compiler/ml/btype.ml index 81e8d24cd0..8b6046c095 100644 --- a/compiler/ml/btype.ml +++ b/compiler/ml/btype.ml @@ -593,15 +593,23 @@ let forget_abbrev mem path = (**********************************) let is_optional = function + | Noloc.Optional _ -> true + | _ -> false + +let is_optional_loc = function | Optional _ -> true | _ -> false let label_name = function - | Nolabel -> "" + | Noloc.Nolabel -> "" | Labelled s | Optional s -> s -let prefixed_label_name = function +let label_loc_name = function | Nolabel -> "" + | Labelled {txt} | Optional {txt} -> txt + +let prefixed_label_name = function + | Noloc.Nolabel -> "" | Labelled s -> "~" ^ s | Optional s -> "?" ^ s @@ -610,7 +618,7 @@ type sargs = (Asttypes.arg_label * Parsetree.expression) list let rec extract_label_aux hd l = function | [] -> None | ((l', t) as p) :: ls -> - if label_name l' = l then Some (l', t, List.rev_append hd ls) + if label_loc_name l' = l then Some (l', t, List.rev_append hd ls) else extract_label_aux (p :: hd) l ls let extract_label l (ls : sargs) : diff --git a/compiler/ml/btype.mli b/compiler/ml/btype.mli index ef099af22b..e19c6a644f 100644 --- a/compiler/ml/btype.mli +++ b/compiler/ml/btype.mli @@ -180,11 +180,13 @@ val forget_abbrev : abbrev_memo ref -> Path.t -> unit (**** Utilities for labels ****) -val is_optional : arg_label -> bool -val label_name : arg_label -> label +val is_optional : Noloc.arg_label -> bool +val is_optional_loc : arg_label -> bool +val label_name : Noloc.arg_label -> label +val label_loc_name : arg_label -> label (* Returns the label name with first character '?' or '~' as appropriate. *) -val prefixed_label_name : arg_label -> label +val prefixed_label_name : Noloc.arg_label -> label type sargs = (arg_label * Parsetree.expression) list diff --git a/compiler/ml/ctype.ml b/compiler/ml/ctype.ml index de2ad58632..77b5755a26 100644 --- a/compiler/ml/ctype.ml +++ b/compiler/ml/ctype.ml @@ -1893,7 +1893,7 @@ let rec mcomp type_pairs env t1 t2 = match (t1'.desc, t2'.desc) with | Tvar _, Tvar _ -> assert false | Tarrow (l1, t1, u1, _, _), Tarrow (l2, t2, u2, _, _) - when Asttypes.same_arg_label l1 l2 + when Asttypes.Noloc.same_arg_label l1 l2 || not (is_optional l1 || is_optional l2) -> mcomp type_pairs env t1 t2; mcomp type_pairs env u1 u2 @@ -2310,7 +2310,7 @@ and unify3 env t1 t1' t2 t2' = (match (d1, d2) with | Tarrow (l1, t1, u1, c1, a1), Tarrow (l2, t2, u2, c2, a2) when a1 = a2 - && (Asttypes.same_arg_label l1 l2 + && (Asttypes.Noloc.same_arg_label l1 l2 || (!umode = Pattern && not (is_optional l1 || is_optional l2)) ) -> ( unify env t1 t2; @@ -2765,7 +2765,7 @@ let filter_arrow ~env ~arity t l = let t' = newty2 lv (Tarrow (l, t1, t2, Cok, arity)) in link_type t t'; (t1, t2) - | Tarrow (l', t1, t2, _, _) when Asttypes.same_arg_label l l' -> (t1, t2) + | Tarrow (l', t1, t2, _, _) when Asttypes.Noloc.same_arg_label l l' -> (t1, t2) | _ -> raise (Unify []) (* Used by [filter_method]. *) @@ -2880,7 +2880,7 @@ let rec moregen inst_nongen type_pairs env t1 t2 = moregen_occur env t1'.level t2; link_type t1' t2 | Tarrow (l1, t1, u1, _, _), Tarrow (l2, t2, u2, _, _) - when Asttypes.same_arg_label l1 l2 -> + when Asttypes.Noloc.same_arg_label l1 l2 -> moregen inst_nongen type_pairs env t1 t2; moregen inst_nongen type_pairs env u1 u2 | Ttuple tl1, Ttuple tl2 -> @@ -3150,7 +3150,7 @@ let rec eqtype rename type_pairs subst env t1 t2 = raise (Unify []); subst := (t1', t2') :: !subst) | Tarrow (l1, t1, u1, _, _), Tarrow (l2, t2, u2, _, _) - when Asttypes.same_arg_label l1 l2 -> + when Asttypes.Noloc.same_arg_label l1 l2 -> eqtype rename type_pairs subst env t1 t2; eqtype rename type_pairs subst env u1 u2 | Ttuple tl1, Ttuple tl2 -> @@ -3563,7 +3563,7 @@ let rec subtype_rec env trace t1 t2 cstrs = match (t1.desc, t2.desc) with | Tvar _, _ | _, Tvar _ -> (trace, t1, t2, !univar_pairs) :: cstrs | Tarrow (l1, t1, u1, _, _), Tarrow (l2, t2, u2, _, _) - when Asttypes.same_arg_label l1 l2 -> + when Asttypes.Noloc.same_arg_label l1 l2 -> let cstrs = subtype_rec env ((t2, t1) :: trace) t2 t1 cstrs in subtype_rec env ((u1, u2) :: trace) u1 u2 cstrs | Ttuple tl1, Ttuple tl2 -> subtype_list env trace tl1 tl2 cstrs diff --git a/compiler/ml/ctype.mli b/compiler/ml/ctype.mli index d7d3a1bc4f..f3690efb51 100644 --- a/compiler/ml/ctype.mli +++ b/compiler/ml/ctype.mli @@ -204,7 +204,11 @@ val with_passive_variants : ('a -> 'b) -> 'a -> 'b (* Call [f] in passive_variants mode, for exhaustiveness check. *) val filter_arrow : - env:Env.t -> arity:arity -> type_expr -> arg_label -> type_expr * type_expr + env:Env.t -> + arity:arity -> + type_expr -> + Noloc.arg_label -> + type_expr * type_expr (* A special case of unification (with l:'a -> 'b). *) val filter_method : Env.t -> string -> private_flag -> type_expr -> type_expr diff --git a/compiler/ml/parsetree0.ml b/compiler/ml/parsetree0.ml index 805214c8de..2b6a7eebd8 100644 --- a/compiler/ml/parsetree0.ml +++ b/compiler/ml/parsetree0.ml @@ -76,7 +76,7 @@ and core_type = { and core_type_desc = | Ptyp_any (* _ *) | Ptyp_var of string (* 'a *) - | Ptyp_arrow of arg_label * core_type * core_type + | Ptyp_arrow of Noloc.arg_label * core_type * core_type (* T1 -> T2 Simple ~l:T1 -> T2 Labelled ?l:T1 -> T2 Optional @@ -225,7 +225,7 @@ and expression_desc = let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive) *) | Pexp_function of case list (* function P1 -> E1 | ... | Pn -> En *) - | Pexp_fun of arg_label * expression option * pattern * expression + | Pexp_fun of Noloc.arg_label * expression option * pattern * expression (* fun P -> E1 (Simple, None) fun ~l:P -> E1 (Labelled l, None) fun ?l:P -> E1 (Optional l, None) @@ -236,7 +236,7 @@ and expression_desc = - "fun P1 P2 .. Pn -> E1" is represented as nested Pexp_fun. - "let f P = E" is represented using Pexp_fun. *) - | Pexp_apply of expression * (arg_label * expression) list + | Pexp_apply of expression * (Noloc.arg_label * expression) list (* E0 ~l1:E1 ... ~ln:En li can be empty (non labeled argument) or start with '?' (optional argument). diff --git a/compiler/ml/pprintast.ml b/compiler/ml/pprintast.ml index ca6ae8d64e..33a8a2655f 100644 --- a/compiler/ml/pprintast.ml +++ b/compiler/ml/pprintast.ml @@ -288,8 +288,8 @@ let string_quot f x = pp f "`%s" x let rec type_with_label ctxt f (label, c) = match label with | Nolabel -> core_type1 ctxt f c (* otherwise parenthesize *) - | Labelled s -> pp f "%s:%a" s (core_type1 ctxt) c - | Optional s -> pp f "?%s:%a" s (core_type1 ctxt) c + | Labelled {txt = s} -> pp f "%s:%a" s (core_type1 ctxt) c + | Optional {txt = s} -> pp f "?%s:%a" s (core_type1 ctxt) c and core_type ctxt f x = if x.ptyp_attributes <> [] then @@ -497,7 +497,7 @@ and label_exp ctxt f (l, opt, p) = | Nolabel -> (* single case pattern parens needed here *) pp f "%a@ " (simple_pattern ctxt) p - | Optional rest -> ( + | Optional {txt = rest} -> ( match p with | {ppat_desc = Ppat_var {txt; _}; ppat_attributes = []} when txt = rest -> ( match opt with @@ -508,7 +508,7 @@ and label_exp ctxt f (l, opt, p) = | Some o -> pp f "?%s:(%a=@;%a)@;" rest (pattern1 ctxt) p (expression ctxt) o | None -> pp f "?%s:%a@;" rest (simple_pattern ctxt) p)) - | Labelled l -> ( + | Labelled {txt = l} -> ( match p with | {ppat_desc = Ppat_var {txt; _}; ppat_attributes = []} when txt = l -> pp f "~%s@;" l @@ -1282,10 +1282,10 @@ and label_x_expression_param ctxt f (l, e) = in match l with | Nolabel -> expression2 ctxt f e (* level 2*) - | Optional str -> + | Optional {txt = str} -> if Some str = simple_name then pp f "?%s" str else pp f "?%s:%a" str (simple_expr ctxt) e - | Labelled lbl -> + | Labelled {txt = lbl} -> if Some lbl = simple_name then pp f "~%s" lbl else pp f "~%s:%a" lbl (simple_expr ctxt) e diff --git a/compiler/ml/printast.ml b/compiler/ml/printast.ml index 56d0037d22..777829f0c9 100644 --- a/compiler/ml/printast.ml +++ b/compiler/ml/printast.ml @@ -110,10 +110,11 @@ let option i f ppf x = let longident_loc i ppf li = line i ppf "%a\n" fmt_longident_loc li let string i ppf s = line i ppf "\"%s\"\n" s let string_loc i ppf s = line i ppf "%a\n" fmt_string_loc s -let arg_label i ppf = function + +let arg_label_loc i ppf = function | Nolabel -> line i ppf "Nolabel\n" - | Optional s -> line i ppf "Optional \"%s\"\n" s - | Labelled s -> line i ppf "Labelled \"%s\"\n" s + | Optional {txt = s} -> line i ppf "Optional \"%s\"\n" s + | Labelled {txt = s} -> line i ppf "Labelled \"%s\"\n" s let rec core_type i ppf x = line i ppf "core_type %a\n" fmt_location x.ptyp_loc; @@ -129,7 +130,7 @@ let rec core_type i ppf x = | None -> () | Some n -> line i ppf "arity = %d\n" n in - arg_label i ppf lbl; + arg_label_loc i ppf lbl; core_type i ppf arg; core_type i ppf ret | Ptyp_tuple l -> @@ -246,7 +247,7 @@ and expression i ppf x = | None -> () | Some arity -> line i ppf "arity:%d\n" arity in - arg_label i ppf l; + arg_label_loc i ppf l; option i expression ppf eo; pattern i ppf p; expression i ppf e @@ -657,7 +658,7 @@ and longident_x_expression i ppf (li, e, opt) = and label_x_expression i ppf (l, e) = line i ppf "\n"; - arg_label i ppf l; + arg_label_loc i ppf l; expression (i + 1) ppf e and label_x_bool_x_core_type_list i ppf x = diff --git a/compiler/ml/printtyp.ml b/compiler/ml/printtyp.ml index 90a9fa1289..d5be994bad 100644 --- a/compiler/ml/printtyp.ml +++ b/compiler/ml/printtyp.ml @@ -142,7 +142,7 @@ let print_name ppf = function | Some name -> fprintf ppf "\"%s\"" name let string_of_label = function - | Nolabel -> "" + | Noloc.Nolabel -> "" | Labelled s -> s | Optional s -> "?" ^ s diff --git a/compiler/ml/printtyp.mli b/compiler/ml/printtyp.mli index c95ee90e5e..a2bf9823fb 100644 --- a/compiler/ml/printtyp.mli +++ b/compiler/ml/printtyp.mli @@ -26,7 +26,7 @@ val tree_of_path : Path.t -> out_ident val path : formatter -> Path.t -> unit val string_of_path : Path.t -> string val raw_type_expr : formatter -> type_expr -> unit -val string_of_label : Asttypes.arg_label -> string +val string_of_label : Asttypes.Noloc.arg_label -> string val wrap_printing_env : Env.t -> (unit -> 'a) -> 'a (* Call the function using the environment for type path shortening *) diff --git a/compiler/ml/printtyped.ml b/compiler/ml/printtyped.ml index 31cb9ef213..6bdd794d97 100644 --- a/compiler/ml/printtyped.ml +++ b/compiler/ml/printtyped.ml @@ -121,7 +121,7 @@ let option i f ppf x = let longident i ppf li = line i ppf "%a\n" fmt_longident li let string i ppf s = line i ppf "\"%s\"\n" s let arg_label i ppf = function - | Nolabel -> line i ppf "Nolabel\n" + | Noloc.Nolabel -> line i ppf "Nolabel\n" | Optional s -> line i ppf "Optional \"%s\"\n" s | Labelled s -> line i ppf "Labelled \"%s\"\n" s diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index a0e4e42200..fc100aa3c9 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -34,7 +34,7 @@ type error = | Orpat_vars of Ident.t * Ident.t list | Expr_type_clash of (type_expr * type_expr) list * type_clash_context option | Apply_non_function of type_expr - | Apply_wrong_label of arg_label * type_expr + | Apply_wrong_label of Noloc.arg_label * type_expr | Label_multiply_defined of { label: string; jsx_component_info: jsx_prop_error_info option; @@ -52,7 +52,7 @@ type error = | Private_label of Longident.t * type_expr | Not_subtype of (type_expr * type_expr) list * (type_expr * type_expr) list | Too_many_arguments of bool * type_expr - | Abstract_wrong_label of arg_label * type_expr + | Abstract_wrong_label of Noloc.arg_label * type_expr | Scoping_let_module of string * type_expr | Not_a_variant_type of Longident.t | Incoherent_label_order @@ -740,7 +740,8 @@ let print_expr_type_clash ?type_clash_context env trace ppf = ~pp_sep:(fun ppf _ -> fprintf ppf ",@ ") (fun ppf (label, argtype) -> match label with - | Asttypes.Nolabel -> fprintf ppf "@[%a@]" Printtyp.type_expr argtype + | Asttypes.Noloc.Nolabel -> + fprintf ppf "@[%a@]" Printtyp.type_expr argtype | Labelled label -> fprintf ppf "@[(~%s: %a)@]" label Printtyp.type_expr argtype | Optional label -> @@ -1879,6 +1880,7 @@ and is_nonexpansive_opt = function let rec approx_type env sty = match sty.ptyp_desc with | Ptyp_arrow {lbl = p; ret = sty; arity} -> + let p = Asttypes.to_noloc p in let ty1 = if is_optional p then type_option (newvar ()) else newvar () in newty (Tarrow (p, ty1, approx_type env sty, Cok, arity)) | Ptyp_tuple args -> newty (Ttuple (List.map (approx_type env) args)) @@ -1897,6 +1899,7 @@ let rec type_approx env sexp = match sexp.pexp_desc with | Pexp_let (_, _, e) -> type_approx env e | Pexp_fun {arg_label = p; rhs = e; arity} -> + let p = Asttypes.to_noloc p in let ty = if is_optional p then type_option (newvar ()) else newvar () in newty (Tarrow (p, ty, type_approx env e, Cok, arity)) | Pexp_match (_, {pc_rhs = e} :: _) -> type_approx env e @@ -2235,9 +2238,9 @@ let not_function env ty = ls = [] && not tvar type lazy_args = - (Asttypes.arg_label * (unit -> Typedtree.expression) option) list + (Asttypes.Noloc.arg_label * (unit -> Typedtree.expression) option) list -type targs = (Asttypes.arg_label * Typedtree.expression option) list +type targs = (Asttypes.Noloc.arg_label * Typedtree.expression option) list let rec type_exp ?recarg env sexp = (* We now delegate everything to type_expect *) type_expect ?recarg env sexp (newvar ()) @@ -2362,6 +2365,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp arity; async; } -> + let l = Asttypes.to_noloc l in assert (is_optional l); (* default allowed only with optional argument *) let open Ast_helper in @@ -2404,6 +2408,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp [Exp.case pat body] | Pexp_fun {arg_label = l; default = None; lhs = spat; rhs = sbody; arity; async} -> + let l = Asttypes.to_noloc l in type_function ?in_function ~arity ~async loc sexp.pexp_attributes env ty_expected l [Ast_helper.Exp.case spat sbody] @@ -3391,7 +3396,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression) unify env lhs_type Predef.type_int; Predef.type_int in - let targs = [(lhs_label, Some lhs)] in + let targs = [(to_noloc lhs_label, Some lhs)] in Some (targs, result_type) | ( Some {form = Binary; specialization}, [(lhs_label, lhs_expr); (rhs_label, rhs_expr)] ) -> @@ -3449,7 +3454,9 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression) let rhs = type_expect env rhs_expr Predef.type_int in (lhs, rhs, Predef.type_int)) in - let targs = [(lhs_label, Some lhs); (rhs_label, Some rhs)] in + let targs = + [(to_noloc lhs_label, Some lhs); (to_noloc rhs_label, Some rhs)] + in Some (targs, result_type) | _ -> None) | _ -> None @@ -3540,9 +3547,9 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) : if List.length args < max_arity && total_app then match (expand_head env ty_fun).desc with | Tarrow (Optional l, t1, t2, _, _) -> - ignored := (Optional l, t1, ty_fun.level) :: !ignored; + ignored := (Noloc.Optional l, t1, ty_fun.level) :: !ignored; let arg = - ( Optional l, + ( Noloc.Optional l, Some (fun () -> option_none (instance env t1) Location.none) ) in type_unknown_args max_arity ~args:(arg :: args) ~top_arity:None @@ -3555,6 +3562,7 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) : (* foo(. ) treated as empty application if all args are optional (hence ignored) *) type_unknown_args max_arity ~args ~top_arity:None omitted ty_fun [] | (l1, sarg1) :: sargl -> + let l1 = to_noloc l1 in let ty1, ty2 = let ty_fun = expand_head env ty_fun in let arity_ok = List.length args < max_arity in @@ -3566,8 +3574,8 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) : unify env ty_fun (newty (Tarrow (l1, t1, t2, Clink (ref Cunknown), top_arity))); (t1, t2) - | Tarrow (l, t1, t2, _, _) when Asttypes.same_arg_label l l1 && arity_ok - -> + | Tarrow (l, t1, t2, _, _) + when Asttypes.Noloc.same_arg_label l l1 && arity_ok -> (t1, t2) | td -> ( let ty_fun = @@ -3620,13 +3628,13 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) : Some (fun () -> option_none (instance env ty) Location.none) )) else (sargs, (l, ty, lv) :: omitted, None) | Some (l', sarg0, sargs) -> - if (not optional) && is_optional l' then + if (not optional) && is_optional_loc l' then Location.prerr_warning sarg0.pexp_loc (Warnings.Nonoptional_label (Printtyp.string_of_label l)); ( sargs, omitted, Some - (if (not optional) || is_optional l' then fun () -> + (if (not optional) || is_optional_loc l' then fun () -> type_argument ?type_clash_context: (type_clash_context_for_function_argument @@ -4290,7 +4298,7 @@ let report_error env ppf error = "It is not a function.") | Apply_wrong_label (l, ty) -> let print_label ppf = function - | Nolabel -> fprintf ppf "without label" + | Noloc.Nolabel -> fprintf ppf "without label" | l -> fprintf ppf "with label %s" (prefixed_label_name l) in fprintf ppf @@ -4369,7 +4377,7 @@ let report_error env ppf error = fprintf ppf "the expected type is@ %a@]" type_expr ty) | Abstract_wrong_label (l, ty) -> let label_mark = function - | Nolabel -> "but its first argument is not labelled" + | Noloc.Nolabel -> "but its first argument is not labelled" | l -> sprintf "but its first argument is labelled %s" (prefixed_label_name l) in diff --git a/compiler/ml/typecore.mli b/compiler/ml/typecore.mli index 6d69191021..1a8bbed4c7 100644 --- a/compiler/ml/typecore.mli +++ b/compiler/ml/typecore.mli @@ -77,7 +77,7 @@ type error = (type_expr * type_expr) list * Error_message_utils.type_clash_context option | Apply_non_function of type_expr - | Apply_wrong_label of arg_label * type_expr + | Apply_wrong_label of Noloc.arg_label * type_expr | Label_multiply_defined of { label: string; jsx_component_info: Error_message_utils.jsx_prop_error_info option; @@ -95,7 +95,7 @@ type error = | Private_label of Longident.t * type_expr | Not_subtype of (type_expr * type_expr) list * (type_expr * type_expr) list | Too_many_arguments of bool * type_expr - | Abstract_wrong_label of arg_label * type_expr + | Abstract_wrong_label of Noloc.arg_label * type_expr | Scoping_let_module of string * type_expr | Not_a_variant_type of Longident.t | Incoherent_label_order diff --git a/compiler/ml/typedtree.ml b/compiler/ml/typedtree.ml index 3421de7041..626950caec 100644 --- a/compiler/ml/typedtree.ml +++ b/compiler/ml/typedtree.ml @@ -76,7 +76,7 @@ and expression_desc = | Texp_constant of constant | Texp_let of rec_flag * value_binding list * expression | Texp_function of { - arg_label: arg_label; + arg_label: Noloc.arg_label; arity: arity; param: Ident.t; case: case; @@ -85,7 +85,7 @@ and expression_desc = } | Texp_apply of { funct: expression; - args: (arg_label * expression option) list; + args: (Noloc.arg_label * expression option) list; partial: bool; } | Texp_match of expression * case list * case list * partial @@ -307,7 +307,7 @@ and core_type = { and core_type_desc = | Ttyp_any | Ttyp_var of string - | Ttyp_arrow of arg_label * core_type * core_type * arity + | Ttyp_arrow of Noloc.arg_label * core_type * core_type * arity | Ttyp_tuple of core_type list | Ttyp_constr of Path.t * Longident.t loc * core_type list | Ttyp_object of object_field list * closed_flag diff --git a/compiler/ml/typedtree.mli b/compiler/ml/typedtree.mli index b28f807aba..96da873af0 100644 --- a/compiler/ml/typedtree.mli +++ b/compiler/ml/typedtree.mli @@ -129,7 +129,7 @@ and expression_desc = let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive) *) | Texp_function of { - arg_label: arg_label; + arg_label: Noloc.arg_label; arity: arity; param: Ident.t; case: case; @@ -148,7 +148,7 @@ and expression_desc = *) | Texp_apply of { funct: expression; - args: (arg_label * expression option) list; + args: (Noloc.arg_label * expression option) list; partial: bool; } (** E0 ~l1:E1 ... ~ln:En @@ -413,7 +413,7 @@ and core_type = { and core_type_desc = | Ttyp_any | Ttyp_var of string - | Ttyp_arrow of arg_label * core_type * core_type * arity + | Ttyp_arrow of Noloc.arg_label * core_type * core_type * arity | Ttyp_tuple of core_type list | Ttyp_constr of Path.t * Longident.t loc * core_type list | Ttyp_object of object_field list * closed_flag diff --git a/compiler/ml/types.ml b/compiler/ml/types.ml index a7f74ec54e..d931fc1ec9 100644 --- a/compiler/ml/types.ml +++ b/compiler/ml/types.ml @@ -23,7 +23,7 @@ type type_expr = {mutable desc: type_desc; mutable level: int; id: int} and type_desc = | Tvar of string option - | Tarrow of arg_label * type_expr * type_expr * commutable * arity + | Tarrow of Noloc.arg_label * type_expr * type_expr * commutable * arity | Ttuple of type_expr list | Tconstr of Path.t * type_expr list * abbrev_memo ref | Tobject of type_expr * (Path.t * type_expr list) option ref diff --git a/compiler/ml/types.mli b/compiler/ml/types.mli index ce44a9e2ac..09f82c8d9e 100644 --- a/compiler/ml/types.mli +++ b/compiler/ml/types.mli @@ -61,7 +61,7 @@ and type_desc = | Tvar of string option (** [Tvar (Some "a")] ==> ['a] or ['_a] [Tvar None] ==> [_] *) - | Tarrow of arg_label * type_expr * type_expr * commutable * arity + | Tarrow of Noloc.arg_label * type_expr * type_expr * commutable * arity (** [Tarrow (Nolabel, e1, e2, c)] ==> [e1 -> e2] [Tarrow (Labelled "l", e1, e2, c)] ==> [l:e1 -> e2] [Tarrow (Optional "l", e1, e2, c)] ==> [?l:e1 -> e2] diff --git a/compiler/ml/typetexp.ml b/compiler/ml/typetexp.ml index 16117f64bc..786a89b994 100644 --- a/compiler/ml/typetexp.ml +++ b/compiler/ml/typetexp.ml @@ -328,6 +328,7 @@ and transl_type_aux env policy styp = in ctyp (Ttyp_var name) ty | Ptyp_arrow {lbl; arg = st1; ret = st2; arity} -> + let lbl = Asttypes.to_noloc lbl in let cty1 = transl_type env policy st1 in let cty2 = transl_type env policy st2 in let ty1 = cty1.ctyp_type in diff --git a/compiler/syntax/src/jsx_v4.ml b/compiler/syntax/src/jsx_v4.ml index cb5fc27470..fcf2272153 100644 --- a/compiler/syntax/src/jsx_v4.ml +++ b/compiler/syntax/src/jsx_v4.ml @@ -10,7 +10,7 @@ let module_access_name config value = let nolabel = Nolabel -let labelled str = Labelled str +let labelled str = Labelled {txt = str; loc = Location.none} let is_optional str = match str with @@ -28,7 +28,7 @@ let is_forward_ref = function let get_label str = match str with - | Optional str | Labelled str -> str + | Optional {txt = str} | Labelled {txt = str} -> str | Nolabel -> "" let constant_string ~loc str = @@ -198,8 +198,8 @@ let record_from_props ~loc ~remove_key call_arguments = | (Nolabel, {pexp_loc}, _) :: _rest -> Jsx_common.raise_error ~loc:pexp_loc "JSX: found non-labelled argument before the last position" - | ((Labelled txt, {pexp_loc}, _) as prop) :: rest - | ((Optional txt, {pexp_loc}, _) as prop) :: rest -> + | ((Labelled {txt}, {pexp_loc}, _) as prop) :: rest + | ((Optional {txt}, {pexp_loc}, _) as prop) :: rest -> if txt = spread_props_label then match acc with | [] -> remove_last_position_unit_aux rest (prop :: acc) @@ -212,7 +212,10 @@ let record_from_props ~loc ~remove_key call_arguments = let props, props_to_spread = remove_last_position_unit_aux call_arguments [] |> List.rev - |> List.partition (fun (label, _, _) -> label <> labelled "_spreadProps") + |> List.partition (fun (label, _, _) -> + match label with + | Labelled {txt = "_spreadProps"} -> false + | _ -> true) in let props = if remove_key then @@ -253,7 +256,11 @@ let make_props_type_params_tvar named_type_list = named_type_list |> List.filter_map (fun (_isOptional, label, _, loc, _interiorType) -> if label = "key" then None - else Some (Typ.var ~loc @@ safe_type_from_value (Labelled label))) + else + Some + (Typ.var ~loc + @@ safe_type_from_value + (Labelled {txt = label; loc = Location.none}))) let strip_option core_type = match core_type with @@ -322,10 +329,12 @@ let make_label_decls named_type_list = interior_type else if is_optional then Type.field ~loc ~attrs ~optional:true {txt = label; loc} - (Typ.var @@ safe_type_from_value @@ Labelled label) + (Typ.var @@ safe_type_from_value + @@ Labelled {txt = label; loc = Location.none}) else Type.field ~loc ~attrs {txt = label; loc} - (Typ.var @@ safe_type_from_value @@ Labelled label)) + (Typ.var @@ safe_type_from_value + @@ Labelled {txt = label; loc = Location.none})) let make_type_decls ~attrs props_name loc named_type_list = let label_decl_list = make_label_decls named_type_list in @@ -644,11 +653,11 @@ let transform_lowercase_call3 ~config mapper jsx_expr_loc call_expr_loc attrs let rec recursively_transform_named_args_for_make expr args newtypes core_type = match expr.pexp_desc with (* TODO: make this show up with a loc. *) - | Pexp_fun {arg_label = Labelled "key" | Optional "key"} -> + | Pexp_fun {arg_label = Labelled {txt = "key"} | Optional {txt = "key"}} -> Jsx_common.raise_error ~loc:expr.pexp_loc "Key cannot be accessed inside of a component. Don't worry - you can \ always key a component from its parent!" - | Pexp_fun {arg_label = Labelled "ref" | Optional "ref"} -> + | Pexp_fun {arg_label = Labelled {txt = "ref"} | Optional {txt = "ref"}} -> Jsx_common.raise_error ~loc:expr.pexp_loc "Ref cannot be passed as a normal prop. Please use `forwardRef` API \ instead." @@ -720,7 +729,13 @@ let rec recursively_transform_named_args_for_make expr args newtypes core_type = | _ -> None in (* The ref arguement of forwardRef should be optional *) - ( (Optional "ref", None, pattern, txt, pattern.ppat_loc, type_) :: args, + ( ( Optional {txt = "ref"; loc = Location.none}, + None, + pattern, + txt, + pattern.ppat_loc, + type_ ) + :: args, newtypes, core_type ) else (args, newtypes, core_type) @@ -994,12 +1009,12 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = (* let make = React.forwardRef({ let \"App" = (props, ref) => make({...props, ref: @optional (Js.Nullabel.toOption(ref))}) })*) - Exp.fun_ ~arity:None nolabel None + Exp.fun_ ~arity:None Nolabel None (match core_type_of_attr with | None -> make_props_pattern named_type_list | Some _ -> make_props_pattern typ_vars_of_core_type) (if has_forward_ref then - Exp.fun_ ~arity:None nolabel None + Exp.fun_ ~arity:None Nolabel None (Pat.var @@ Location.mknoloc "ref") inner_expression else inner_expression) diff --git a/compiler/syntax/src/res_ast_debugger.ml b/compiler/syntax/src/res_ast_debugger.ml index 767558b77b..a4d4f4a390 100644 --- a/compiler/syntax/src/res_ast_debugger.ml +++ b/compiler/syntax/src/res_ast_debugger.ml @@ -111,11 +111,11 @@ module SexpAst = struct | Contravariant -> Sexp.atom "Contravariant" | Invariant -> Sexp.atom "Invariant" - let arg_label lbl = + let arg_label_loc lbl = match lbl with | Asttypes.Nolabel -> Sexp.atom "Nolabel" - | Labelled txt -> Sexp.list [Sexp.atom "Labelled"; string txt] - | Optional txt -> Sexp.list [Sexp.atom "Optional"; string txt] + | Labelled {txt} -> Sexp.list [Sexp.atom "Labelled"; string txt] + | Optional {txt} -> Sexp.list [Sexp.atom "Optional"; string txt] let constant c = let sexpr = @@ -559,7 +559,7 @@ module SexpAst = struct Sexp.list [ Sexp.atom "Pexp_fun"; - arg_label arg_lbl; + arg_label_loc arg_lbl; (match expr_opt with | None -> Sexp.atom "None" | Some expr -> Sexp.list [Sexp.atom "Some"; expression expr]); @@ -574,7 +574,7 @@ module SexpAst = struct Sexp.list (map_empty ~f:(fun (arg_lbl, expr) -> - Sexp.list [arg_label arg_lbl; expression expr]) + Sexp.list [arg_label_loc arg_lbl; expression expr]) args); ] | Pexp_match (expr, cases) -> @@ -838,7 +838,12 @@ module SexpAst = struct | Ptyp_var var -> Sexp.list [Sexp.atom "Ptyp_var"; string var] | Ptyp_arrow {lbl; arg; ret} -> Sexp.list - [Sexp.atom "Ptyp_arrow"; arg_label lbl; core_type arg; core_type ret] + [ + Sexp.atom "Ptyp_arrow"; + arg_label_loc lbl; + core_type arg; + core_type ret; + ] | Ptyp_tuple types -> Sexp.list [Sexp.atom "Ptyp_tuple"; Sexp.list (map_empty ~f:core_type types)] diff --git a/compiler/syntax/src/res_comments_table.ml b/compiler/syntax/src/res_comments_table.ml index 3acd19966a..9e1e0f5bbd 100644 --- a/compiler/syntax/src/res_comments_table.ml +++ b/compiler/syntax/src/res_comments_table.ml @@ -335,7 +335,7 @@ let is_if_then_else_expr expr = type node = | Case of Parsetree.case | CoreType of Parsetree.core_type - | ExprArgument of Parsetree.expression + | ExprArgument of {expr: Parsetree.expression; loc: Location.t} | Expression of Parsetree.expression | ExprRecordRow of Longident.t Asttypes.loc * Parsetree.expression | ExtensionConstructor of Parsetree.extension_constructor @@ -365,11 +365,7 @@ let get_loc node = | Some ({loc}, _), _ -> loc.Location.loc_end); } | CoreType ct -> ct.ptyp_loc - | ExprArgument expr -> ( - match expr.Parsetree.pexp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _attrs -> - {loc with loc_end = expr.pexp_loc.loc_end} - | _ -> expr.pexp_loc) + | ExprArgument {loc} -> loc | Expression e -> ( match e.pexp_attributes with | ({txt = "res.braces" | "ns.braces"; loc}, _) :: _ -> loc @@ -558,7 +554,7 @@ and walk_node node tbl comments = match node with | Case c -> walk_case c tbl comments | CoreType ct -> walk_core_type ct tbl comments - | ExprArgument ea -> walk_expr_argument ea tbl comments + | ExprArgument ea -> walk_expr_argument ea.expr ea.loc tbl comments | Expression e -> walk_expression e tbl comments | ExprRecordRow (ri, e) -> walk_expr_record_row (ri, e) tbl comments | ExtensionConstructor ec -> walk_extension_constructor ec tbl comments @@ -1407,14 +1403,16 @@ and walk_expression expr t comments = arguments |> List.filter (fun (label, _) -> match label with - | Asttypes.Labelled "children" -> false + | Asttypes.Labelled {txt = "children"} -> false | Asttypes.Nolabel -> false | _ -> true) in let maybe_children = arguments |> List.find_opt (fun (label, _) -> - label = Asttypes.Labelled "children") + match label with + | Asttypes.Labelled {txt = "children"} -> true + | _ -> false) in match maybe_children with (* There is no need to deal with this situation as the children cannot be NONE *) @@ -1433,26 +1431,45 @@ and walk_expression expr t comments = in attach t.trailing call_expr.pexp_loc after_expr else - walk_list (props |> List.map (fun (_, e) -> ExprArgument e)) t leading; + walk_list + (props + |> List.map (fun (lbl, expr) -> + let loc = + match lbl with + | Asttypes.Labelled {loc} | Optional {loc} -> + {loc with loc_end = expr.Parsetree.pexp_loc.loc_end} + | _ -> expr.pexp_loc + in + ExprArgument {expr; loc})) + t leading; walk_expression children t inside) else let after_expr, rest = partition_adjacent_trailing call_expr.pexp_loc after in attach t.trailing call_expr.pexp_loc after_expr; - walk_list (arguments |> List.map (fun (_, e) -> ExprArgument e)) t rest + walk_list + (arguments + |> List.map (fun (lbl, expr) -> + let loc = + match lbl with + | Asttypes.Labelled {loc} | Optional {loc} -> + {loc with loc_end = expr.Parsetree.pexp_loc.loc_end} + | _ -> expr.pexp_loc + in + ExprArgument {expr; loc})) + t rest | Pexp_fun _ | Pexp_newtype _ -> ( let _, parameters, return_expr = fun_expr expr in let comments = visit_list_but_continue_with_remaining_comments ~newline_delimited:false - ~walk_node:walk_expr_pararameter - ~get_loc:(fun (_attrs, _argLbl, expr_opt, pattern) -> + ~walk_node:walk_expr_parameter + ~get_loc:(fun (_attrs, argLbl, expr_opt, pattern) -> + let label_loc = Asttypes.get_lbl_loc argLbl in let open Parsetree in let start_pos = - match pattern.ppat_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _attrs -> - loc.loc_start - | _ -> pattern.ppat_loc.loc_start + if label_loc <> Location.none then label_loc.loc_start + else pattern.ppat_loc.loc_start in match expr_opt with | None -> {pattern.ppat_loc with loc_start = start_pos} @@ -1493,7 +1510,7 @@ and walk_expression expr t comments = attach t.trailing return_expr.pexp_loc trailing) | _ -> () -and walk_expr_pararameter (_attrs, _argLbl, expr_opt, pattern) t comments = +and walk_expr_parameter (_attrs, _argLbl, expr_opt, pattern) t comments = let leading, inside, trailing = partition_by_loc comments pattern.ppat_loc in attach t.leading pattern.ppat_loc leading; walk_pattern pattern t inside; @@ -1511,22 +1528,15 @@ and walk_expr_pararameter (_attrs, _argLbl, expr_opt, pattern) t comments = attach t.trailing expr.pexp_loc trailing | None -> attach t.trailing pattern.ppat_loc trailing -and walk_expr_argument expr t comments = - match expr.Parsetree.pexp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _attrs -> - let leading, trailing = partition_leading_trailing comments loc in - attach t.leading loc leading; - let after_label, rest = partition_adjacent_trailing loc trailing in - attach t.trailing loc after_label; - let before, inside, after = partition_by_loc rest expr.pexp_loc in - attach t.leading expr.pexp_loc before; - walk_expression expr t inside; - attach t.trailing expr.pexp_loc after - | _ -> - let before, inside, after = partition_by_loc comments expr.pexp_loc in - attach t.leading expr.pexp_loc before; - walk_expression expr t inside; - attach t.trailing expr.pexp_loc after +and walk_expr_argument expr loc t comments = + let leading, trailing = partition_leading_trailing comments loc in + attach t.leading loc leading; + let after_label, rest = partition_adjacent_trailing loc trailing in + attach t.trailing loc after_label; + let before, inside, after = partition_by_loc rest expr.pexp_loc in + attach t.leading expr.pexp_loc before; + walk_expression expr t inside; + attach t.trailing expr.pexp_loc after and walk_case (case : Parsetree.case) t comments = let before, inside, after = partition_by_loc comments case.pc_lhs.ppat_loc in @@ -1935,11 +1945,11 @@ and walk_object_field field t comments = and walk_type_parameters type_parameters t comments = visit_list_but_continue_with_remaining_comments - ~get_loc:(fun (_, _, typexpr) -> - match typexpr.Parsetree.ptyp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _attrs -> - {loc with loc_end = typexpr.ptyp_loc.loc_end} - | _ -> typexpr.ptyp_loc) + ~get_loc:(fun (_, lbl, typexpr) -> + let lbl_loc = Asttypes.get_lbl_loc lbl in + if lbl_loc <> Location.none then + {lbl_loc with loc_end = typexpr.Parsetree.ptyp_loc.loc_end} + else typexpr.ptyp_loc) ~walk_node:walk_type_parameter ~newline_delimited:false type_parameters t comments diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 74c03c890a..4fdbc33f33 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -1647,21 +1647,18 @@ and parse_parameter p = let lidents = parse_lident_list p in Some (TypeParameter {attrs; locs = lidents; p_pos = start_pos})) else - let attrs, lbl, pat = + let attrs, lbl, lbl_loc, pat = match p.Parser.token with | Tilde -> ( Parser.next p; - let lbl_name, loc = parse_lident p in - let prop_loc_attr = - (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) - in + let lbl_name, lbl_loc = parse_lident p in match p.Parser.token with | Comma | Equal | Rparen -> let loc = mk_loc start_pos p.prev_end_pos in ( [], - Asttypes.Labelled lbl_name, - Ast_helper.Pat.var ~attrs:(prop_loc_attr :: attrs) ~loc - (Location.mkloc lbl_name loc) ) + Asttypes.Labelled {txt = lbl_name; loc = lbl_loc}, + lbl_loc, + Ast_helper.Pat.var ~attrs ~loc (Location.mkloc lbl_name loc) ) | Colon -> let lbl_end = p.prev_end_pos in Parser.next p; @@ -1670,31 +1667,30 @@ and parse_parameter p = let pat = let pat = Ast_helper.Pat.var ~loc (Location.mkloc lbl_name loc) in let loc = mk_loc start_pos p.prev_end_pos in - Ast_helper.Pat.constraint_ ~attrs:(prop_loc_attr :: attrs) ~loc - pat typ + Ast_helper.Pat.constraint_ ~attrs ~loc pat typ in - ([], Asttypes.Labelled lbl_name, pat) + ([], Asttypes.Labelled {txt = lbl_name; loc = lbl_loc}, lbl_loc, pat) | As -> Parser.next p; let pat = let pat = parse_constrained_pattern p in - { - pat with - ppat_attributes = (prop_loc_attr :: attrs) @ pat.ppat_attributes; - } + {pat with ppat_attributes = attrs @ pat.ppat_attributes} in - ([], Asttypes.Labelled lbl_name, pat) + ([], Asttypes.Labelled {txt = lbl_name; loc = lbl_loc}, lbl_loc, pat) | t -> Parser.err p (Diagnostics.unexpected t p.breadcrumbs); let loc = mk_loc start_pos p.prev_end_pos in ( [], - Asttypes.Labelled lbl_name, - Ast_helper.Pat.var ~attrs:(prop_loc_attr :: attrs) ~loc - (Location.mkloc lbl_name loc) )) + Asttypes.Labelled {txt = lbl_name; loc = lbl_loc}, + lbl_loc, + Ast_helper.Pat.var ~attrs ~loc (Location.mkloc lbl_name loc) )) | _ -> let pattern = parse_constrained_pattern p in let attrs = List.concat [pattern.ppat_attributes; attrs] in - ([], Asttypes.Nolabel, {pattern with ppat_attributes = attrs}) + ( [], + Asttypes.Nolabel, + Location.none, + {pattern with ppat_attributes = attrs} ) in match p.Parser.token with | Equal -> ( @@ -1711,7 +1707,7 @@ and parse_parameter p = Parser.err ~start_pos ~end_pos:p.prev_end_pos p (Diagnostics.message (ErrorMessages.missing_tilde_labeled_parameter lbl_name)); - Asttypes.Optional lbl_name + Asttypes.Optional {txt = lbl_name; loc = lbl_loc} | lbl -> lbl in match p.Parser.token with @@ -2677,7 +2673,7 @@ and parse_jsx_opening_or_self_closing_element ~start_pos p = [ jsx_props; [ - (Asttypes.Labelled "children", children); + (Asttypes.Labelled {txt = "children"; loc = Location.none}, children); ( Asttypes.Nolabel, Ast_helper.Exp.construct (Location.mknoloc (Longident.Lident "()")) @@ -2740,15 +2736,12 @@ and parse_jsx_prop p = | Question | Lident _ -> ( let optional = Parser.optional p Question in let name, loc = parse_lident p in - let prop_loc_attr = - (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) - in (* optional punning: *) if optional then Some - ( Asttypes.Optional name, - Ast_helper.Exp.ident ~attrs:[prop_loc_attr] ~loc - (Location.mkloc (Longident.Lident name) loc) ) + ( Asttypes.Optional {txt = name; loc}, + Ast_helper.Exp.ident ~loc (Location.mkloc (Longident.Lident name) loc) + ) else match p.Parser.token with | Equal -> @@ -2756,21 +2749,19 @@ and parse_jsx_prop p = (* no punning *) let optional = Parser.optional p Question in Scanner.pop_mode p.scanner Jsx; - let attr_expr = - let e = parse_primary_expr ~operand:(parse_atomic_expr p) p in - {e with pexp_attributes = prop_loc_attr :: e.pexp_attributes} - in + let attr_expr = parse_primary_expr ~operand:(parse_atomic_expr p) p in let label = - if optional then Asttypes.Optional name else Asttypes.Labelled name + if optional then Asttypes.Optional {txt = name; loc} + else Asttypes.Labelled {txt = name; loc} in Some (label, attr_expr) | _ -> let attr_expr = - Ast_helper.Exp.ident ~loc ~attrs:[prop_loc_attr] - (Location.mkloc (Longident.Lident name) loc) + Ast_helper.Exp.ident ~loc (Location.mkloc (Longident.Lident name) loc) in let label = - if optional then Asttypes.Optional name else Asttypes.Labelled name + if optional then Asttypes.Optional {txt = name; loc} + else Asttypes.Labelled {txt = name; loc} in Some (label, attr_expr)) (* {...props} *) @@ -2782,15 +2773,9 @@ and parse_jsx_prop p = Scanner.pop_mode p.scanner Jsx; Parser.next p; let loc = mk_loc p.Parser.start_pos p.prev_end_pos in - let prop_loc_attr = - (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) - in - let attr_expr = - let e = parse_primary_expr ~operand:(parse_expr p) p in - {e with pexp_attributes = prop_loc_attr :: e.pexp_attributes} - in + let attr_expr = parse_primary_expr ~operand:(parse_expr p) p in (* using label "spreadProps" to distinguish from others *) - let label = Asttypes.Labelled "_spreadProps" in + let label = Asttypes.Labelled {txt = "_spreadProps"; loc} in match p.Parser.token with | Rbrace -> Parser.next p; @@ -3006,7 +2991,7 @@ and parse_braced_or_record_expr p = [ { attrs = []; - p_label = Asttypes.Nolabel; + p_label = Nolabel; expr = None; pat = Ast_helper.Pat.var ~loc:ident.loc ident; p_pos = start_pos; @@ -3623,25 +3608,26 @@ and parse_argument2 p : argument option = Parser.next p; let end_pos = p.prev_end_pos in let loc = mk_loc start_pos end_pos in - let prop_loc_attr = - (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) - in + let named_arg_loc = loc in let ident_expr = - Ast_helper.Exp.ident ~attrs:[prop_loc_attr] ~loc - (Location.mkloc (Longident.Lident ident) loc) + Ast_helper.Exp.ident ~loc (Location.mkloc (Longident.Lident ident) loc) in match p.Parser.token with | Question -> Parser.next p; - Some {label = Optional ident; expr = ident_expr} + Some + { + label = Optional {txt = ident; loc = named_arg_loc}; + expr = ident_expr; + } | Equal -> Parser.next p; let label = match p.Parser.token with | Question -> Parser.next p; - Asttypes.Optional ident - | _ -> Labelled ident + Asttypes.Optional {txt = ident; loc = named_arg_loc} + | _ -> Asttypes.Labelled {txt = ident; loc = named_arg_loc} in let expr = match p.Parser.token with @@ -3650,20 +3636,22 @@ and parse_argument2 p : argument option = Parser.next p; Ast_helper.Exp.ident ~loc (Location.mkloc (Longident.Lident "_") loc) - | _ -> - let expr = parse_constrained_or_coerced_expr p in - {expr with pexp_attributes = prop_loc_attr :: expr.pexp_attributes} + | _ -> parse_constrained_or_coerced_expr p in Some {label; expr} | Colon -> Parser.next p; let typ = parse_typ_expr p in let loc = mk_loc start_pos p.prev_end_pos in - let expr = - Ast_helper.Exp.constraint_ ~attrs:[prop_loc_attr] ~loc ident_expr typ - in - Some {label = Labelled ident; expr} - | _ -> Some {label = Labelled ident; expr = ident_expr}) + let expr = Ast_helper.Exp.constraint_ ~loc ident_expr typ in + Some + {label = Asttypes.Labelled {txt = ident; loc = named_arg_loc}; expr} + | _ -> + Some + { + label = Asttypes.Labelled {txt = ident; loc = named_arg_loc}; + expr = ident_expr; + }) | t -> Parser.err p (Diagnostics.lident t); Some {label = Nolabel; expr = Recover.default_expr ()}) @@ -3979,7 +3967,7 @@ and parse_array_exp p = (Longident.Ldot (Longident.Ldot (Longident.Lident "Belt", "Array"), "concatMany")) loc)) - [(Asttypes.Nolabel, Ast_helper.Exp.array ~loc list_exprs)] + [(Nolabel, Ast_helper.Exp.array ~loc list_exprs)] (* TODO: check attributes in the case of poly type vars, * might be context dependend: parseFieldDeclaration (see ocaml) *) @@ -4006,8 +3994,7 @@ and parse_poly_type_expr p = let typ = Ast_helper.Typ.var ~loc:var.loc var.txt in let return_type = parse_typ_expr ~alias:false p in let loc = mk_loc typ.Parsetree.ptyp_loc.loc_start p.prev_end_pos in - Ast_helper.Typ.arrow ~loc ~arity:(Some 1) Asttypes.Nolabel typ - return_type + Ast_helper.Typ.arrow ~loc ~arity:(Some 1) Nolabel typ return_type | _ -> Ast_helper.Typ.var ~loc:var.loc var.txt) | _ -> assert false) | _ -> parse_typ_expr p @@ -4233,20 +4220,14 @@ and parse_type_parameter p = | Tilde -> ( Parser.next p; let name, loc = parse_lident p in - let lbl_loc_attr = - (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) - in Parser.expect ~grammar:Grammar.TypeExpression Colon p; - let typ = - let typ = parse_typ_expr p in - {typ with ptyp_attributes = lbl_loc_attr :: typ.ptyp_attributes} - in + let typ = parse_typ_expr p in match p.Parser.token with | Equal -> Parser.next p; Parser.expect Question p; - Some {attrs; label = Optional name; typ; start_pos} - | _ -> Some {attrs; label = Labelled name; typ; start_pos}) + Some {attrs; label = Optional {txt = name; loc}; typ; start_pos} + | _ -> Some {attrs; label = Labelled {txt = name; loc}; typ; start_pos}) | Lident _ -> ( let name, loc = parse_lident p in match p.token with @@ -4264,8 +4245,8 @@ and parse_type_parameter p = | Equal -> Parser.next p; Parser.expect Question p; - Some {attrs; label = Optional name; typ; start_pos} - | _ -> Some {attrs; label = Labelled name; typ; start_pos}) + Some {attrs; label = Optional {txt = name; loc}; typ; start_pos} + | _ -> Some {attrs; label = Labelled {txt = name; loc}; typ; start_pos}) | _ -> let constr = Location.mkloc (Longident.Lident name) loc in let args = parse_type_constructor_args ~constr_name:constr p in @@ -4310,22 +4291,16 @@ and parse_es6_arrow_type ~attrs p = match p.Parser.token with | Tilde -> Parser.next p; - let name, loc = parse_lident p in - let lbl_loc_attr = - (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) - in + let name, label_loc = parse_lident p in Parser.expect ~grammar:Grammar.TypeExpression Colon p; - let typ = - let typ = parse_typ_expr ~alias:false ~es6_arrow:false p in - {typ with ptyp_attributes = lbl_loc_attr :: typ.ptyp_attributes} - in + let typ = parse_typ_expr ~alias:false ~es6_arrow:false p in let arg = match p.Parser.token with | Equal -> Parser.next p; Parser.expect Question p; - Asttypes.Optional name - | _ -> Asttypes.Labelled name + Asttypes.Optional {txt = name; loc = label_loc} + | _ -> Asttypes.Labelled {txt = name; loc = label_loc} in Parser.expect EqualGreater p; let return_type = parse_typ_expr ~alias:false p in @@ -4419,7 +4394,7 @@ and parse_arrow_type_rest ~es6_arrow ~start_pos typ p = Parser.next p; let return_type = parse_typ_expr ~alias:false p in let loc = mk_loc start_pos p.prev_end_pos in - Ast_helper.Typ.arrow ~loc ~arity:(Some 1) Asttypes.Nolabel typ return_type + Ast_helper.Typ.arrow ~loc ~arity:(Some 1) Nolabel typ return_type | _ -> typ and parse_typ_expr_region p = @@ -5026,8 +5001,7 @@ and parse_type_equation_or_constr_decl p = let return_type = parse_typ_expr ~alias:false p in let loc = mk_loc uident_start_pos p.prev_end_pos in let arrow_type = - Ast_helper.Typ.arrow ~loc ~arity:(Some 1) Asttypes.Nolabel typ - return_type + Ast_helper.Typ.arrow ~loc ~arity:(Some 1) Nolabel typ return_type in let typ = parse_type_alias p arrow_type in (Some typ, Asttypes.Public, Parsetree.Ptype_abstract) diff --git a/compiler/syntax/src/res_parsetree_viewer.ml b/compiler/syntax/src/res_parsetree_viewer.ml index 565a42f6f8..e6b1ee02a6 100644 --- a/compiler/syntax/src/res_parsetree_viewer.ml +++ b/compiler/syntax/src/res_parsetree_viewer.ml @@ -196,10 +196,9 @@ let filter_parsing_attrs attrs = match attr with | ( { Location.txt = - ( "res.braces" | "ns.braces" | "res.iflet" | "res.namedArgLoc" - | "res.ternary" | "res.await" | "res.template" - | "res.taggedTemplate" | "res.patVariantSpread" - | "res.dictPattern" ); + ( "res.braces" | "ns.braces" | "res.iflet" | "res.ternary" + | "res.await" | "res.template" | "res.taggedTemplate" + | "res.patVariantSpread" | "res.dictPattern" ); }, _ ) -> false @@ -455,7 +454,7 @@ let collect_ternary_parts expr = let parameters_should_hug parameters = match parameters with - | [Parameter {attrs = []; lbl = Asttypes.Nolabel; default_expr = None; pat}] + | [Parameter {attrs = []; lbl = Nolabel; default_expr = None; pat}] when is_huggable_pattern pat -> true | _ -> false diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 1f48309c24..0b887d74fd 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -1937,23 +1937,17 @@ and print_type_parameter ~state (attrs, lbl, typ) cmt_tbl = let label = match lbl with | Asttypes.Nolabel -> Doc.nil - | Labelled lbl -> + | Labelled {txt = lbl} -> Doc.concat [Doc.text "~"; print_ident_like lbl; Doc.text ": "] - | Optional lbl -> + | Optional {txt = lbl} -> Doc.concat [Doc.text "~"; print_ident_like lbl; Doc.text ": "] in let optional_indicator = match lbl with - | Asttypes.Nolabel | Labelled _ -> Doc.nil - | Optional _lbl -> Doc.text "=?" - in - let loc, typ = - match typ.ptyp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: attrs -> - ( {loc with loc_end = typ.ptyp_loc.loc_end}, - {typ with ptyp_attributes = attrs} ) - | _ -> (typ.ptyp_loc, typ) + | Nolabel | Labelled _ -> Doc.nil + | Optional _ -> Doc.text "=?" in + let loc = {(Asttypes.get_lbl_loc lbl) with loc_end = typ.ptyp_loc.loc_end} in let doc = Doc.group (Doc.concat @@ -4257,7 +4251,7 @@ and print_pexp_apply ~state expr cmt_tbl = let args = if partial then let dummy = Ast_helper.Exp.constant ~attrs (Ast_helper.Const.int 0) in - args @ [(Asttypes.Labelled "...", dummy)] + args @ [(Asttypes.Labelled {txt = "..."; loc = Location.none}, dummy)] else args in let call_expr_doc = @@ -4509,7 +4503,7 @@ and print_jsx_props ~state args cmt_tbl : Doc.t * Parsetree.expression option = match args with | [] -> (Doc.nil, None) | [ - (Asttypes.Labelled "children", children); + (Asttypes.Labelled {txt = "children"}, children); ( Asttypes.Nolabel, { Parsetree.pexp_desc = @@ -4518,9 +4512,9 @@ and print_jsx_props ~state args cmt_tbl : Doc.t * Parsetree.expression option = ] -> let doc = if is_self_closing children then Doc.line else Doc.nil in (doc, Some children) - | ((_, expr) as last_prop) + | ((e_lbl, expr) as last_prop) :: [ - (Asttypes.Labelled "children", children); + (Asttypes.Labelled {txt = "children"}, children); ( Asttypes.Nolabel, { Parsetree.pexp_desc = @@ -4528,10 +4522,10 @@ and print_jsx_props ~state args cmt_tbl : Doc.t * Parsetree.expression option = } ); ] -> let loc = - match expr.Parsetree.pexp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _attrs -> + match e_lbl with + | Asttypes.Labelled {loc} | Asttypes.Optional {loc} -> {loc with loc_end = expr.pexp_loc.loc_end} - | _ -> expr.pexp_loc + | Nolabel -> expr.pexp_loc in let trailing_comments_present = has_trailing_comments cmt_tbl loc in let prop_doc = print_jsx_prop ~state last_prop cmt_tbl in @@ -4562,20 +4556,19 @@ and print_jsx_props ~state args cmt_tbl : Doc.t * Parsetree.expression option = and print_jsx_prop ~state arg cmt_tbl = match arg with - | ( ((Asttypes.Labelled lbl_txt | Optional lbl_txt) as lbl), + | ( ((Asttypes.Labelled {txt = lbl_txt} | Optional {txt = lbl_txt}) as lbl), { - Parsetree.pexp_attributes = - [({Location.txt = "res.namedArgLoc"; loc = arg_loc}, _)]; + pexp_attributes = []; pexp_desc = Pexp_ident {txt = Longident.Lident ident}; } ) when lbl_txt = ident (* jsx punning *) -> ( match lbl with | Nolabel -> Doc.nil - | Labelled _lbl -> print_comments (print_ident_like ident) cmt_tbl arg_loc - | Optional _lbl -> + | Labelled {loc} -> print_comments (print_ident_like ident) cmt_tbl loc + | Optional {loc} -> let doc = Doc.concat [Doc.question; print_ident_like ident] in - print_comments doc cmt_tbl arg_loc) - | ( ((Asttypes.Labelled lbl_txt | Optional lbl_txt) as lbl), + print_comments doc cmt_tbl loc) + | ( ((Asttypes.Labelled {txt = lbl_txt} | Optional {txt = lbl_txt}) as lbl), { Parsetree.pexp_attributes = []; pexp_desc = Pexp_ident {txt = Longident.Lident ident}; @@ -4585,25 +4578,19 @@ and print_jsx_prop ~state arg cmt_tbl = | Nolabel -> Doc.nil | Labelled _lbl -> print_ident_like ident | Optional _lbl -> Doc.concat [Doc.question; print_ident_like ident]) - | Asttypes.Labelled "_spreadProps", expr -> + | Asttypes.Labelled {txt = "_spreadProps"}, expr -> let doc = print_expression_with_comments ~state expr cmt_tbl in Doc.concat [Doc.lbrace; Doc.dotdotdot; doc; Doc.rbrace] | lbl, expr -> - let arg_loc, expr = - match expr.pexp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: attrs -> - (loc, {expr with pexp_attributes = attrs}) - | _ -> (Location.none, expr) - in - let lbl_doc = + let arg_loc, lbl_doc = match lbl with - | Asttypes.Labelled lbl -> - let lbl = print_comments (print_ident_like lbl) cmt_tbl arg_loc in - Doc.concat [lbl; Doc.equal] - | Asttypes.Optional lbl -> - let lbl = print_comments (print_ident_like lbl) cmt_tbl arg_loc in - Doc.concat [lbl; Doc.equal; Doc.question] - | Nolabel -> Doc.nil + | Asttypes.Labelled {txt = lbl; loc} -> + let lbl = print_comments (print_ident_like lbl) cmt_tbl loc in + (loc, Doc.concat [lbl; Doc.equal]) + | Asttypes.Optional {txt = lbl; loc} -> + let lbl = print_comments (print_ident_like lbl) cmt_tbl loc in + (loc, Doc.concat [lbl; Doc.equal; Doc.question]) + | Nolabel -> (Location.none, Doc.nil) in let expr_doc = let leading_line_comment_present = @@ -4654,9 +4641,9 @@ and print_arguments_with_callback_in_first_position ~state ~partial args cmt_tbl let lbl_doc = match lbl with | Asttypes.Nolabel -> Doc.nil - | Asttypes.Labelled txt -> + | Asttypes.Labelled {txt} -> Doc.concat [Doc.tilde; print_ident_like txt; Doc.equal] - | Asttypes.Optional txt -> + | Asttypes.Optional {txt} -> Doc.concat [Doc.tilde; print_ident_like txt; Doc.equal; Doc.question] in let callback = @@ -4742,9 +4729,9 @@ and print_arguments_with_callback_in_last_position ~state ~partial args cmt_tbl let lbl_doc = match lbl with | Asttypes.Nolabel -> Doc.nil - | Asttypes.Labelled txt -> + | Asttypes.Labelled {txt} -> Doc.concat [Doc.tilde; print_ident_like txt; Doc.equal] - | Asttypes.Optional txt -> + | Asttypes.Optional {txt} -> Doc.concat [Doc.tilde; print_ident_like txt; Doc.equal; Doc.question] in let callback_fits_on_one_line = @@ -4897,37 +4884,26 @@ and print_arguments ~state ~partial and print_argument ~state (arg_lbl, arg) cmt_tbl = match (arg_lbl, arg) with (* ~a (punned)*) - | ( Labelled lbl, - ({ - pexp_desc = Pexp_ident {txt = Longident.Lident name}; - pexp_attributes = [] | [({Location.txt = "res.namedArgLoc"}, _)]; - } as arg_expr) ) - when lbl = name && not (ParsetreeViewer.is_braced_expr arg_expr) -> - let loc = - match arg.pexp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _ -> loc - | _ -> arg.pexp_loc - in + | ( Labelled {txt = lbl; loc = l0}, + { + pexp_attributes = []; + pexp_desc = Pexp_ident {txt = Longident.Lident name}; + } ) + when lbl = name && not (ParsetreeViewer.is_braced_expr arg) -> + let loc = {l0 with loc_end = arg.pexp_loc.loc_end} in let doc = Doc.concat [Doc.tilde; print_ident_like lbl] in print_comments doc cmt_tbl loc (* ~a: int (punned)*) - | ( Labelled lbl, + | ( Labelled {txt = lbl; loc = l0}, { pexp_desc = Pexp_constraint ( ({pexp_desc = Pexp_ident {txt = Longident.Lident name}} as arg_expr), typ ); - pexp_loc; - pexp_attributes = - ([] | [({Location.txt = "res.namedArgLoc"}, _)]) as attrs; + pexp_attributes = []; } ) when lbl = name && not (ParsetreeViewer.is_braced_expr arg_expr) -> - let loc = - match attrs with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _ -> - {loc with loc_end = pexp_loc.loc_end} - | _ -> arg.pexp_loc - in + let loc = {l0 with loc_end = arg.pexp_loc.loc_end} in let doc = Doc.concat [ @@ -4939,40 +4915,32 @@ and print_argument ~state (arg_lbl, arg) cmt_tbl = in print_comments doc cmt_tbl loc (* ~a? (optional lbl punned)*) - | ( Optional lbl, + | ( Optional {txt = lbl; loc}, { pexp_desc = Pexp_ident {txt = Longident.Lident name}; - pexp_attributes = [] | [({Location.txt = "res.namedArgLoc"}, _)]; + pexp_attributes = []; } ) when lbl = name -> - let loc = - match arg.pexp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _ -> loc - | _ -> arg.pexp_loc - in let doc = Doc.concat [Doc.tilde; print_ident_like lbl; Doc.question] in print_comments doc cmt_tbl loc | _lbl, expr -> - let arg_loc, expr = - match expr.pexp_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: attrs -> - (loc, {expr with pexp_attributes = attrs}) - | _ -> (expr.pexp_loc, expr) - in - let printed_lbl, dotdotdot = + let arg_loc, printed_lbl, dotdotdot = match arg_lbl with - | Nolabel -> (Doc.nil, false) - | Labelled "..." -> + | Nolabel -> (expr.pexp_loc, Doc.nil, false) + | Labelled {txt = "..."; loc} -> + let arg_loc = loc in let doc = Doc.text "..." in - (print_comments doc cmt_tbl arg_loc, true) - | Labelled lbl -> + (loc, print_comments doc cmt_tbl arg_loc, true) + | Labelled {txt = lbl; loc} -> + let arg_loc = loc in let doc = Doc.concat [Doc.tilde; print_ident_like lbl; Doc.equal] in - (print_comments doc cmt_tbl arg_loc, false) - | Optional lbl -> + (loc, print_comments doc cmt_tbl arg_loc, false) + | Optional {txt = lbl; loc} -> + let arg_loc = loc in let doc = Doc.concat [Doc.tilde; print_ident_like lbl; Doc.equal; Doc.question] in - (print_comments doc cmt_tbl arg_loc, false) + (loc, print_comments doc cmt_tbl arg_loc, false) in let printed_expr = let doc = print_expression_with_comments ~state expr cmt_tbl in @@ -5077,7 +5045,7 @@ and print_expr_fun_parameters ~state ~in_callback ~async ~has_constraint ParsetreeViewer.Parameter { attrs = []; - lbl = Asttypes.Nolabel; + lbl = Nolabel; default_expr = None; pat = {Parsetree.ppat_desc = Ppat_any; ppat_loc}; }; @@ -5092,7 +5060,7 @@ and print_expr_fun_parameters ~state ~in_callback ~async ~has_constraint ParsetreeViewer.Parameter { attrs = []; - lbl = Asttypes.Nolabel; + lbl = Nolabel; default_expr = None; pat = { @@ -5118,7 +5086,7 @@ and print_expr_fun_parameters ~state ~in_callback ~async ~has_constraint ParsetreeViewer.Parameter { attrs = []; - lbl = Asttypes.Nolabel; + lbl = Nolabel; default_expr = None; pat = {ppat_desc = Ppat_construct ({txt = Longident.Lident "()"; loc}, None)}; @@ -5198,8 +5166,8 @@ and print_exp_fun_parameter ~state parameter cmt_tbl = * ~from -> punning *) let label_with_pattern = match (lbl, pattern) with - | Asttypes.Nolabel, pattern -> print_pattern ~state pattern cmt_tbl - | ( (Asttypes.Labelled lbl | Optional lbl), + | Nolabel, pattern -> print_pattern ~state pattern cmt_tbl + | ( (Labelled {txt = lbl} | Optional {txt = lbl}), {ppat_desc = Ppat_var string_loc; ppat_attributes} ) when lbl = string_loc.txt -> (* ~d *) @@ -5209,7 +5177,7 @@ and print_exp_fun_parameter ~state parameter cmt_tbl = Doc.text "~"; print_ident_like lbl; ] - | ( (Asttypes.Labelled lbl | Optional lbl), + | ( (Labelled {txt = lbl} | Optional {txt = lbl}), { ppat_desc = Ppat_constraint ({ppat_desc = Ppat_var {txt}}, typ); ppat_attributes; @@ -5224,7 +5192,7 @@ and print_exp_fun_parameter ~state parameter cmt_tbl = Doc.text ": "; print_typ_expr ~state typ cmt_tbl; ] - | (Asttypes.Labelled lbl | Optional lbl), pattern -> + | (Labelled {txt = lbl} | Optional {txt = lbl}), pattern -> (* ~b as c *) Doc.concat [ @@ -5236,7 +5204,7 @@ and print_exp_fun_parameter ~state parameter cmt_tbl = in let optional_label_suffix = match (lbl, default_expr) with - | Asttypes.Optional _, None -> Doc.text "=?" + | Optional _, None -> Doc.text "=?" | _ -> Doc.nil in let doc = @@ -5244,24 +5212,11 @@ and print_exp_fun_parameter ~state parameter cmt_tbl = (Doc.concat [attrs; label_with_pattern; default_expr_doc; optional_label_suffix]) in + let lbl_loc = Asttypes.get_lbl_loc lbl in let cmt_loc = match default_expr with - | None -> ( - match pattern.ppat_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _ -> - {loc with loc_end = pattern.ppat_loc.loc_end} - | _ -> pattern.ppat_loc) - | Some expr -> - let start_pos = - match pattern.ppat_attributes with - | ({Location.txt = "res.namedArgLoc"; loc}, _) :: _ -> loc.loc_start - | _ -> pattern.ppat_loc.loc_start - in - { - pattern.ppat_loc with - loc_start = start_pos; - loc_end = expr.pexp_loc.loc_end; - } + | None -> {lbl_loc with loc_end = pattern.ppat_loc.loc_end} + | Some expr -> {lbl_loc with loc_end = expr.pexp_loc.loc_end} in print_comments doc cmt_tbl cmt_loc diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt index 6fdd1ca056..73aacb2109 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt @@ -63,8 +63,7 @@ Looks like there might be an expression missing here -let findThreadByIdLinearScan [arity:2]~threads:((threads)[@res.namedArgLoc ]) - ~id:((id)[@res.namedArgLoc ]) = +let findThreadByIdLinearScan [arity:2]~threads ~id = ((Js.Array2.findi ThreadsModel.threads (fun [arity:2]thread -> fun i -> diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/jsx.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/jsx.res.txt index c384682f15..2853150fe2 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/jsx.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/jsx.res.txt @@ -65,6 +65,4 @@ let x = ([%rescript.exprhole ]) let x = ((Foo.bar.createElement ~children:[] ())[@JSX ]) > ([%rescript.exprhole ]) -let x = - ((Foo.bar.createElement ~baz:((baz)[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) \ No newline at end of file +let x = ((Foo.bar.createElement ~baz ~children:[] ())[@JSX ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt b/tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt index 06b15e81f8..6e402ab12a 100644 --- a/tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt +++ b/tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt @@ -32,6 +32,5 @@ A labeled parameter starts with a `~`. Did you mean: `~x`? let f [arity:3]x ?(y= 2) z = (x + y) + z -let g [arity:3]~x:((x)[@res.namedArgLoc ]) ?y:(((y)[@res.namedArgLoc ])= 2) - ~z:((z)[@res.namedArgLoc ]) = (x + y) + z +let g [arity:3]~x ?(y= 2) ~z = (x + y) + z type nonrec f = x:int -> y:int -> int (a:2) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/other/expected/regionMissingComma.res.txt b/tests/syntax_tests/data/parsing/errors/other/expected/regionMissingComma.res.txt index 8cc3ca5763..1a1827c3e7 100644 --- a/tests/syntax_tests/data/parsing/errors/other/expected/regionMissingComma.res.txt +++ b/tests/syntax_tests/data/parsing/errors/other/expected/regionMissingComma.res.txt @@ -23,8 +23,7 @@ Did you forget a `,` here? external make : - ?style:((ReactDOMRe.Style.t)[@res.namedArgLoc ]) -> - ?image:((bool)[@res.namedArgLoc ]) -> React.element (a:2) = + ?style:ReactDOMRe.Style.t -> ?image:bool -> React.element (a:2) = "ModalContent" type nonrec 'extraInfo student = { diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt index bd44146f4f..58a09da053 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt @@ -35,6 +35,6 @@ module ClientSet = (b -> Client.getUniqueId)) [@res.braces ]) end) - let empty = Belt.Set.make ~id:(((module T))[@res.namedArgLoc ]) + let empty = Belt.Set.make ~id:(module T) end ;;Js.log {js|test|js} \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/typexpr/expected/arrow.res.txt b/tests/syntax_tests/data/parsing/errors/typexpr/expected/arrow.res.txt index 4a76a16f95..c621d68f7f 100644 --- a/tests/syntax_tests/data/parsing/errors/typexpr/expected/arrow.res.txt +++ b/tests/syntax_tests/data/parsing/errors/typexpr/expected/arrow.res.txt @@ -39,16 +39,12 @@ module Error2 = type nonrec observation = { observed: int ; - onStep: - currentValue:((unit)[@res.namedArgLoc ]) -> - [%rescript.typehole ] (a:1) - } + onStep: currentValue:unit -> [%rescript.typehole ] (a:1) } end module Error3 = struct type nonrec observation = { observed: int ; - onStep: - currentValue:((unit)[@res.namedArgLoc ]) -> [%rescript.typehole ] } + onStep: currentValue:unit -> [%rescript.typehole ] } end \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/typexpr/expected/garbage.res.txt b/tests/syntax_tests/data/parsing/errors/typexpr/expected/garbage.res.txt index bce429c7f3..f1bc816958 100644 --- a/tests/syntax_tests/data/parsing/errors/typexpr/expected/garbage.res.txt +++ b/tests/syntax_tests/data/parsing/errors/typexpr/expected/garbage.res.txt @@ -8,6 +8,5 @@ I'm not sure what to parse here when looking at "?". -external printName : - name:((unit)[@res.namedArgLoc ]) -> unit (a:1) = "printName"[@@module - {js|moduleName|js}] \ No newline at end of file +external printName : name:unit -> unit (a:1) = "printName"[@@module + {js|moduleName|js}] \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt index ffe47af868..106a05e81e 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt @@ -5,5 +5,5 @@ ;;List.map (fun [arity:1]x -> x + 1) myList ;;List.reduce (fun [arity:2]acc -> fun curr -> acc + curr) 0 myList let unitUncurried = apply () -;;call ~a:(((((a)[@res.namedArgLoc ]) : int))[@res.namedArgLoc ]) +;;call ~a:(a : int) ;;call_partial 3 ... \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/argument.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/argument.res.txt index 3b1fe1a857..fcd6932823 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/argument.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/argument.res.txt @@ -1,11 +1,9 @@ -let foo [arity:1]~a:((a)[@res.namedArgLoc ]) = (a ()) +. 1. +let foo [arity:1]~a = (a ()) +. 1. let a [arity:1]() = 2 -let bar = foo ~a:((a)[@res.namedArgLoc ]) -let comparisonResult = - compare currentNode.value ~targetValue:((targetValue)[@res.namedArgLoc ]) -;;callback firstNode ~y:((y)[@res.namedArgLoc ]) +let bar = foo ~a +let comparisonResult = compare currentNode.value ~targetValue +;;callback firstNode ~y ;;document.createElementWithOptions {js|div|js} - (elementProps ~onClick:((fun [arity:1]_ -> Js.log {js|hello world|js}) - [@res.namedArgLoc ])) + (elementProps ~onClick:(fun [arity:1]_ -> Js.log {js|hello world|js})) ;;resolve () ;;resolve () \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt index 6c16e83722..8bb00c53d3 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt @@ -20,24 +20,17 @@ let f [arity:2]exception Terminate exception Exit = () let f [arity:1][] = () let f [arity:1](x::xs) = x + (xs -> Belt.List.length) let f [arity:2](x : int) (y : int) = x + y -let f [arity:2]~a:((a)[@res.namedArgLoc ]) ~b:((b)[@res.namedArgLoc ]) = - a + b -let f [arity:2]~a:((x)[@res.namedArgLoc ]) ~b:((y)[@res.namedArgLoc ]) = - x + y -let f [arity:2]~a:(((x : int))[@res.namedArgLoc ]) - ~b:(((y : int))[@res.namedArgLoc ]) = x + y -let f [arity:3]?a:(((a)[@res.namedArgLoc ])= 1) - ?b:(((b)[@res.namedArgLoc ])= 2) c = (a + b) + c -let f [arity:3]?a:(((x)[@res.namedArgLoc ])= 1) - ?b:(((y)[@res.namedArgLoc ])= 2) c = (x + y) + c -let f [arity:3]?a:((((x : int))[@res.namedArgLoc ])= 1) - ?b:((((y : int))[@res.namedArgLoc ])= 2) c = (x + y) + c -let f [arity:3]?a:((a)[@res.namedArgLoc ]) ?b:((b)[@res.namedArgLoc ]) c = +let f [arity:2]~a ~b = a + b +let f [arity:2]~a:x ~b:y = x + y +let f [arity:2]~a:(x : int) ~b:(y : int) = x + y +let f [arity:3]?(a= 1) ?(b= 2) c = (a + b) + c +let f [arity:3]?a:(x= 1) ?b:(y= 2) c = (x + y) + c +let f [arity:3]?a:((x : int)= 1) ?b:((y : int)= 2) c = (x + y) + c +let f [arity:3]?a ?b c = match (a, b) with | (Some a, Some b) -> (a + b) + c | _ -> 3 -let f [arity:3]?a:((x)[@res.namedArgLoc ]) ?b:((y)[@res.namedArgLoc ]) c = +let f [arity:3]?a:x ?b:y c = match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3 -let f [arity:3]?a:(((x : int option))[@res.namedArgLoc ]) - ?b:(((y : int option))[@res.namedArgLoc ]) c = +let f [arity:3]?a:(x : int option) ?b:(y : int option) c = match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3 let f [arity:2]a b = a + b let f [arity:1]() = () @@ -45,10 +38,9 @@ let f [arity:1]() = () let f [arity:3]a b c = () let f [arity:4]a b c d = () let f [arity:3]a b c = () -let f [arity:4]~a:((a)[@res.namedArgLoc ][@attr ]) b - ~c:((c)[@res.namedArgLoc ][@attr ]) d = () -let f [arity:4]~a:((a)[@res.namedArgLoc ][@attr ]) ((b)[@attrOnB ]) - ~c:((c)[@res.namedArgLoc ][@attr ]) ((d)[@attrOnD ]) = () +let f [arity:4]~a:((a)[@attr ]) b ~c:((c)[@attr ]) d = () +let f [arity:4]~a:((a)[@attr ]) ((b)[@attrOnB ]) ~c:((c)[@attr ]) + ((d)[@attrOnD ]) = () let f [arity:1]list = list () ;;match colour with | Red when diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt index cdffed3d8f..ed3e620e20 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt @@ -21,11 +21,11 @@ let f = then async fun [arity:2]a -> fun b -> (a + b : int) else (async fun [arity:2]c -> fun d -> (c - d : int))) [@res.ternary ]) -let foo = async ~a:((34)[@res.namedArgLoc ]) -let bar async [arity:1]~a:((a)[@res.namedArgLoc ]) = a + 1 +let foo = async ~a:34 +let bar async [arity:1]~a = a + 1 let ex1 = ((3)[@res.await ]) + ((4)[@res.await ]) let ex2 = ((3)[@res.await ]) ** ((4)[@res.await ]) -let ex3 = ((foo -> (bar ~arg:((arg)[@res.namedArgLoc ])))[@res.await ]) +let ex3 = ((foo -> (bar ~arg))[@res.await ]) let ex4 = (((foo.bar).baz)[@res.await ]) let attr1 = ((async fun [arity:1]x -> x + 1)[@a ]) let attr2 = ((fun (type a) -> diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt index b510458769..71c6ce2066 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt @@ -29,6 +29,5 @@ ({ startTime = (percent *. duration) } : Video.chapter) in { a; b } -> onChange | _ -> ()) - [@res.braces ]))[@res.namedArgLoc ][@res.braces ]) - ~children:[] ())[@JSX ]) + [@res.braces ]))[@res.braces ]) ~children:[] ())[@JSX ]) ;;if inclusions.(index) <- (uid, url) then onChange inclusions \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt index 2e7a5a90ed..b1a932b369 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt @@ -33,13 +33,11 @@ let unique_instance = build_instance (module Unique) 0 let build_dispatch_table [arity:1]handlers = ((let table = Hashtbl.create (module String) in List.iter handlers - ~f:((fun - [arity:1](((module I) : (module Query_handler_instance)) as - instance) - -> - Hashtbl.set table ~key:((I.Query_handler.name) - [@res.namedArgLoc ]) ~data:((instance)[@res.namedArgLoc ])) - [@res.namedArgLoc ]) table) + ~f:(fun + [arity:1](((module I) : (module Query_handler_instance)) as + instance) + -> Hashtbl.set table ~key:I.Query_handler.name ~data:instance) + table) [@res.braces ]) ;;(module Three) ;;((module Three) : (module X_int)) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt index b419ba2906..7a853a944a 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt @@ -1,29 +1,23 @@ let _ = ((div ~children:[] ())[@JSX ]) let _ = ((div ~children:[] ())[@JSX ]) -let _ = ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) -let _ = ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) -let _ = ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) -let _ = ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) +let _ = ((div ~className:{js|menu|js} ~children:[] ())[@JSX ]) +let _ = ((div ~className:{js|menu|js} ~children:[] ())[@JSX ]) +let _ = ((div ~className:{js|menu|js} ~children:[] ())[@JSX ]) +let _ = ((div ~className:{js|menu|js} ~children:[] ())[@JSX ]) let _ = - ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~onClick:((fun [arity:1]_ -> Js.log {js|click|js}) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ((div ~className:{js|menu|js} + ~onClick:((fun [arity:1]_ -> Js.log {js|click|js})[@res.braces ]) + ~children:[] ()) [@JSX ]) let _ = - ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~onClick:((fun [arity:1]_ -> Js.log {js|click|js}) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ((div ~className:{js|menu|js} + ~onClick:((fun [arity:1]_ -> Js.log {js|click|js})[@res.braces ]) + ~children:[] ()) [@JSX ]) let _ = ((Navbar.createElement ~children:[] ())[@JSX ]) let _ = ((Navbar.createElement ~children:[] ())[@JSX ]) let _ = ((Navbar.createElement ~children:[] ())[@JSX ]) -let _ = - ((Navbar.createElement ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~children:[] ()) +let _ = ((Navbar.createElement ~className:{js|menu|js} ~children:[] ()) [@JSX ]) let _ = ((Dot.Up.createElement ~children:[] ())[@JSX ]) let _ = ((Dot.Up.createElement ~children:[] ())[@JSX ]) @@ -36,9 +30,7 @@ let _ = ((Dot.Up.createElement ~children:[((Dot.Up.createElement ~children:[] ())[@JSX ])] ()) [@JSX ]) -let _ = - ((Dot.Up.createElement ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~children:[] ()) +let _ = ((Dot.Up.createElement ~className:{js|menu|js} ~children:[] ()) [@JSX ]) let _ = ((Dot.low.createElement ~children:[] ())[@JSX ]) let _ = ((Dot.low.createElement ~children:[] ())[@JSX ]) @@ -51,34 +43,28 @@ let _ = ((Dot.low.createElement ~children:[((Dot.low.createElement ~children:[] ())[@JSX ])] ()) [@JSX ]) -let _ = - ((Dot.low.createElement ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~children:[] ()) +let _ = ((Dot.low.createElement ~className:{js|menu|js} ~children:[] ()) [@JSX ]) -let _ = ((el ~punned:((punned)[@res.namedArgLoc ]) ~children:[] ())[@JSX ]) -let _ = ((el ?punned:((punned)[@res.namedArgLoc ]) ~children:[] ())[@JSX ]) -let _ = ((el ~punned:((punned)[@res.namedArgLoc ]) ~children:[] ())[@JSX ]) -let _ = ((el ?punned:((punned)[@res.namedArgLoc ]) ~children:[] ())[@JSX ]) -let _ = ((el ?a:((b)[@res.namedArgLoc ]) ~children:[] ())[@JSX ]) -let _ = ((el ?a:((b)[@res.namedArgLoc ]) ~children:[] ())[@JSX ]) +let _ = ((el ~punned ~children:[] ())[@JSX ]) +let _ = ((el ?punned ~children:[] ())[@JSX ]) +let _ = ((el ~punned ~children:[] ())[@JSX ]) +let _ = ((el ?punned ~children:[] ())[@JSX ]) +let _ = ((el ?a:b ~children:[] ())[@JSX ]) +let _ = ((el ?a:b ~children:[] ())[@JSX ]) let _ = (([])[@JSX ]) let _ = (([])[@JSX ]) let _ = - ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~children:[((div ~className:(({js|submenu|js})[@res.namedArgLoc ]) - ~children:[sub1] ()) + ((div ~className:{js|menu|js} + ~children:[((div ~className:{js|submenu|js} ~children:[sub1] ()) [@JSX ]); - ((div ~className:(({js|submenu|js})[@res.namedArgLoc ]) - ~children:[sub2] ()) + ((div ~className:{js|submenu|js} ~children:[sub2] ()) [@JSX ])] ()) [@JSX ]) let _ = - ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~children:[((div ~className:(({js|submenu|js})[@res.namedArgLoc ]) - ~children:[sub1] ()) + ((div ~className:{js|menu|js} + ~children:[((div ~className:{js|submenu|js} ~children:[sub1] ()) [@JSX ]); - ((div ~className:(({js|submenu|js})[@res.namedArgLoc ]) - ~children:[sub2] ()) + ((div ~className:{js|submenu|js} ~children:[sub2] ()) [@JSX ])] ()) [@JSX ]) let _ = ((div ~children:child ())[@JSX ]) @@ -95,27 +81,23 @@ let _ = [@JSX ]) let _ = ((Outer.createElement ~inner:((Inner.createElement ~children:[] ()) - [@res.namedArgLoc ][@JSX ]) ~children:[] ()) + [@JSX ]) ~children:[] ()) [@JSX ]) let _ = - ((div ~onClick:((onClickHandler)[@res.namedArgLoc ]) - ~children:[(([{js|foobar|js}])[@JSX ])] ()) + ((div ~onClick:onClickHandler ~children:[(([{js|foobar|js}])[@JSX ])] ()) [@JSX ]) let _ = ((Window.createElement - ~style:(({ - width = 10; - height = 10; - paddingTop = 10; - paddingLeft = 10; - paddingRight = 10; - paddingBottom = 10 - })[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) -let _ = - ((OverEager.createElement ~fiber:((Metal.fiber)[@res.namedArgLoc ]) - ~children:[] ()) - [@JSX ]) + ~style:{ + width = 10; + height = 10; + paddingTop = 10; + paddingLeft = 10; + paddingRight = 10; + paddingBottom = 10 + } ~children:[] ()) + [@JSX ]) +let _ = ((OverEager.createElement ~fiber:Metal.fiber ~children:[] ())[@JSX ]) let arrayOfListOfJsx = [|(([])[@JSX ])|] let arrayOfListOfJsx = [|(([((Foo.createElement ~children:[] ())[@JSX ])])[@JSX ])|] @@ -146,8 +128,7 @@ let _ = ((a ~children:[] ())[@JSX ]) > ((b ~children:[] ())[@JSX ]) let _ = ((a ~children:[] ())[@JSX ]) < ((b ~children:[] ())[@JSX ]) let _ = ((a ~children:[] ())[@JSX ]) > ((b ~children:[] ())[@JSX ]) let y = - ((Routes.createElement ~path:((Routes.stateToPath state) - [@res.namedArgLoc ]) ~isHistorical:((true)[@res.namedArgLoc ]) + ((Routes.createElement ~path:(Routes.stateToPath state) ~isHistorical:true ~onHashChange:((fun [arity:3]_oldPath -> fun _oldUrl -> fun newUrl -> @@ -167,47 +148,37 @@ let y = currentActualPath) latestComponentBag ()) [@res.ternary ])) - [@res.braces ])) ()) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + [@res.braces ])) ())[@res.braces ]) + ~children:[] ()) [@JSX ]) let z = ((div - ~style:((ReactDOMRe.Style.make ~width:((width)[@res.namedArgLoc ]) - ~height:((height)[@res.namedArgLoc ]) ~color:((color) - [@res.namedArgLoc ]) ~backgroundColor:((backgroundColor) - [@res.namedArgLoc ]) ~margin:((margin)[@res.namedArgLoc ]) - ~padding:((padding)[@res.namedArgLoc ]) ~border:((border) - [@res.namedArgLoc ]) ~borderColor:((borderColor) - [@res.namedArgLoc ]) - ~someOtherAttribute:((someOtherAttribute) - [@res.namedArgLoc ]) ())[@res.namedArgLoc ]) - ~key:((string_of_int 1)[@res.namedArgLoc ]) ~children:[] ()) + ~style:(ReactDOMRe.Style.make ~width ~height ~color ~backgroundColor + ~margin ~padding ~border ~borderColor ~someOtherAttribute ()) + ~key:(string_of_int 1) ~children:[] ()) [@JSX ]) let omega = ((div - ~aList:(([width; - height; - color; - backgroundColor; - margin; - padding; - border; - borderColor; - someOtherAttribute])[@res.namedArgLoc ]) - ~key:((string_of_int 1)[@res.namedArgLoc ]) ~children:[] ()) + ~aList:[width; + height; + color; + backgroundColor; + margin; + padding; + border; + borderColor; + someOtherAttribute] ~key:(string_of_int 1) ~children:[] ()) [@JSX ]) let someArray = ((div - ~anArray:(([|width;height;color;backgroundColor;margin;padding;border;borderColor;someOtherAttribute|]) - [@res.namedArgLoc ]) ~key:((string_of_int 1)[@res.namedArgLoc ]) - ~children:[] ()) + ~anArray:[|width;height;color;backgroundColor;margin;padding;border;borderColor;someOtherAttribute|] + ~key:(string_of_int 1) ~children:[] ()) [@JSX ]) let tuples = ((div - ~aTuple:(((width, height, color, backgroundColor, margin, padding, - border, borderColor, someOtherAttribute, - definitelyBreakere))[@res.namedArgLoc ]) - ~key:((string_of_int 1)[@res.namedArgLoc ]) ~children:[] ()) + ~aTuple:(width, height, color, backgroundColor, margin, padding, + border, borderColor, someOtherAttribute, definitelyBreakere) + ~key:(string_of_int 1) ~children:[] ()) [@JSX ]) let icon = ((Icon.createElement @@ -215,124 +186,100 @@ let icon = | v when v < 0.1 -> {js|sound-off|js} | v when v < 0.11 -> {js|sound-min|js} | v when v < 0.51 -> {js|sound-med|js} - | _ -> {js|sound-max|js})[@res.namedArgLoc ][@res.braces ]) - ~children:[] ()) + | _ -> {js|sound-max|js})[@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((MessengerSharedPhotosAlbumViewPhotoReact.createElement ?ref:((if foo#bar === baz then Some (foooooooooooooooooooooooo setRefChild) - else None)[@res.namedArgLoc ][@res.ternary ]) - ~key:((node#legacy_attachment_id)[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) -let _ = ((Foo.createElement ~bar:((bar)[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) -let _ = ((Foo.createElement ?bar:((bar)[@res.namedArgLoc ]) ~children:[] ()) - [@JSX ]) -let _ = - ((Foo.createElement ?bar:((Baz.bar)[@res.namedArgLoc ]) ~children:[] ()) + else None)[@res.ternary ]) ~key:(node#legacy_attachment_id) + ~children:[] ()) [@JSX ]) +let _ = ((Foo.createElement ~bar ~children:[] ())[@JSX ]) +let _ = ((Foo.createElement ?bar ~children:[] ())[@JSX ]) +let _ = ((Foo.createElement ?bar:Baz.bar ~children:[] ())[@JSX ]) let x = ((div ~children:[] ())[@JSX ]) -let _ = ((div ~asd:((1)[@res.namedArgLoc ]) ~children:[] ())[@JSX ]) +let _ = ((div ~asd:1 ~children:[] ())[@JSX ]) ;;foo#bar #= ((bar ~children:[] ())[@JSX ]) ;;foo #= ((bar ~children:[] ())[@JSX ]) ;;foo #= ((bar ~children:[] ())[@JSX ]) let x = [|((div ~children:[] ())[@JSX ])|] let z = ((div ~children:[] ())[@JSX ]) let z = - (((Button.createElement ~onClick:((handleStaleClick)[@res.namedArgLoc ]) - ~children:[] ())[@JSX ]), - ((Button.createElement ~onClick:((handleStaleClick)[@res.namedArgLoc ]) - ~children:[] ())[@JSX ])) + (((Button.createElement ~onClick:handleStaleClick ~children:[] ())[@JSX ]), + ((Button.createElement ~onClick:handleStaleClick ~children:[] ()) + [@JSX ])) let y = [|((div ~children:[] ())[@JSX ]);((div ~children:[] ())[@JSX ])|] let y = - [|((Button.createElement ~onClick:((handleStaleClick)[@res.namedArgLoc ]) - ~children:[] ()) - [@JSX ]);((Button.createElement ~onClick:((handleStaleClick) - [@res.namedArgLoc ]) ~children:[] ()) + [|((Button.createElement ~onClick:handleStaleClick ~children:[] ()) + [@JSX ]);((Button.createElement ~onClick:handleStaleClick ~children:[] ()) [@JSX ])|] let _ = ((Description.createElement - ~term:((Text.createElement ~text:(({js|Age|js})[@res.namedArgLoc ]) - ~children:[] ())[@res.namedArgLoc ][@res.braces ][@JSX ]) - ~children:[child] ()) + ~term:((Text.createElement ~text:{js|Age|js} ~children:[] ()) + [@res.braces ][@JSX ]) ~children:[child] ()) [@JSX ]) let _ = ((Description.createElement - ~term:((Text.createElement ~text:(({js|Age|js})[@res.namedArgLoc ]) - ~children:(([||])[@res.namedArgLoc ]) ()) - [@res.namedArgLoc ][@res.braces ]) ~children:[child] ()) + ~term:((Text.createElement ~text:{js|Age|js} ~children:[||] ()) + [@res.braces ]) ~children:[child] ()) [@JSX ]) let _ = ((Description.createElement - ~term:((Text.createElement ~text:(({js|Age|js})[@res.namedArgLoc ]) ()) - [@res.namedArgLoc ][@res.braces ][@JSX ]) ~children:[child] ()) + ~term:((Text.createElement ~text:{js|Age|js} ())[@res.braces ][@JSX ]) + ~children:[child] ()) [@JSX ]) let _ = ((Description.createElement - ~term:((Text.createElement ~superLongPunnedProp:((superLongPunnedProp) - [@res.namedArgLoc ]) - ~anotherSuperLongOneCrazyLongThingHere:((anotherSuperLongOneCrazyLongThingHere) - [@res.namedArgLoc ]) ~text:(({js|Age|js})[@res.namedArgLoc ]) - ~children:[] ())[@res.namedArgLoc ][@res.braces ][@JSX ]) - ~children:[child] ()) + ~term:((Text.createElement ~superLongPunnedProp + ~anotherSuperLongOneCrazyLongThingHere ~text:{js|Age|js} + ~children:[] ())[@res.braces ][@JSX ]) ~children:[child] ()) [@JSX ]) let _ = ((Foo.createElement - ~bar:((Baz.createElement ~superLongPunnedProp:((superLongPunnedProp) - [@res.namedArgLoc ]) - ~anotherSuperLongOneCrazyLongThingHere:((anotherSuperLongOneCrazyLongThingHere) - [@res.namedArgLoc ]) ~children:[] ()) - [@res.namedArgLoc ][@res.braces ][@JSX ]) ~children:[] ()) + ~bar:((Baz.createElement ~superLongPunnedProp + ~anotherSuperLongOneCrazyLongThingHere ~children:[] ()) + [@res.braces ][@JSX ]) ~children:[] ()) [@JSX ]) let _ = ((div ~children:[((span ~children:[str {js|hello|js}] ())[@JSX ])] ()) [@JSX ]) let _ = - ((description - ~term:((text ~text:(({js|Age|js})[@res.namedArgLoc ]) ~children:[] ()) - [@res.namedArgLoc ][@res.braces ][@JSX ]) ~children:[child] ()) + ((description ~term:((text ~text:{js|Age|js} ~children:[] ()) + [@res.braces ][@JSX ]) ~children:[child] ()) [@JSX ]) let _ = - ((description - ~term:((text ~text:(({js|Age|js})[@res.namedArgLoc ]) ~children:(( - [||])[@res.namedArgLoc ]) ()) - [@res.namedArgLoc ][@res.braces ]) ~children:[child] ()) + ((description ~term:((text ~text:{js|Age|js} ~children:[||] ()) + [@res.braces ]) ~children:[child] ()) [@JSX ]) let _ = - ((description - ~term:((text ~text:(({js|Age|js})[@res.namedArgLoc ]) ~children:(( - [||])[@res.namedArgLoc ])) - [@res.namedArgLoc ][@res.braces ][@JSX ]) ~children:[child] ()) + ((description ~term:((text ~text:{js|Age|js} ~children:[||]) + [@res.braces ][@JSX ]) ~children:[child] ()) [@JSX ]) let _ = - ((description ~term:((text ~text:(({js|Age|js})[@res.namedArgLoc ]) ()) - [@res.namedArgLoc ][@res.braces ][@JSX ]) ~children:[child] ()) + ((description ~term:((text ~text:{js|Age|js} ())[@res.braces ][@JSX ]) + ~children:[child] ()) [@JSX ]) let _ = ((description - ~term:((div ~superLongPunnedProp:((superLongPunnedProp) - [@res.namedArgLoc ]) - ~anotherSuperLongOneCrazyLongThingHere:((anotherSuperLongOneCrazyLongThingHere) - [@res.namedArgLoc ]) ~text:(({js|Age|js})[@res.namedArgLoc ]) - ~children:[] ())[@res.namedArgLoc ][@res.braces ][@JSX ]) + ~term:((div ~superLongPunnedProp ~anotherSuperLongOneCrazyLongThingHere + ~text:{js|Age|js} ~children:[] ())[@res.braces ][@JSX ]) ~children:[child] ()) [@JSX ]) let _ = - ((div ~onClick:((fun [arity:1]event -> handleChange event) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ((div ~onClick:((fun [arity:1]event -> handleChange event)[@res.braces ]) + ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((fun [arity:1]eventWithLongIdent -> - handleChange eventWithLongIdent) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + handleChange eventWithLongIdent)[@res.braces ]) + ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((fun [arity:1]event -> ((Js.log event; handleChange event) - [@res.braces ]))[@res.namedArgLoc ][@res.braces ]) - ~children:[] ()) + [@res.braces ]))[@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((StaticDiv.createElement @@ -342,41 +289,39 @@ let _ = fun lineBreak -> fun identifier -> ((doStuff foo bar baz; bar lineBreak identifier) - [@res.braces ]))[@res.namedArgLoc ][@res.braces ]) - ~children:[] ()) + [@res.braces ]))[@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((AttrDiv.createElement ~onClick:((fun [arity:1]event -> handleChange event) - [@res.namedArgLoc ][@res.braces ][@bar ]) ~children:[] ()) + [@res.braces ][@bar ]) ~children:[] ()) [@JSX ]) let _ = ((AttrDiv.createElement ~onClick:((fun [arity:1]eventLongIdentifier -> - handleChange eventLongIdentifier) - [@res.namedArgLoc ][@res.braces ][@bar ]) ~children:[] ()) + handleChange eventLongIdentifier)[@res.braces ][@bar ]) + ~children:[] ()) [@JSX ]) let _ = ((StaticDivNamed.createElement - ~onClick:((fun [arity:6]~foo:((foo)[@res.namedArgLoc ]) -> - fun ~bar:((bar)[@res.namedArgLoc ]) -> - fun ~baz:((baz)[@res.namedArgLoc ]) -> - fun ~lineBreak:((lineBreak)[@res.namedArgLoc ]) -> - fun ~identifier:((identifier)[@res.namedArgLoc ]) -> - fun () -> bar lineBreak identifier) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ~onClick:((fun [arity:6]~foo -> + fun ~bar -> + fun ~baz -> + fun ~lineBreak -> + fun ~identifier -> + fun () -> bar lineBreak identifier)[@res.braces ]) + ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((fun [arity:1]e -> (((doStuff (); bar foo) - [@res.braces ]) : event)) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + [@res.braces ]) : event))[@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((fun [arity:2]e -> fun e2 -> (((doStuff (); bar foo)[@res.braces ]) : event)) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + [@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div @@ -387,7 +332,7 @@ let _ = fun breakLine -> (((doStuff (); bar foo) [@res.braces ]) : (event * event2 * event3 * event4 * event5))) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + [@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div @@ -397,8 +342,8 @@ let _ = fun superLongIdent -> fun breakLine -> (doStuff () : (event * event2 * event3 * event4 * - event5))) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + event5)))[@res.braces ]) + ~children:[] ()) [@JSX ]) let _ = ((div @@ -409,126 +354,91 @@ let _ = [@JSX ]) let _ = ((div - ~style:((ReactDOMRe.Style.make ~width:(({js|20px|js}) - [@res.namedArgLoc ]) ~height:(({js|20px|js}) - [@res.namedArgLoc ]) ~borderRadius:(({js|100%|js}) - [@res.namedArgLoc ]) ~backgroundColor:(({js|red|js}) - [@res.namedArgLoc ])) - [@res.namedArgLoc ][@res.braces ][@foo ]) ~children:[] ()) + ~style:((ReactDOMRe.Style.make ~width:{js|20px|js} ~height:{js|20px|js} + ~borderRadius:{js|100%|js} ~backgroundColor:{js|red|js}) + [@res.braces ][@foo ]) ~children:[] ()) [@JSX ]) let _ = - ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) - ~value:((value)[@res.namedArgLoc ]) - ~children:((ReactDOMRe.Style.make ~width:(({js|20px|js}) - [@res.namedArgLoc ]) ~height:(({js|20px|js}) - [@res.namedArgLoc ]) ~borderRadius:(({js|100%|js}) - [@res.namedArgLoc ]) ~backgroundColor:(({js|red|js}) - [@res.namedArgLoc ]))[@res.braces ]) ()) + ((Animated.createElement ~initialValue:0.0 ~value + ~children:((ReactDOMRe.Style.make ~width:{js|20px|js} + ~height:{js|20px|js} ~borderRadius:{js|100%|js} + ~backgroundColor:{js|red|js})[@res.braces ]) ()) [@JSX ]) let _ = - ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) - ~value:((value)[@res.namedArgLoc ]) + ((Animated.createElement ~initialValue:0.0 ~value ~children:((fun [arity:1]value -> ((div - ~style:((ReactDOMRe.Style.make ~width:(({js|20px|js}) - [@res.namedArgLoc ]) - ~height:(({js|20px|js}) - [@res.namedArgLoc ]) - ~borderRadius:(({js|100%|js}) - [@res.namedArgLoc ]) - ~backgroundColor:(({js|red|js}) - [@res.namedArgLoc ])) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ~style:((ReactDOMRe.Style.make ~width:{js|20px|js} + ~height:{js|20px|js} + ~borderRadius:{js|100%|js} + ~backgroundColor:{js|red|js}) + [@res.braces ]) ~children:[] ()) [@JSX ]))[@res.braces ]) ()) [@JSX ]) let _ = - ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) - ~value:((value)[@res.namedArgLoc ]) + ((Animated.createElement ~initialValue:0.0 ~value ~children:((fun [arity:1]value -> (((div - ~style:((ReactDOMRe.Style.make - ~width:(({js|20px|js}) - [@res.namedArgLoc ]) - ~height:(({js|20px|js}) - [@res.namedArgLoc ]) - ~borderRadius:(({js|100%|js}) - [@res.namedArgLoc ]) - ~backgroundColor:(({js|red|js}) - [@res.namedArgLoc ])) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ~style:((ReactDOMRe.Style.make ~width:{js|20px|js} + ~height:{js|20px|js} + ~borderRadius:{js|100%|js} + ~backgroundColor:{js|red|js}) + [@res.braces ]) ~children:[] ()) [@JSX ]) : ReasonReact.element))[@res.braces ]) ()) [@JSX ]) let _ = - ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) - ~value:((value)[@res.namedArgLoc ]) + ((Animated.createElement ~initialValue:0.0 ~value ~children:((fun [arity:1]value -> ((div - ~style:((ReactDOMRe.Style.make ~width:(({js|20px|js}) - [@res.namedArgLoc ]) - ~height:(({js|20px|js}) - [@res.namedArgLoc ]) - ~borderRadius:(({js|100%|js}) - [@res.namedArgLoc ]) - ~backgroundColor:(({js|red|js}) - [@res.namedArgLoc ])) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ~style:((ReactDOMRe.Style.make ~width:{js|20px|js} + ~height:{js|20px|js} + ~borderRadius:{js|100%|js} + ~backgroundColor:{js|red|js}) + [@res.braces ]) ~children:[] ()) [@res.braces ][@JSX ]))[@res.braces ][@foo ]) ()) [@JSX ]) let _ = - ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) - ~value:((value)[@res.namedArgLoc ]) + ((Animated.createElement ~initialValue:0.0 ~value ~children:((fun [arity:1]value -> ((let width = {js|20px|js} in let height = {js|20px|js} in ((div - ~style:((ReactDOMRe.Style.make ~width:((width) - [@res.namedArgLoc ]) ~height:((height) - [@res.namedArgLoc ]) - ~borderRadius:(({js|100%|js}) - [@res.namedArgLoc ]) - ~backgroundColor:(({js|red|js}) - [@res.namedArgLoc ])) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ~style:((ReactDOMRe.Style.make ~width ~height + ~borderRadius:{js|100%|js} + ~backgroundColor:{js|red|js}) + [@res.braces ]) ~children:[] ()) [@JSX ])) [@res.braces ]))[@res.braces ]) ()) [@JSX ]) let _ = - ((div ~callback:((reduce (fun [arity:1]() -> not state)) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + ((div ~callback:((reduce (fun [arity:1]() -> not state))[@res.braces ]) + ~children:[] ()) [@JSX ]) let _ = - ((button ?id:((id)[@res.namedArgLoc ]) - ~className:((Cn.make [|{js|button|js};{js|is-fullwidth|js}|]) - [@res.namedArgLoc ][@res.braces ]) ~onClick:((onClick) - [@res.namedArgLoc ]) ~children:[((ste {js|Submit|js})[@res.braces ])] - ()) + ((button ?id ~className:((Cn.make [|{js|button|js};{js|is-fullwidth|js}|]) + [@res.braces ]) ~onClick + ~children:[((ste {js|Submit|js})[@res.braces ])] ()) [@JSX ]) let _ = - ((button ?id:((id)[@res.namedArgLoc ]) - ~className:((Cn.make [{js|button|js}; {js|is-fullwidth|js}]) - [@res.namedArgLoc ][@res.braces ]) ~onClick:((onClick) - [@res.namedArgLoc ]) ~children:[((ste {js|Submit|js})[@res.braces ])] - ()) + ((button ?id ~className:((Cn.make [{js|button|js}; {js|is-fullwidth|js}]) + [@res.braces ]) ~onClick + ~children:[((ste {js|Submit|js})[@res.braces ])] ()) [@JSX ]) let _ = - ((button ?id:((id)[@res.namedArgLoc ]) - ~className:((Cn.make ({js|button|js}, {js|is-fullwidth|js})) - [@res.namedArgLoc ][@res.braces ]) ~onClick:((onClick) - [@res.namedArgLoc ]) ~children:[((ste {js|Submit|js})[@res.braces ])] - ()) + ((button ?id ~className:((Cn.make ({js|button|js}, {js|is-fullwidth|js})) + [@res.braces ]) ~onClick + ~children:[((ste {js|Submit|js})[@res.braces ])] ()) [@JSX ]) let _ = - ((button ?id:((id)[@res.namedArgLoc ]) ~className:((Cn.make { a = b }) - [@res.namedArgLoc ][@res.braces ]) ~onClick:((onClick) - [@res.namedArgLoc ]) ~children:[((ste {js|Submit|js})[@res.braces ])] - ()) + ((button ?id ~className:((Cn.make { a = b })[@res.braces ]) ~onClick + ~children:[((ste {js|Submit|js})[@res.braces ])] ()) [@JSX ]) let _ = ((X.createElement ~y:((z -> (Belt.Option.getWithDefault {js||js})) - [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) + [@res.braces ]) ~children:[] ()) [@JSX ]) let _ = - ((div ~style:((getStyle ())[@res.namedArgLoc ][@res.braces ]) + ((div ~style:((getStyle ())[@res.braces ]) ~children:[((ReasonReact.string {js|BugTest|js})[@res.braces ])] ()) [@JSX ]) let _ = @@ -541,13 +451,10 @@ let _ = [@res.braces ])] ()) [@JSX ]) let _ = - ((View.createElement ~style:((styles#backgroundImageWrapper) - [@res.namedArgLoc ]) + ((View.createElement ~style:(styles#backgroundImageWrapper) ~children:[(((let uri = {js|/images/header-background.png|js} in - ((Image.createElement ~resizeMode:((Contain) - [@res.namedArgLoc ]) ~style:((styles#backgroundImage) - [@res.namedArgLoc ]) ~uri:((uri)[@res.namedArgLoc ]) - ~children:[] ()) + ((Image.createElement ~resizeMode:Contain + ~style:(styles#backgroundImage) ~uri ~children:[] ()) [@JSX ]))) [@res.braces ])] ()) [@JSX ]) @@ -558,9 +465,9 @@ let _ = (fun [arity:1]possibleGradeValue -> ((option ~key:((string_of_int possibleGradeValue) - [@res.namedArgLoc ][@res.braces ]) + [@res.braces ]) ~value:((string_of_int possibleGradeValue) - [@res.namedArgLoc ][@res.braces ]) + [@res.braces ]) ~children:[((str (string_of_int possibleGradeValue)) @@ -576,7 +483,7 @@ let _ = [@JSX ])] ())[@JSX ]) ;;((div ~children:[((div ~onClick:((fun [arity:1]_ -> Js.log (a <= 10)) - [@res.namedArgLoc ][@res.braces ]) + [@res.braces ]) ~children:[((div ~children:[((Js.log (a <= 10)) [@res.braces ])] ()) @@ -594,7 +501,5 @@ let _ = ;;(([[|a|]])[@JSX ]) ;;(([(1, 2)])[@JSX ]) ;;(([((array -> f)[@res.braces ])])[@JSX ]) -let _ = - ((A.createElement ~x:(({js|y|js})[@res.namedArgLoc ]) ~_spreadProps:((str) - [@res.namedArgLoc ]) ~children:[] ()) +let _ = ((A.createElement ~x:{js|y|js} ~_spreadProps:str ~children:[] ()) [@JSX ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/parenthesized.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/parenthesized.res.txt index 871890abac..9640bcb5fe 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/parenthesized.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/parenthesized.res.txt @@ -16,9 +16,7 @@ let aTuple = (1, 2) let aRecord = { name = {js|steve|js}; age = 30 } let blockExpression = ((let a = 1 in let b = 2 in a + b)[@res.braces ]) let assertSmthing = assert true -let jsx = - ((div ~className:(({js|cx|js})[@res.namedArgLoc ]) ~children:[foo] ()) - [@JSX ]) +let jsx = ((div ~className:{js|cx|js} ~children:[foo] ())[@JSX ]) let ifExpr = if true then Js.log true else Js.log false let forExpr = for p = 0 to 10 do () done let whileExpr = while true do doSomeImperativeThing () done diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/primary.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/primary.res.txt index f7aabdd001..b825a969be 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/primary.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/primary.res.txt @@ -18,15 +18,9 @@ let x = (arr.((x : int))).((y : int)) ;;f (x : int) ;;f a b c ;;f a b c -;;f ~a:((a)[@res.namedArgLoc ]) ~b:((bArg)[@res.namedArgLoc ]) ?c:((c) - [@res.namedArgLoc ]) ?d:((expr)[@res.namedArgLoc ]) -;;((f ~a:((a)[@res.namedArgLoc ]) ~b:((bArg)[@res.namedArgLoc ]) ?c:((c) - [@res.namedArgLoc ]) ?d:((expr)[@res.namedArgLoc ])) ~a:((a) - [@res.namedArgLoc ]) ~b:((bArg)[@res.namedArgLoc ]) ?c:((c) - [@res.namedArgLoc ]) ?d:((expr)[@res.namedArgLoc ])) ~a:((a) - [@res.namedArgLoc ]) ~b:((bArg)[@res.namedArgLoc ]) ?c:((c) - [@res.namedArgLoc ]) ?d:((expr)[@res.namedArgLoc ]) -;;f ~a:(((x : int))[@res.namedArgLoc ]) ?b:(((y : int))[@res.namedArgLoc ]) +;;f ~a ~b:bArg ?c ?d:expr +;;((f ~a ~b:bArg ?c ?d:expr) ~a ~b:bArg ?c ?d:expr) ~a ~b:bArg ?c ?d:expr +;;f ~a:(x : int) ?b:(y : int) ;;connection#platformId ;;((connection#left)#account)#accountName ;;john#age #= 99 diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt index 5c29a6c063..1730377121 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt @@ -5,11 +5,10 @@ let l = (fun [arity:1]i -> i + 1) -> (fun [arity:1]__x -> List.map __x [1; 2; 3]) let x [arity:1]__x = List.length __x let nested [arity:1]x [arity:1]__x = List.length __x -let incr [arity:1]~v:((v)[@res.namedArgLoc ]) = v + 1 +let incr [arity:1]~v = v + 1 let l1 = List.length (List.map (fun [arity:1]__x -> incr ~v:__x) [1; 2; 3]) let l2 = List.length (List.map (fun [arity:1]__x -> incr ~v:__x) [1; 2; 3]) -let optParam [arity:2]?v:((v)[@res.namedArgLoc ]) () = - ((if v == None then 0 else 1)[@res.ternary ]) +let optParam [arity:2]?v () = ((if v == None then 0 else 1)[@res.ternary ]) let l1 = List.length (List.map (fun [arity:1]__x -> optParam ?v:__x ()) [Some 1; None; Some 2]) diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/firstClassModules.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/firstClassModules.res.txt index a538484514..072909bd18 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/firstClassModules.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/firstClassModules.res.txt @@ -8,7 +8,7 @@ let sort (type s) let foo [arity:2](module Foo) baz = Foo.bar baz let bump_list (type a) [arity:2]((module B) : (module Bumpable with type t = a)) (l : a list) = - List.map ~f:((B.bump l)[@res.namedArgLoc ]) + List.map ~f:(B.bump l) ;;match x with | (module Set) -> () | ((module Set) : (module Set.S with type elt = s)) -> () diff --git a/tests/syntax_tests/data/parsing/grammar/signature/expected/external.res.txt b/tests/syntax_tests/data/parsing/grammar/signature/expected/external.res.txt index 196499d2a1..4569a856f7 100644 --- a/tests/syntax_tests/data/parsing/grammar/signature/expected/external.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/signature/expected/external.res.txt @@ -2,8 +2,7 @@ module type Signature = sig type nonrec t external linkProgram : - t -> program:((webGlProgram)[@res.namedArgLoc ]) -> unit (a:2) = - "linkProgram"[@@send ] + t -> program:webGlProgram -> unit (a:2) = "linkProgram"[@@send ] external add_nat : nat -> int -> int -> int (a:3) = "add_nat_bytecode" external svg : unit -> React.element (a:1) = "svg" external svg : unit -> React.element (a:1) = "svg" diff --git a/tests/syntax_tests/data/parsing/grammar/structure/expected/externalDefinition.res.txt b/tests/syntax_tests/data/parsing/grammar/structure/expected/externalDefinition.res.txt index 94f22ade32..fef51f61f5 100644 --- a/tests/syntax_tests/data/parsing/grammar/structure/expected/externalDefinition.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/structure/expected/externalDefinition.res.txt @@ -1,9 +1,7 @@ external clear : t -> int -> unit (a:2) = "clear" external add_nat : nat -> int (a:1) = "add_nat_bytecode" external attachShader : - t -> - program:((webGlProgram)[@res.namedArgLoc ]) -> - shader:((webGlShader)[@res.namedArgLoc ]) -> unit (a:3) = + t -> program:webGlProgram -> shader:webGlShader -> unit (a:3) = "attachShader"[@@send ] external svg : unit -> React.element (a:1) = "svg" external svg : unit -> React.element (a:1) = "svg" diff --git a/tests/syntax_tests/data/parsing/grammar/typedefinition/expected/privateTypeEquation.res.txt b/tests/syntax_tests/data/parsing/grammar/typedefinition/expected/privateTypeEquation.res.txt index 1bc71f372b..1c13dd6ee6 100644 --- a/tests/syntax_tests/data/parsing/grammar/typedefinition/expected/privateTypeEquation.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/typedefinition/expected/privateTypeEquation.res.txt @@ -5,8 +5,7 @@ type nonrec t = private int type nonrec t = private int -> int (a:1) type nonrec t = private int -> int (a:1) type nonrec t = private int -> int -> int (a:1) (a:1) -type nonrec t = private - int -> x:((string)[@res.namedArgLoc ]) -> float -> unit (a:3) +type nonrec t = private int -> x:string -> float -> unit (a:3) type nonrec t = private string as 'x type nonrec t = private [%ext ] type nonrec t = private [%ext {js|console.log|js}] diff --git a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/es6Arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/es6Arrow.res.txt index 1caf71d444..aa42f44491 100644 --- a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/es6Arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/es6Arrow.res.txt @@ -1,49 +1,34 @@ type nonrec t = x -> unit (a:1) type nonrec t = x -> unit (a:1) type nonrec t = int -> string -> unit (a:2) -type nonrec t = - a:((int)[@res.namedArgLoc ]) -> b:((int)[@res.namedArgLoc ]) -> int (a:2) -type nonrec t = - ?a:((int)[@res.namedArgLoc ]) -> ?b:((int)[@res.namedArgLoc ]) -> int (a:2) +type nonrec t = a:int -> b:int -> int (a:2) +type nonrec t = ?a:int -> ?b:int -> int (a:2) type nonrec t = int -> int -> int -> int (a:1) (a:1) (a:1) -type nonrec t = - a:((int)[@res.namedArgLoc ]) -> - b:((int)[@res.namedArgLoc ]) -> - c:((int)[@res.namedArgLoc ]) -> int (a:1) (a:1) (a:1) +type nonrec t = a:int -> b:int -> c:int -> int (a:1) (a:1) (a:1) let (f : x -> unit (a:1)) = xf let (f : x -> unit (a:1)) = xf let (f : int -> string -> unit (a:2)) = xf -let (t : - a:((int)[@res.namedArgLoc ]) -> b:((int)[@res.namedArgLoc ]) -> int (a:2)) - = xf -let (t : - ?a:((int)[@res.namedArgLoc ]) -> ?b:((int)[@res.namedArgLoc ]) -> int (a:2)) - = xf +let (t : a:int -> b:int -> int (a:2)) = xf +let (t : ?a:int -> ?b:int -> int (a:2)) = xf let (t : int -> int -> int -> int (a:1) (a:1) (a:1)) = xf -let (t : - a:((int)[@res.namedArgLoc ]) -> - b:((int)[@res.namedArgLoc ]) -> - c:((int)[@res.namedArgLoc ]) -> int (a:1) (a:1) (a:1)) - = xf -type nonrec t = f:((int)[@res.namedArgLoc ]) -> string -type nonrec t = ?f:((int)[@res.namedArgLoc ]) -> string -let (f : f:((int)[@res.namedArgLoc ]) -> string) = fx -let (f : ?f:((int)[@res.namedArgLoc ]) -> string) = fx -type nonrec t = f:((int)[@res.namedArgLoc ]) -> string (a:1) -type nonrec t = f:((int)[@res.namedArgLoc ]) -> string -type nonrec t = f:((int -> string (a:1))[@res.namedArgLoc ]) -> float (a:1) -type nonrec t = f:((int -> string (a:1))[@res.namedArgLoc ]) -> float -type nonrec t = f:((int)[@res.namedArgLoc ]) -> string -> float (a:1) +let (t : a:int -> b:int -> c:int -> int (a:1) (a:1) (a:1)) = xf +type nonrec t = f:int -> string +type nonrec t = ?f:int -> string +let (f : f:int -> string) = fx +let (f : ?f:int -> string) = fx +type nonrec t = f:int -> string (a:1) +type nonrec t = f:int -> string +type nonrec t = f:(int -> string (a:1)) -> float (a:1) +type nonrec t = f:(int -> string (a:1)) -> float +type nonrec t = f:int -> string -> float (a:1) type nonrec t = - ((a:((int)[@res.namedArgLoc ]) -> - ((b:((int)[@res.namedArgLoc ]) -> ((float)[@attr ]) -> unit)[@attrBeforeLblB - ]) (a:3)) + ((a:int -> ((b:int -> ((float)[@attr ]) -> unit)[@attrBeforeLblB ]) (a:3)) [@attrBeforeLblA ]) type nonrec t = - ((a:((int)[@res.namedArgLoc ]) -> - ((b:((int)[@res.namedArgLoc ]) -> ((float)[@attr ]) -> unit (a:1) (a:1)) - [@attrBeforeLblB ]) (a:1))[@attrBeforeLblA ]) -type nonrec t = ((a:((int)[@res.namedArgLoc ]) -> unit)[@attr ]) + ((a:int -> + ((b:int -> ((float)[@attr ]) -> unit (a:1) (a:1))[@attrBeforeLblB ]) (a:1)) + [@attrBeforeLblA ]) +type nonrec t = ((a:int -> unit)[@attr ]) type nonrec 'a getInitialPropsFn = < query: string dict ;req: 'a Js.t Js.Nullable.t > -> 'a Js.t Js.Promise.t (a:1) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/objectTypeSpreading.res.txt b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/objectTypeSpreading.res.txt index bfe62dd69d..dba6e2e8bb 100644 --- a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/objectTypeSpreading.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/objectTypeSpreading.res.txt @@ -15,14 +15,12 @@ let steve = ((([%obj { name = {js|Steve|js}; age = 30 }] : < user ;age: int > )) [@res.braces ]) let printFullUser [arity:1](steve : < user ;age: int > ) = Js.log steve -let printFullUser - [arity:1]~user:(((user : < user ;age: int > ))[@res.namedArgLoc ]) = +let printFullUser [arity:1]~user:(user : < user ;age: int > ) = Js.log steve -let printFullUser - [arity:1]~user:(((user : < user ;age: int > ))[@res.namedArgLoc ]) = +let printFullUser [arity:1]~user:(user : < user ;age: int > ) = + Js.log steve +let printFullUser [arity:1]?(user= (steve : < user ;age: int > )) = Js.log steve -let printFullUser [arity:1]?user:(((user)[@res.namedArgLoc ])= - (steve : < user ;age: int > )) = Js.log steve external steve : < user ;age: int > = "steve"[@@val ] let makeCeoOf30yearsOld [arity:1]name = ([%obj { name; age = 30 }] : < user ;age: int > ) diff --git a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/parenthesized.res.txt b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/parenthesized.res.txt index 67be279695..cb2fe0fb03 100644 --- a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/parenthesized.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/parenthesized.res.txt @@ -1 +1 @@ -type nonrec t = ((a:((int)[@res.namedArgLoc ]) -> unit (a:1))[@attr ]) \ No newline at end of file +type nonrec t = ((a:int -> unit (a:1))[@attr ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt index 7dabe08322..1d67914ae9 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt @@ -141,9 +141,8 @@ include match successor with | None -> let leaf = - createNode ~value:((Js.Internal.raw_expr {js|0|js}) - [@res.namedArgLoc ]) ~color:((Black)[@res.namedArgLoc ]) - ~height:((0.)[@res.namedArgLoc ]) in + createNode ~value:(Js.Internal.raw_expr {js|0|js}) + ~color:Black ~height:0. in let isLeaf = Js.Internal.fn_mk1 (fun [arity:1]x -> x === leaf) in (leaf, isLeaf) | Some successor -> @@ -153,8 +152,7 @@ include (match nodeParent with | None -> () | Some parent -> - leftOrRightSet parent ~node:((nodeToRemove)[@res.namedArgLoc ]) - (Some successor)); + leftOrRightSet parent ~node:nodeToRemove (Some successor)); updateSumRecursive rbt successor; if (colorGet nodeToRemove) === Black then @@ -276,9 +274,7 @@ include (if (rootGet rbt) === (Some successor) then rootSet rbt None; (match parentGet successor with | None -> () - | Some parent -> - leftOrRightSet parent ~node:((successor)[@res.namedArgLoc ]) - None))) + | Some parent -> leftOrRightSet parent ~node:successor None))) [@res.braces ]) let remove [arity:2]rbt value = match _findNode rbt (rootGet rbt) value with @@ -303,9 +299,7 @@ include | None -> None | Some node -> Some (valueGet node)) [@res.braces ]) - let make [arity:1]~compare:((compare)[@res.namedArgLoc ]) = - t ~size:((0)[@res.namedArgLoc ]) ~root:((None)[@res.namedArgLoc ]) - ~compare:((compare)[@res.namedArgLoc ]) + let make [arity:1]~compare = t ~size:0 ~root:None ~compare let rec heightOfInterval [arity:4]rbt node lhs rhs = match node with | None -> 0. @@ -355,7 +349,7 @@ include match firstVisibleNode node offset with | None -> maxNode node | first -> first - let firstVisible [arity:2]rbt ~offset:((offset)[@res.namedArgLoc ]) = + let firstVisible [arity:2]rbt ~offset = match firstVisibleNode (rootGet rbt) offset with | None -> None | Some node -> Some (valueGet node) @@ -370,8 +364,7 @@ include match rightGet node with | None -> firstRightParent node | Some right -> Some (leftmost right) - let rec sumLeftSpine [arity:2]node - ~fromRightChild:((fromRightChild)[@res.namedArgLoc ]) = + let rec sumLeftSpine [arity:2]node ~fromRightChild = ((let leftSpine = match leftGet node with | None -> heightGet node @@ -384,12 +377,10 @@ include | Some parent -> leftSpine +. (sumLeftSpine parent - ~fromRightChild:(((rightGet parent) === (Some node)) - [@res.namedArgLoc ]))) + ~fromRightChild:((rightGet parent) === (Some node)))) [@res.braces ]) let getY [arity:1]node = - (sumLeftSpine node ~fromRightChild:((true)[@res.namedArgLoc ])) -. - (heightGet node) + (sumLeftSpine node ~fromRightChild:true) -. (heightGet node) let linearSearch [arity:2]rbt callback = ((let rec find [arity:2]node callback = if Js.Internal.fn_run1 callback (valueGet node) @@ -402,8 +393,7 @@ include | None -> None | Some node -> find node callback) [@res.braces ]) - let rec iterate [arity:4]~inclusive:((inclusive)[@res.namedArgLoc ]) - firstNode lastNode ~callback:((callback)[@res.namedArgLoc ]) = + let rec iterate [arity:4]~inclusive firstNode lastNode ~callback = match firstNode with | None -> () | Some node -> @@ -411,12 +401,9 @@ include if (!==) firstNode lastNode then (if not inclusive then Js.Internal.fn_run1 callback node; - iterate ~inclusive:((inclusive)[@res.namedArgLoc ]) - (nextNode node) lastNode ~callback:((callback) - [@res.namedArgLoc ]))) - let rec iterateWithY [arity:5]?y:((y)[@res.namedArgLoc ]) - ~inclusive:((inclusive)[@res.namedArgLoc ]) firstNode lastNode - ~callback:((callback)[@res.namedArgLoc ]) = + iterate ~inclusive (nextNode node) lastNode ~callback)) + let rec iterateWithY [arity:5]?y ~inclusive firstNode lastNode + ~callback = match firstNode with | None -> () | Some node -> @@ -425,22 +412,20 @@ include if (!==) firstNode lastNode then (if not inclusive then Js.Internal.fn_run2 callback node y; - iterateWithY ~y:((y +. (heightGet node))[@res.namedArgLoc ]) - ~inclusive:((inclusive)[@res.namedArgLoc ]) (nextNode node) - lastNode ~callback:((callback)[@res.namedArgLoc ]))) - let rec updateSum [arity:2]node ~delta:((delta)[@res.namedArgLoc ]) = + iterateWithY ~y:(y +. (heightGet node)) ~inclusive + (nextNode node) lastNode ~callback)) + let rec updateSum [arity:2]node ~delta = match node with | None -> () | Some node -> (sumSet node ((sumGet node) +. delta); - updateSum (parentGet node) ~delta:((delta)[@res.namedArgLoc ])) - let setHeight [arity:3]rbt value ~height:((height)[@res.namedArgLoc ]) = + updateSum (parentGet node) ~delta) + let setHeight [arity:3]rbt value ~height = match _findNode rbt (rootGet rbt) value with | None -> () | Some node -> let delta = height -. (heightGet node) in - (heightSet node height; - updateSum (Some node) ~delta:((delta)[@res.namedArgLoc ])) + (heightSet node height; updateSum (Some node) ~delta) type nonrec 'value oldNewVisibleNodes = { mutable old: 'value array ; diff --git a/tests/syntax_tests/data/ppx/react/expected/externalWithCustomName.res.txt b/tests/syntax_tests/data/ppx/react/expected/externalWithCustomName.res.txt index 93680d0ead..3eadedfee0 100644 --- a/tests/syntax_tests/data/ppx/react/expected/externalWithCustomName.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/externalWithCustomName.res.txt @@ -8,7 +8,7 @@ module Foo = { external component: React.componentLike, React.element> = "component" } -let t = React.createElement(Foo.component, {a: 1, b: "1"}) +let t = React.createElement(Foo.component, {a: 1, b: {"1"}}) @@jsxConfig({version: 4, mode: "automatic"}) @@ -20,4 +20,4 @@ module Foo = { external component: React.componentLike, React.element> = "component" } -let t = React.jsx(Foo.component, {a: 1, b: "1"}) +let t = React.jsx(Foo.component, {a: 1, b: {"1"}}) diff --git a/tests/syntax_tests/data/ppx/react/expected/firstClassModules.res.txt b/tests/syntax_tests/data/ppx/react/expected/firstClassModules.res.txt index 6d4c3beee9..934880c83a 100644 --- a/tests/syntax_tests/data/ppx/react/expected/firstClassModules.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/firstClassModules.res.txt @@ -50,7 +50,7 @@ module External = { props< module(T with type t = 'a and type key = 'key), option<'key>, - (option<'key> => unit), + option<'key> => unit, array<'a>, >, React.element, diff --git a/tests/syntax_tests/data/ppx/react/expected/firstClassModules.resi.txt b/tests/syntax_tests/data/ppx/react/expected/firstClassModules.resi.txt index 54bfc7895c..556f6b9f0e 100644 --- a/tests/syntax_tests/data/ppx/react/expected/firstClassModules.resi.txt +++ b/tests/syntax_tests/data/ppx/react/expected/firstClassModules.resi.txt @@ -17,7 +17,7 @@ module Select: { props< module(T with type t = 'a and type key = 'key), option<'key>, - (option<'key> => unit), + option<'key> => unit, array<'a>, >, React.element, diff --git a/tests/syntax_tests/data/ppx/react/expected/forwardRef.res.txt b/tests/syntax_tests/data/ppx/react/expected/forwardRef.res.txt index 6f5d0caad5..84afe72df2 100644 --- a/tests/syntax_tests/data/ppx/react/expected/forwardRef.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/forwardRef.res.txt @@ -21,7 +21,7 @@ module V4C = { ~props={ type_: "text", ?className, - ref: ?(Js.Nullable.toOption(ref)->Belt.Option.map(React.Ref.domRef)), + ref: ?{Js.Nullable.toOption(ref)->Belt.Option.map(React.Ref.domRef)}, }, [], ), @@ -78,7 +78,7 @@ module V4CUncurried = { ~props={ type_: "text", ?className, - ref: ?(Js.Nullable.toOption(ref)->Belt.Option.map(React.Ref.domRef)), + ref: ?{Js.Nullable.toOption(ref)->Belt.Option.map(React.Ref.domRef)}, }, [], ), @@ -135,7 +135,7 @@ module V4A = { { type_: "text", ?className, - ref: ?(Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)), + ref: ?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)}, }, ), children, @@ -189,7 +189,7 @@ module V4AUncurried = { { type_: "text", ?className, - ref: ?(Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)), + ref: ?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)}, }, ), children, diff --git a/tests/syntax_tests/data/ppx/react/expected/uncurriedProps.res.txt b/tests/syntax_tests/data/ppx/react/expected/uncurriedProps.res.txt index 28da95c83e..3cd05a73c2 100644 --- a/tests/syntax_tests/data/ppx/react/expected/uncurriedProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/uncurriedProps.res.txt @@ -51,7 +51,7 @@ module Bar = { @res.jsxComponentProps type props = {} - let make = (_: props) => React.jsx(Foo.make, {callback: (_, _, _) => ()}) + let make = (_: props) => React.jsx(Foo.make, {callback: {(_, _, _) => ()}}) let make = { let \"UncurriedProps$Bar" = props => make(props)