From d4fe75321b5d175c810620818cf0c62aab207a2c Mon Sep 17 00:00:00 2001 From: Roland Peelen Date: Thu, 22 Oct 2026 16:14:31 +0200 Subject: [PATCH 1/5] Format a blank line around module items that span several lines Why: Dense code, often written by AI agents, runs multi-line modules and functions together, which makes a file hard to scan (#8960). The formatter already collapses several blank lines into one; it now also separates an item that prints on more than one line from its neighbours in structures and signatures. Blocks inside expressions keep their layout. Format modified (structure items): Example: module Details = { let make = () => React.string("details") } module Output = Tool.TextResult.Output let failed = Tool.TextResult.failed Before (rescript): module Details = { let make = () => React.string("details") } module Output = Tool.TextResult.Output let failed = Tool.TextResult.failed After (rescript): module Details = { let make = () => React.string("details") } module Output = Tool.TextResult.Output let failed = Tool.TextResult.failed Format unchanged (one-line items with comments): Example: let a = 1 // about b let b = 2 // trailing let c = 3 After (rescript): let a = 1 // about b let b = 2 // trailing let c = 3 Review: Is "multi-line" decided on the source or on the output? On the output: the new Res_doc.item_separator measures the items on each side with the printer's own layout decisions, stopping at the first line break, so an item that only breaks at the line width counts and formatting twice gives the same text. All 1025 printer and idempotency fixtures are stable across two passes. Review: Why a Res_doc.comment marker? Leading comments print inside the item's document (a value binding carries them), so a `//` line above a one-line item would make it multi-line. The marker keeps comments out of the measurement; doc comments are attributes and still count. Review: Why move own-line trailing comments below the blank line? A comment inside the previous item's source, such as `f(a // c => 1)`, prints on its own line after the item. Formatting again makes it a leading comment of the next item, after the blank line, so the first pass puts it there too. Review: Does this reformat existing code? Yes: 346 of the 1870 .res/.resi files `make format` covers gain blank lines. They are not reformatted in this commit, so `make checkformat` reports them. Signed-off-by: Roland Peelen --- ...formatter-multiline-item-spacing.polish.md | 1 + compiler/syntax/src/res_doc.ml | 109 +++++++++++++++--- compiler/syntax/src/res_doc.mli | 9 ++ compiler/syntax/src/res_printer.ml | 22 ++-- .../data/ast-mapping/expected/Braces.res.txt | 2 + .../expected/FunctionsAndArrows.res.txt | 1 + .../ast-mapping/expected/JSXElements.res.txt | 2 + .../ast-mapping/expected/JSXFragments.res.txt | 2 + .../expected/JsxComponents.res.txt | 7 ++ .../expected/RawExtensions.res.txt | 2 + .../expected/TernaryExpressions.res.txt | 1 + .../data/ast-mapping/expected/regexp.res.txt | 2 + .../reason/expected/bracedJsx.res.txt | 4 + .../reason/expected/comments.res.txt | 11 ++ .../reason/expected/modType.res.txt | 2 + .../conversion/reason/expected/ppx.res.txt | 3 + .../ppx/react/expected/aliasProps.res.txt | 8 ++ .../ppx/react/expected/asyncAwait.res.txt | 3 + .../ppx/react/expected/commentAtTop.res.txt | 1 + .../react/expected/defaultPatternProp.res.txt | 3 + .../react/expected/defaultValueProp.res.txt | 6 + .../react/expected/fileLevelConfig.res.txt | 1 + .../react/expected/firstClassModules.resi.txt | 1 + .../ppx/react/expected/forwardRef.res.txt | 6 + .../data/ppx/react/expected/fragment.res.txt | 5 + .../data/ppx/react/expected/interface.res.txt | 3 + .../ppx/react/expected/interface.resi.txt | 1 + .../react/expected/interfaceWithRef.res.txt | 2 + .../react/expected/interfaceWithRef.resi.txt | 1 + .../ppx/react/expected/mangleKeyword.res.txt | 2 + .../data/ppx/react/expected/nested.res.txt | 3 + .../data/ppx/react/expected/newtype.res.txt | 7 ++ .../ppx/react/expected/noPropsWithKey.res.txt | 2 + .../expected/optimizeAutomaticMode.res.txt | 2 + .../react/expected/optionalKeyType.res.txt | 3 + .../react/expected/returnConstraint.res.txt | 4 + .../ppx/react/expected/sharedProps.res.txt | 4 + .../expected/sharedPropsWithProps.res.txt | 10 ++ .../data/ppx/react/expected/topLevel.res.txt | 1 + .../ppx/react/expected/typeConstraint.res.txt | 1 + .../ppx/react/expected/uncurriedProps.res.txt | 4 + .../data/ppx/react/expected/v4.res.txt | 8 ++ .../expected/callbackTrailing.res.txt | 5 + .../printer/comments/expected/expr.res.txt | 6 + .../printer/comments/expected/modExpr.res.txt | 2 + .../printer/comments/expected/modType.res.txt | 2 + .../comments/expected/namedArgs.res.txt | 1 + .../printer/comments/expected/pattern.res.txt | 1 + .../comments/expected/structureItem.res.txt | 1 + .../comments/expected/typeDefinition.res.txt | 1 + .../printer/comments/expected/typexpr.res.txt | 5 + .../comments/expected/valueBindings.res.txt | 1 + .../data/printer/expected/regexp.res.txt | 2 + .../printer/expected/regexpStatements.res.txt | 2 + .../printer/expr/expected/DocComments.res.txt | 2 + .../data/printer/expr/expected/apply.res.txt | 13 +++ .../data/printer/expr/expected/array.res.txt | 1 + .../data/printer/expr/expected/assert.res.txt | 1 + .../printer/expr/expected/assignment.res.txt | 16 +++ .../printer/expr/expected/asyncAwait.res.txt | 9 ++ .../data/printer/expr/expected/binary.res.txt | 21 ++++ .../data/printer/expr/expected/block.res.txt | 1 + .../data/printer/expr/expected/braced.res.txt | 25 ++++ .../data/printer/expr/expected/bsObj.res.txt | 2 + .../printer/expr/expected/callback.res.txt | 6 + .../data/printer/expr/expected/coerce.res.txt | 8 ++ .../printer/expr/expected/constructor.res.txt | 4 + .../printer/expr/expected/extension.res.txt | 2 + .../data/printer/expr/expected/field.res.txt | 2 + .../expr/expected/firstClassModule.res.txt | 5 + .../data/printer/expr/expected/fun.res.txt | 8 ++ .../expr/expected/functionLayouts.res.txt | 5 + .../data/printer/expr/expected/jsx.res.txt | 8 ++ .../printer/expr/expected/jsxChildren.res.txt | 39 +++++++ .../expr/expected/jsxChildrenComments.res.txt | 40 +++++++ .../printer/expr/expected/newtype.res.txt | 1 + .../printer/expr/expected/polyvariant.res.txt | 4 + .../data/printer/expr/expected/record.res.txt | 12 ++ .../printer/expr/expected/refFunction.res.txt | 9 ++ .../printer/expr/expected/setfield.res.txt | 1 + .../printer/expr/expected/ternary.res.txt | 17 +++ .../data/printer/expr/expected/unary.res.txt | 7 ++ .../modExpr/expected/attributes.res.txt | 5 + .../printer/modExpr/expected/functor.res.txt | 6 + .../printer/modExpr/expected/include.res.txt | 2 + .../printer/modExpr/expected/parens.res.txt | 1 + .../modExpr/expected/structure.res.txt | 3 + .../modType/expected/moduleTypeOf.res.txt | 1 + .../modType/expected/withConstraints.res.txt | 6 + .../other/expected/StaticReactTypes.res.txt | 1 + .../printer/other/expected/attributes.res.txt | 1 + .../printer/other/expected/fatSlider.res.txt | 1 + .../printer/pattern/expected/alias.res.txt | 1 + .../expected/firstClassModules.res.txt | 1 + .../printer/pattern/expected/list.res.txt | 1 + .../printer/pattern/expected/record.res.txt | 12 ++ .../signature/expected/exception.resi.txt | 1 + .../expected/externalObjectSpread.resi.txt | 1 + .../expected/multilineSpacing.resi.txt | 19 +++ .../printer/signature/multilineSpacing.resi | 14 +++ .../structure/expected/exception.res.txt | 4 + .../expected/externalObjectSpread.res.txt | 1 + .../structure/expected/include.res.txt | 1 + .../expected/multilineSpacing.res.txt | 58 ++++++++++ .../structure/expected/typeExtension.res.txt | 12 ++ .../printer/structure/multilineSpacing.res | 46 ++++++++ .../printer/typeDef/expected/abstract.res.txt | 1 + .../typeDef/expected/attributes.res.txt | 3 + .../expected/inlineRecordMultiline.res.txt | 1 + .../printer/typeDef/expected/record.res.txt | 4 + .../printer/typeDef/expected/variant.res.txt | 7 ++ .../printer/typexpr/expected/arrow.res.txt | 2 + .../printer/typexpr/expected/bsObject.res.txt | 3 + .../typexpr/expected/firstClassModule.res.txt | 1 + .../expected/objectTypeSpreading.res.txt | 2 + .../typexpr/expected/typeConstr.res.txt | 4 + .../printer/typexpr/expected/variant.res.txt | 4 + 117 files changed, 776 insertions(+), 25 deletions(-) create mode 100644 changes/formatter-multiline-item-spacing.polish.md create mode 100644 tests/syntax_tests/data/printer/signature/expected/multilineSpacing.resi.txt create mode 100644 tests/syntax_tests/data/printer/signature/multilineSpacing.resi create mode 100644 tests/syntax_tests/data/printer/structure/expected/multilineSpacing.res.txt create mode 100644 tests/syntax_tests/data/printer/structure/multilineSpacing.res diff --git a/changes/formatter-multiline-item-spacing.polish.md b/changes/formatter-multiline-item-spacing.polish.md new file mode 100644 index 00000000000..35142e74164 --- /dev/null +++ b/changes/formatter-multiline-item-spacing.polish.md @@ -0,0 +1 @@ +- Format a blank line before and after a top-level or module-level item that spans several lines. diff --git a/compiler/syntax/src/res_doc.ml b/compiler/syntax/src/res_doc.ml index e2222c22882..14369d3c0e9 100644 --- a/compiler/syntax/src/res_doc.ml +++ b/compiler/syntax/src/res_doc.ml @@ -23,6 +23,8 @@ type t = | Group of {mutable should_break: bool; doc: t} | CustomLayout of t list | BreakParent + | ItemSeparator of {prev: t; next: t} (* see [item_separator] *) + | Comment of t (* see [comment] *) let nil = Nil let line = LineBreak Classic @@ -52,6 +54,8 @@ let group d = Group {should_break = false; doc = d} let breakable_group ~force_break d = Group {should_break = force_break; doc = d} let custom_layout gs = CustomLayout gs let break_parent = BreakParent +let item_separator ~prev ~next = ItemSeparator {prev; next} +let comment d = Comment d let space = Text " " let comma = Text "," @@ -75,9 +79,9 @@ let propagate_forced_breaks doc = match doc with | Text _ | Nil | LineSuffix _ -> false | BreakParent -> true - | LineBreak (Hard | Literal) -> true + | LineBreak (Hard | Literal) | ItemSeparator _ -> true | LineBreak (Classic | Soft) -> false - | Indent children -> + | Indent children | Comment children -> let child_forces_break = walk children in child_forces_break | IfBreaks ({yes = true_doc; no = false_doc} as ib) -> @@ -115,9 +119,12 @@ let propagate_forced_breaks doc = (* See documentation in interface file *) let rec will_break doc = match doc with - | LineBreak (Hard | Literal) | BreakParent | Group {should_break = true} -> + | LineBreak (Hard | Literal) + | BreakParent | ItemSeparator _ + | Group {should_break = true} -> true - | Group {doc} | Indent doc | CustomLayout (doc :: _) -> will_break doc + | Group {doc} | Indent doc | Comment doc | CustomLayout (doc :: _) -> + will_break doc | Concat docs -> List.exists will_break docs | IfBreaks {yes; no} -> will_break yes || will_break no | _ -> false @@ -151,10 +158,12 @@ let fits w stack = | _, Nil | _, LineSuffix _ | _, BreakParent -> () | _, Text txt -> width := width.contents - String.length txt | _, Indent doc -> calculate (indent + 2) mode doc + | _, Comment doc -> calculate indent mode doc | Flat, LineBreak Hard | Flat, LineBreak Literal -> result := Some true | Flat, LineBreak Classic -> width := width.contents - 1 | Flat, LineBreak Soft -> () | Break, LineBreak _ -> result := Some true + | _, ItemSeparator _ -> result := Some true | _, Group {should_break = true; doc} -> calculate indent Break doc | _, Group {doc} -> calculate indent mode doc | _, IfBreaks {yes = break_doc; broken = true} -> @@ -184,6 +193,61 @@ let fits w stack = in calculate_all stack +let select_custom_layout ~width ~pos ind rest docs = + let rec find_group_that_fits groups = + match groups with + | [] -> Nil + | [last_group] -> last_group + | doc :: docs -> + if fits (width - pos) ((ind, Flat, doc) :: rest) then doc + else find_group_that_fits docs + in + find_group_that_fits docs + +(* Whether [doc], printed from the start of a line indented by [ind], spans more + than one line. Takes the layout decisions of [to_string] up to the first line + break. Comments and line suffixes do not count. *) +let spans_lines ~width ind mode doc = + let rec loop ~pos stack = + match stack with + | [] -> false + | (ind, mode, doc) :: rest -> ( + match doc with + | Nil | BreakParent | LineSuffix _ | Comment _ -> loop ~pos rest + | Text txt -> + String.contains txt '\n' || loop ~pos:(pos + String.length txt) rest + | Concat docs -> + loop ~pos (List.map (fun doc -> (ind, mode, doc)) docs @ rest) + | Indent doc -> loop ~pos ((ind + 2, mode, doc) :: rest) + | IfBreaks {yes; no; broken} -> + let doc = if broken || mode = Break then yes else no in + loop ~pos ((ind, mode, doc) :: rest) + | LineBreak (Hard | Literal) | ItemSeparator _ -> true + | LineBreak Classic -> mode = Break || loop ~pos:(pos + 1) rest + | LineBreak Soft -> mode = Break || loop ~pos rest + | Group {should_break; doc} -> + let flat = (ind, Flat, doc) :: rest in + if should_break || not (fits (width - pos) flat) then + loop ~pos ((ind, Break, doc) :: rest) + else loop ~pos flat + | CustomLayout docs -> + let doc = select_custom_layout ~width ~pos ind rest docs in + loop ~pos ((ind, Flat, doc) :: rest)) + in + loop ~pos:ind [(ind, mode, doc)] + +(* Own-line trailing comments are line suffixes that start with a hard line. *) +let starts_with_hard_line doc = + match doc with + | LineBreak Hard | Concat (LineBreak Hard :: _) -> true + | _ -> false + +let rec drop_leading_hard_lines doc = + match doc with + | LineBreak Hard -> Nil + | Concat (LineBreak Hard :: docs) -> drop_leading_hard_lines (Concat docs) + | doc -> doc + let to_string ~width doc = propagate_forced_breaks doc; let buffer = Mini_buffer.create 1000 in @@ -201,6 +265,7 @@ let to_string ~width doc = let ops = List.map (fun doc -> (ind, mode, doc)) docs in process ~pos line_suffices (List.append ops rest) | Indent doc -> process ~pos line_suffices ((ind + 2, mode, doc) :: rest) + | Comment doc -> process ~pos line_suffices ((ind, mode, doc) :: rest) | IfBreaks {yes = break_doc; broken = true} -> process ~pos line_suffices ((ind, mode, break_doc) :: rest) | IfBreaks {yes = break_doc; no = flat_doc} -> @@ -243,16 +308,28 @@ let to_string ~width doc = then process ~pos line_suffices ((ind, Break, doc) :: rest) else process ~pos line_suffices ((ind, Flat, doc) :: rest) | CustomLayout docs -> - let rec find_group_that_fits groups = - match groups with - | [] -> Nil - | [last_group] -> last_group - | doc :: docs -> - if fits (width - pos) ((ind, Flat, doc) :: rest) then doc - else find_group_that_fits docs - in - let doc = find_group_that_fits docs in - process ~pos line_suffices ((ind, Flat, doc) :: rest)) + let doc = select_custom_layout ~width ~pos ind rest docs in + process ~pos line_suffices ((ind, Flat, doc) :: rest) + | ItemSeparator {prev; next} -> + if spans_lines ~width ind mode prev || spans_lines ~width ind mode next + then + (* Own-line trailing comments of [prev] go below the blank line, where + they print once they are leading comments of [next]. *) + let separator = (ind, mode, hard_line) in + let same_line, below = + List.partition + (fun (_, _, doc) -> not (starts_with_hard_line doc)) + (List.rev line_suffices) + in + let rest = + match below with + | [] -> rest + | (ind, mode, doc) :: below -> + ((ind, mode, drop_leading_hard_lines doc) :: below) + @ (separator :: rest) + in + process ~pos (List.rev same_line) (separator :: separator :: rest) + else process ~pos line_suffices ((ind, mode, hard_line) :: rest)) | [] -> ( match line_suffices with | [] -> () @@ -332,6 +409,8 @@ let debug t = | Literal -> "Literal" in text ("LineBreak(" ^ break_txt ^ ")") + | ItemSeparator _ -> text "ItemSeparator" + | Comment doc -> concat [text "comment("; to_doc doc; text ")"] | Group {should_break; doc} -> group (concat @@ -356,5 +435,5 @@ let is_nil doc = match doc with | Nil -> true | Text _ | LineSuffix _ | Concat _ | Indent _ | IfBreaks _ | LineBreak _ - | Group _ | CustomLayout _ | BreakParent -> + | Group _ | CustomLayout _ | BreakParent | ItemSeparator _ | Comment _ -> false diff --git a/compiler/syntax/src/res_doc.mli b/compiler/syntax/src/res_doc.mli index d3423658c04..805b7748aa2 100644 --- a/compiler/syntax/src/res_doc.mli +++ b/compiler/syntax/src/res_doc.mli @@ -18,6 +18,15 @@ val breakable_group : force_break:bool -> t -> t * will be checked until one fits. *) val custom_layout : t list -> t val break_parent : t + +val item_separator : prev:t -> next:t -> t +(** A hard line, and a blank line when [prev] or [next], the documents printed + on each side of it, span several lines. It measures them but does not print + them. *) + +val comment : t -> t +(** Prints like its argument, which [item_separator] does not measure. *) + val join : sep:t -> t list -> t (* [(doc1, sep1); (doc2,sep2)] joins as doc1 sep1 doc2 *) diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 8c0424b1ba3..fede41d2f6e 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -326,10 +326,8 @@ let print_leading_comments node tbl loc = else if diff > 1 then Doc.concat [Doc.hard_line; Doc.hard_line] else Doc.hard_line in - let doc = - Doc.group - (Doc.concat [Doc.concat (List.rev (cmt_doc :: acc)); separator; node]) - in + let comments = Doc.concat (List.rev (separator :: cmt_doc :: acc)) in + let doc = Doc.group (Doc.concat [Doc.comment comments; node]) in doc | comment :: (next_comment :: _comments as rest) -> let cmt_doc = print_leading_comment ~next_comment comment in @@ -387,7 +385,9 @@ let print_comments_before_marker doc (tbl : Comment_table.t) loc marker = Hashtbl.replace tbl.trailing loc after_marker; print_trailing_comments doc tbl.trailing loc -let print_list ~get_loc ~nodes ~print ?(force_break = false) t = +(* [~space_multiline] adds a blank line next to nodes printed on several lines *) +let print_list ~get_loc ~nodes ~print ?(force_break = false) + ?(space_multiline = false) t = let rec loop first_loc_opt prev_loc_opt acc nodes = match nodes with | [] -> (first_loc_opt, prev_loc_opt, Doc.concat (List.rev acc)) @@ -403,12 +403,14 @@ let print_list ~get_loc ~nodes ~print ?(force_break = false) t = else let doc = print_comments raw_doc t loc in let acc = - match prev_loc_opt with - | None -> [doc] - | Some prev_loc -> + match (prev_loc_opt, acc) with + | None, _ | _, [] -> [doc] + | Some prev_loc, prev_doc :: _ -> let sep = if start_pos.pos_lnum - prev_loc.Location.loc_end.pos_lnum > 1 then Doc.concat [Doc.hard_line; Doc.hard_line] + else if space_multiline then + Doc.item_separator ~prev:prev_doc ~next:doc else Doc.hard_line in doc :: sep :: acc @@ -690,7 +692,7 @@ let rec print_structure ~state (s : Parsetree.structure) t = | [] -> print_comments_inside_file t | structure -> let previous_can_continue = ref false in - print_list + print_list ~space_multiline:true ~get_loc:(fun s -> s.Parsetree.pstr_loc) ~nodes:structure ~print:(fun item cmt_tbl -> @@ -1108,7 +1110,7 @@ and print_signature ~state signature cmt_tbl = match signature with | [] -> print_comments_inside_file cmt_tbl | signature -> - print_list + print_list ~space_multiline:true ~get_loc:(fun s -> s.Parsetree.psig_loc) ~nodes:signature ~print:(print_signature_item ~state) diff --git a/tests/syntax_tests/data/ast-mapping/expected/Braces.res.txt b/tests/syntax_tests/data/ast-mapping/expected/Braces.res.txt index 94ec22a3e38..32986b560c3 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/Braces.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/Braces.res.txt @@ -1,9 +1,11 @@ let value = {42} + let branch = if true { 1 } else { 2 } + let case = switch value { | 42 => value | _ => 0 diff --git a/tests/syntax_tests/data/ast-mapping/expected/FunctionsAndArrows.res.txt b/tests/syntax_tests/data/ast-mapping/expected/FunctionsAndArrows.res.txt index 508c2860fb2..4763329d388 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/FunctionsAndArrows.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/FunctionsAndArrows.res.txt @@ -7,6 +7,7 @@ let id = x => x // labeled, optional, and default parameters let labeled = (~x, ~y) => x - y + let optional = (~x=?, ~y=1, z) => { switch x { | Some(x) => x + y + z diff --git a/tests/syntax_tests/data/ast-mapping/expected/JSXElements.res.txt b/tests/syntax_tests/data/ast-mapping/expected/JSXElements.res.txt index 835aab0f9f5..2cbfcb9c121 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/JSXElements.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/JSXElements.res.txt @@ -39,7 +39,9 @@ let elementWithConditionalChildren = ReactDOM.jsx( }), }, ) + let commentOnly = ReactDOM.jsx("div", {/* no child */}) + let commentsBetweenElements = ReactDOM.jsx( "div", { diff --git a/tests/syntax_tests/data/ast-mapping/expected/JSXFragments.res.txt b/tests/syntax_tests/data/ast-mapping/expected/JSXFragments.res.txt index b80a42ace16..e2c9e22a1e2 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/JSXFragments.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/JSXFragments.res.txt @@ -22,7 +22,9 @@ let nestedFragments = React.jsxs( ]), }, ) + let commentOnly = React.jsx(React.jsxFragment, {}) // no child + let commentsBetweenElements = React.jsxs( React.jsxFragment /* between */, {children: React.array([ReactDOM.jsx("span", {}), ReactDOM.jsx("span", {})])}, diff --git a/tests/syntax_tests/data/ast-mapping/expected/JsxComponents.res.txt b/tests/syntax_tests/data/ast-mapping/expected/JsxComponents.res.txt index b463e41a075..a2383bfba1e 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/JsxComponents.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/JsxComponents.res.txt @@ -3,7 +3,9 @@ module A = { type props<'x> = { x: 'x, } + let make = ({x, _}: props<_>): React.element => React.string(x) + let make = React.component({ let \"JsxComponents$A" = (props: props<_>) => make(props) \"JsxComponents$A" @@ -15,6 +17,7 @@ module B = { /** Doc */ @deprecated @genType let make = ({x, _}: props): React.element => React.string(x) + /** Doc */ @deprecated @genType let make = React.component({ @@ -26,6 +29,7 @@ module B = { module C = { let make = (props: props): React.element => React.string(props.x) + let make = React.component({ let \"JsxComponents$C" = (props: props): React.element => make(props) \"JsxComponents$C" @@ -34,6 +38,7 @@ module C = { module D = { let make = (props: props): React.element => React.string(props.x) + let make = React.component({ let \"JsxComponents$D" = (props: props): React.element => make(props) \"JsxComponents$D" @@ -57,6 +62,7 @@ module F: { } let make: React.component> + @jsx.componentWithProps let other: props => React.element } = { @@ -66,6 +72,7 @@ module F: { } let make = ({x, _}: props<_>): React.element => React.string(x) + let make = React.component({ let \"JsxComponents$F" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ast-mapping/expected/RawExtensions.res.txt b/tests/syntax_tests/data/ast-mapping/expected/RawExtensions.res.txt index 3b21442b871..6e9b07042e1 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/RawExtensions.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/RawExtensions.res.txt @@ -1,7 +1,9 @@ let add = %raw("(a, b) => a + b") + let template = %raw(`function (a) { return "x" + a }`) + let escaped = %raw(`"a\`b\${c}"`) let fn = %ffi("(a) => a + 1") let applied = %ffi(`(a, b) => a * b`)(2, 3) diff --git a/tests/syntax_tests/data/ast-mapping/expected/TernaryExpressions.res.txt b/tests/syntax_tests/data/ast-mapping/expected/TernaryExpressions.res.txt index 3fb4f4dbcaf..2c2c02bb2a4 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/TernaryExpressions.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/TernaryExpressions.res.txt @@ -2,6 +2,7 @@ let choose = (condition, yes, no) => condition ? yes : no let nested = (first, second, a, b, c) => first ? a : second ? b : c let inCondition = (first, second, a, b, c) => (first ? second : false) ? a : b + c + let mixed = (condition, yes, no) => if condition { condition ? yes : no diff --git a/tests/syntax_tests/data/ast-mapping/expected/regexp.res.txt b/tests/syntax_tests/data/ast-mapping/expected/regexp.res.txt index 5818664601b..16806da9d3b 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/regexp.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/regexp.res.txt @@ -4,8 +4,10 @@ let characterClass = /[/\]]+/u let unicode = /世界+/g let dot = /./s let flags = /a/dgimsuy + @foo let attributed = /a/g + let comments = [/* before */ /a/g /* after */, /b/] let use = f(/a/i, /b/m) let expressionAttributes = @foo /a/g diff --git a/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt b/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt index 241cb963078..c7dc9e340d6 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt @@ -15,6 +15,7 @@ type state = { module Styles = { open Css + let terminal = style(list{ margin(10->px), backgroundColor("222"->hex), @@ -26,7 +27,9 @@ module Styles = { fontFamily(#custom(Theme.codeFontFamily)), unsafe("WebkitOverflowScrolling", "touch"), }) + let line = style(list{whiteSpace(#preWrap)}) + let input = style(list{ backgroundColor("222"->hex), fontFamily(#custom(Theme.codeFontFamily)), @@ -37,6 +40,7 @@ module Styles = { padding(zero), outlineStyle(none), }) + let title = style(list{ fontSize(48->px), fontWeight(extraBold), diff --git a/tests/syntax_tests/data/conversion/reason/expected/comments.res.txt b/tests/syntax_tests/data/conversion/reason/expected/comments.res.txt index 948e3ba49be..5065f0e7637 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/comments.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/comments.res.txt @@ -5,6 +5,7 @@ let /* a */ x /* b */ = /* c */ 1 /* comment 2 */ // comment 4 let x = 1 /* 5 */ + /* 6 */ let f = ( @@ -18,6 +19,7 @@ let f = ( // 7 y: 2, // 8 } + /* **** comment */ /* ** comment */ /* comment */ @@ -68,6 +70,7 @@ type variant = | X(int) /* End of line on X */ /* Comment above Y */ | Y(int) /* End of line on Y */ + /* Comment on entire type def for variant */ type rec x = { @@ -139,12 +142,14 @@ let store_attributes = arg => { Temp.logIt(proc_name, ()) } } + 3 // - 3 //- 3 //- 3 /* - */ + // **** comment /* ** comment */ @ocaml.doc(" docstring ") @@ -290,6 +295,7 @@ type t3 = (int, int) // End of line on (int, int) type variant = | X(int, int) // End of line on X | Y(int, int) // End of line on Y + // Comment on entire type def for variant // Before let @@ -421,6 +427,7 @@ let result = @ocaml.doc("") (2 + 3) // }; let a = () + for i in 0 to 10 { // bla a @@ -434,6 +441,7 @@ type color = | Red(int) // After red end of line | Black(int) // After black end of line | Green(int) // After green end of line + // On next line after color type def let blahCurriedX = (x, x) => @@ -445,6 +453,7 @@ let blahCurriedX = (x, x) => | Black(x) => 0 // After black | Green(x) => 0 } // After second green + // On next line after blahCurriedX def let name_equal = (x, y) => x == y @@ -631,6 +640,7 @@ while trueThing { // does work ) } + while trueThing { f( // a @@ -661,6 +671,7 @@ ignore((_xxx, _yyy) => { type tester<'a, 'b> = | TwoArgsConstructor('a, 'b) | OneTupleArgConstructor(('a, 'b)) + let callFunctionTwoArgs = (a, b) => () let callFunctionOneTuple = tuple => () diff --git a/tests/syntax_tests/data/conversion/reason/expected/modType.res.txt b/tests/syntax_tests/data/conversion/reason/expected/modType.res.txt index 260265ccf4d..a3454a224b9 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/modType.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/modType.res.txt @@ -1,12 +1,14 @@ module Same = (Na: N, Nb: N): ((S with type number1 = Na.number) with type number2 = Nb.number) => { type number1 = Na.number type number2 = Nb.number + let rec sim = ((n, m)) => if Na.is_zero(n) { Nb.is_zero(m) } else { sim((Na.pred(n), Nb.pred(m))) } + let similar = ((n, m)) => try sim((n, m)) catch { | Na.Too_small => false diff --git a/tests/syntax_tests/data/conversion/reason/expected/ppx.res.txt b/tests/syntax_tests/data/conversion/reason/expected/ppx.res.txt index 3f0dda10e0a..3800c8052d9 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/ppx.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/ppx.res.txt @@ -10,6 +10,7 @@ } } ` + {taggedTemplate: false} ) @@ -21,7 +22,9 @@ module Form = %form( @as("form-name") formName: string, } + type output = input + let validators = { name: { strategy: OnFirstBlur, diff --git a/tests/syntax_tests/data/ppx/react/expected/aliasProps.res.txt b/tests/syntax_tests/data/ppx/react/expected/aliasProps.res.txt index cf1e0bc6ad1..f85b0d3f5b3 100644 --- a/tests/syntax_tests/data/ppx/react/expected/aliasProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/aliasProps.res.txt @@ -15,6 +15,7 @@ module C0 = { let text = __text_value (React.string(text): React.element) } + let make = React.component({ let \"AliasProps$C0" = (props: props<_>) => make(props) @@ -37,6 +38,7 @@ module C1 = { let text = __text_value (React.string(p ++ text): React.element) } + let make = React.component({ let \"AliasProps$C1" = (props: props<_>) => make(props) @@ -58,6 +60,7 @@ module C2 = { let bar = __foo_value (React.string(bar): React.element) } + let make = React.component({ let \"AliasProps$C2" = (props: props<_>) => make(props) @@ -90,6 +93,7 @@ module C3 = { }: React.element ) } + let make = React.component({ let \"AliasProps$C3" = (props: props<_>) => make(props) @@ -112,6 +116,7 @@ module C4 = { let x = __x_value (ReactDOM.jsx("div", {children: ?ReactDOM.someElement(b)}): React.element) } + let make = React.component({ let \"AliasProps$C4" = (props: props<_>) => make(props) @@ -134,6 +139,7 @@ module C5 = { let z = __z_value (x + y + z: React.element) } + let make = React.component({ let \"AliasProps$C5" = (props: props<_>) => make(props) @@ -148,6 +154,7 @@ module C6 = { let make: React.component } + @res.jsxComponentProps type props<'comp, 'x> = { comp: 'comp, @@ -156,6 +163,7 @@ module C6 = { let make = ({comp: module(Comp: Comp), x: (a, b), _}: props<_, _>): React.element => React.jsx(Comp.make, {}) + let make = React.component({ let \"AliasProps$C6" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt b/tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt index f0dce005e25..d9e7f3b5eb0 100644 --- a/tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt @@ -10,6 +10,7 @@ module C0 = { let a = await f(a) ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})}) } + let make = React.component({ let \"AsyncAwait$C0" = (props: props<_>) => Jsx.promise(make(props)) @@ -29,6 +30,7 @@ module C1 = { | #off => React.string("off") } } + let make = React.component({ let \"AsyncAwait$C1" = (props: props<_>) => Jsx.promise(make(props)) @@ -46,6 +48,7 @@ module Braced = { let a = await f(a) ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})}) } + let make = React.component({ let \"AsyncAwait$Braced" = (props: props<_>) => Jsx.promise(make(props)) diff --git a/tests/syntax_tests/data/ppx/react/expected/commentAtTop.res.txt b/tests/syntax_tests/data/ppx/react/expected/commentAtTop.res.txt index 033f9b418d6..c0a48e04662 100644 --- a/tests/syntax_tests/data/ppx/react/expected/commentAtTop.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/commentAtTop.res.txt @@ -6,6 +6,7 @@ type props<'msg> = { let make = ({msg, _}: props<_>): React.element => { ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})}) } + let make = React.component({ let \"CommentAtTop" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/defaultPatternProp.res.txt b/tests/syntax_tests/data/ppx/react/expected/defaultPatternProp.res.txt index b1ea9117691..ddf93b36486 100644 --- a/tests/syntax_tests/data/ppx/react/expected/defaultPatternProp.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/defaultPatternProp.res.txt @@ -6,6 +6,7 @@ module C0 = { type props = {} let make = (_: props): React.element => React.null + let make = React.component({ let \"DefaultPatternProp$C0$M" = props => make(props) @@ -14,6 +15,7 @@ module C0 = { } module type S = module type of M + @res.jsxComponentProps type props<'component> = { component?: 'component, @@ -27,6 +29,7 @@ module C0 = { let module(C: S) = __component_value (React.jsx(C.make, {}): React.element) } + let make = React.component({ let \"DefaultPatternProp$C0" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/defaultValueProp.res.txt b/tests/syntax_tests/data/ppx/react/expected/defaultValueProp.res.txt index 5406c7724d4..ba31d682b2e 100644 --- a/tests/syntax_tests/data/ppx/react/expected/defaultValueProp.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/defaultValueProp.res.txt @@ -4,6 +4,7 @@ module C0 = { a?: 'a, b?: 'b, } + let make = ({a: ?__a, b: ?__b, _}: props<_, _>) => { let __a_value = switch __a { | Some(a) => a @@ -17,6 +18,7 @@ module C0 = { let b = __b_value (React.int(a + b): React.element) } + let make = React.component({ let \"DefaultValueProp$C0" = (props: props<_>) => make(props) \"DefaultValueProp$C0" @@ -38,6 +40,7 @@ module C1 = { let a = __a_value (React.int(a + b): React.element) } + let make = React.component({ let \"DefaultValueProp$C1" = (props: props<_>) => make(props) @@ -47,6 +50,7 @@ module C1 = { module C2 = { let a = "foo" + @res.jsxComponentProps type props<'a> = { a?: 'a, @@ -60,6 +64,7 @@ module C2 = { let a = __a_value (React.string(a): React.element) } + let make = React.component({ let \"DefaultValueProp$C2" = (props: props<_>) => make(props) @@ -85,6 +90,7 @@ module C3 = { }: React.element ) } + let make = React.component({ let \"DefaultValueProp$C3" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/fileLevelConfig.res.txt b/tests/syntax_tests/data/ppx/react/expected/fileLevelConfig.res.txt index 2cd52b3ac31..eeec4feefd4 100644 --- a/tests/syntax_tests/data/ppx/react/expected/fileLevelConfig.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/fileLevelConfig.res.txt @@ -9,6 +9,7 @@ module V4A = { let make = ({msg, _}: props<_>): Preact.element => { Preact.Elements.jsx("div", {children: ?Preact.Elements.someElement({msg->React.string})}) } + let make = Preact.component({ let \"FileLevelConfig$V4A" = (props: props<_>) => make(props) 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 feabbdaf5f4..1b0812a8c6c 100644 --- a/tests/syntax_tests/data/ppx/react/expected/firstClassModules.resi.txt +++ b/tests/syntax_tests/data/ppx/react/expected/firstClassModules.resi.txt @@ -5,6 +5,7 @@ module Select: { type key type t } + @res.jsxComponentProps type props<'model, 'selected, 'onChange, 'items> = { model: 'model, 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 f23f859040f..34b6281e1c7 100644 --- a/tests/syntax_tests/data/ppx/react/expected/forwardRef.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/forwardRef.res.txt @@ -29,12 +29,14 @@ module V4A = { ]), }, ) + let make = React.forwardRef({ let \"ForwardRef$V4A$FancyInput" = (props: props<_>, ref) => make(props, ref) \"ForwardRef$V4A$FancyInput" }) } + @res.jsxComponentProps type props = {} @@ -50,6 +52,7 @@ module V4A = { }, ) } + let make = React.component({ let \"ForwardRef$V4A" = props => make(props) @@ -86,12 +89,14 @@ module V4AUncurried = { ]), }, ) + let make = React.forwardRef({ let \"ForwardRef$V4AUncurried$FancyInput" = (props: props<_>, ref) => make(props, ref) \"ForwardRef$V4AUncurried$FancyInput" }) } + @res.jsxComponentProps type props = {} @@ -107,6 +112,7 @@ module V4AUncurried = { }, ) } + let make = React.component({ let \"ForwardRef$V4AUncurried" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/fragment.res.txt b/tests/syntax_tests/data/ppx/react/expected/fragment.res.txt index 80c3bb1d868..67f207d12a5 100644 --- a/tests/syntax_tests/data/ppx/react/expected/fragment.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/fragment.res.txt @@ -2,21 +2,26 @@ let _ = React.jsx(React.jsxFragment, {}) let _ = React.jsx(React.jsxFragment, {children: ReactDOM.jsx("div", {})}) + let _ = React.jsxs( React.jsxFragment, {children: React.array([ReactDOM.jsx("div", {}), ReactDOM.jsx("div", {})])}, ) + let _ = React.jsx(React.jsxFragment, {children: React.jsx(React.jsxFragment, {})}) let _ = React.jsx(Z.make, {}) let _ = React.jsx(Z.make, {children: ReactDOM.jsx("div", {})}) let _ = React.jsx(Z.make, {a: "a", children: ReactDOM.jsx("div", {})}) + let _ = React.jsxs( Z.make, {children: React.array([ReactDOM.jsx("div", {}), ReactDOM.jsx("div", {})])}, ) + let _ = ReactDOM.jsx("div", {}) let _ = ReactDOM.jsx("div", {children: ?ReactDOM.someElement(ReactDOM.jsx("div", {}))}) let _ = ReactDOM.jsx("div", {id: "id", children: ?ReactDOM.someElement(ReactDOM.jsx("div", {}))}) + let _ = ReactDOM.jsxs( "div", {children: React.array([ReactDOM.jsx("div", {}), ReactDOM.jsx("div", {})])}, diff --git a/tests/syntax_tests/data/ppx/react/expected/interface.res.txt b/tests/syntax_tests/data/ppx/react/expected/interface.res.txt index 77b6e77aec2..6f9981a815f 100644 --- a/tests/syntax_tests/data/ppx/react/expected/interface.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/interface.res.txt @@ -3,7 +3,9 @@ module A = { type props<'x> = { x: 'x, } + let make = ({x, _}: props<_>): React.element => React.string(x) + let make = React.component({ let \"Interface$A" = (props: props<_>) => make(props) \"Interface$A" @@ -15,6 +17,7 @@ module NoProps = { type props = {} let make = (_: props): React.element => ReactDOM.jsx("div", {}) + let make = React.component({ let \"Interface$NoProps" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/interface.resi.txt b/tests/syntax_tests/data/ppx/react/expected/interface.resi.txt index d0cc914abf7..b819ab34647 100644 --- a/tests/syntax_tests/data/ppx/react/expected/interface.resi.txt +++ b/tests/syntax_tests/data/ppx/react/expected/interface.resi.txt @@ -3,6 +3,7 @@ module A: { type props<'x> = { x: 'x, } + let make: React.component> } diff --git a/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.res.txt b/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.res.txt index 266f97d3281..f3580c98d26 100644 --- a/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.res.txt @@ -3,6 +3,7 @@ type props<'x, 'ref> = { x: 'x, ref?: 'ref, } + let make = ( {x, _}: props, ref: nullable, @@ -10,6 +11,7 @@ let make = ( let _ = ref->Nullable.toOption->Belt.Option.map(ReactDOM.Ref.domRef) React.string(x) } + let make = React.forwardRef({ let \"InterfaceWithRef" = (props: props<_>, ref) => make(props, ref) \"InterfaceWithRef" diff --git a/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.resi.txt b/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.resi.txt index 462fa9d6404..cf547d26c66 100644 --- a/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.resi.txt +++ b/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.resi.txt @@ -3,4 +3,5 @@ type props<'x, 'ref> = { x: 'x, ref?: 'ref, } + let make: React.component> diff --git a/tests/syntax_tests/data/ppx/react/expected/mangleKeyword.res.txt b/tests/syntax_tests/data/ppx/react/expected/mangleKeyword.res.txt index fd905c590ba..78eb9d2bdc8 100644 --- a/tests/syntax_tests/data/ppx/react/expected/mangleKeyword.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/mangleKeyword.res.txt @@ -9,12 +9,14 @@ module C4A0 = { let make = ({@as("open") _open, @as("type") _type, _}: props<_, string>): React.element => React.string(_open) + let make = React.component({ let \"MangleKeyword$C4A0" = (props: props<_>) => make(props) \"MangleKeyword$C4A0" }) } + module C4A1 = { @res.jsxComponentProps @live type props<'T_open, 'T_type> = { diff --git a/tests/syntax_tests/data/ppx/react/expected/nested.res.txt b/tests/syntax_tests/data/ppx/react/expected/nested.res.txt index 4931436a500..35f584aad73 100644 --- a/tests/syntax_tests/data/ppx/react/expected/nested.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/nested.res.txt @@ -1,12 +1,14 @@ module Outer = { @res.jsxComponentProps type props = {} + let make = (_: props): React.element => { module Inner = { @res.jsxComponentProps type props = {} let make = (_: props): React.element => ReactDOM.jsx("div", {}) + let make = React.component({ let \"Nested$Outer" = props => make(props) @@ -16,6 +18,7 @@ module Outer = { React.jsx(Inner.make, {}) } + let make = React.component({ let \"Nested$Outer" = props => make(props) \"Nested$Outer" diff --git a/tests/syntax_tests/data/ppx/react/expected/newtype.res.txt b/tests/syntax_tests/data/ppx/react/expected/newtype.res.txt index 5873c71b31e..92408363a66 100644 --- a/tests/syntax_tests/data/ppx/react/expected/newtype.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/newtype.res.txt @@ -10,6 +10,7 @@ module V4A = { let make = (type a, {a, b, c, _}: props>, 'a>): React.element => ReactDOM.jsx("div", {}) + let make = React.component({ let \"Newtype$V4A" = (props: props<_>) => make(props) @@ -27,6 +28,7 @@ module V4A1 = { let make = (type x y, {a, b, c, _}: props, 'a>): React.element => ReactDOM.jsx("div", {}) + let make = React.component({ let \"Newtype$V4A1" = (props: props<_>) => make(props) @@ -48,6 +50,7 @@ module V4A2 = { module T = unpack(foo) ReactDOM.jsx("div", {}) } + let make = React.component({ let \"Newtype$V4A2" = (props: props<_>) => make(props) @@ -65,12 +68,14 @@ module V4A3 = { module T = unpack(foo: T with type t = a) foo } + let make = React.component({ let \"Newtype$V4A3" = (props: props<_>) => make(props) \"Newtype$V4A3" }) } + @res.jsxComponentProps type props<'x, 'q> = { x: 'x, @@ -78,6 +83,7 @@ type props<'x, 'q> = { } let make = ({x, q, _}: props<('a, 'b), 'a>): React.element => [fst(x), q] + let make = React.component({ let \"Newtype" = (props: props<_>) => make(props) @@ -93,6 +99,7 @@ module Uncurried = { } let make = (type a, {?foo, _}: props<_>): React.element => React.null + let make = React.component({ let \"Newtype$Uncurried" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/noPropsWithKey.res.txt b/tests/syntax_tests/data/ppx/react/expected/noPropsWithKey.res.txt index 443bb57c62e..1a481fa6780 100644 --- a/tests/syntax_tests/data/ppx/react/expected/noPropsWithKey.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/noPropsWithKey.res.txt @@ -5,6 +5,7 @@ module V4CA = { type props = {} let make = (_: props): React.element => ReactDOM.jsx("div", {}) + let make = React.component({ let \"NoPropsWithKey$V4CA" = props => make(props) @@ -34,6 +35,7 @@ module V4C = { ]), }, ) + let make = React.component({ let \"NoPropsWithKey$V4C" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/optimizeAutomaticMode.res.txt b/tests/syntax_tests/data/ppx/react/expected/optimizeAutomaticMode.res.txt index 7ccf95dfb35..6ce4b5e17e3 100644 --- a/tests/syntax_tests/data/ppx/react/expected/optimizeAutomaticMode.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/optimizeAutomaticMode.res.txt @@ -4,6 +4,7 @@ module User = { type t = {firstName: string, lastName: string} let format = user => "Dr." ++ user.lastName + @res.jsxComponentProps type props<'doctor> = { doctor: 'doctor, @@ -12,6 +13,7 @@ module User = { let make = ({doctor, _}: props<_>): React.element => { ReactDOM.jsx("h1", {id: "h1", children: ?ReactDOM.someElement({React.string(format(doctor))})}) } + let make = React.component({ let \"OptimizeAutomaticMode$User" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/optionalKeyType.res.txt b/tests/syntax_tests/data/ppx/react/expected/optionalKeyType.res.txt index 0420bce343e..16ee150124a 100644 --- a/tests/syntax_tests/data/ppx/react/expected/optionalKeyType.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/optionalKeyType.res.txt @@ -8,18 +8,21 @@ let _ = React.jsxKeyed(C.make, {}, ~key?, ()) let _ = ReactDOM.jsxKeyed("div", {}, ~key="k", ()) let _ = ReactDOM.jsxKeyed("div", {}, ~key=?Some("k"), ()) let _ = ReactDOM.jsxKeyed("div", {}, ~key?, ()) + let _ = ReactDOM.jsxsKeyed( "div", {children: React.array([ReactDOM.jsx("br", {}), ReactDOM.jsx("br", {})])}, ~key="k", (), ) + let _ = ReactDOM.jsxsKeyed( "div", {children: React.array([ReactDOM.jsx("br", {}), ReactDOM.jsx("br", {})])}, ~key=?Some("k"), (), ) + let _ = ReactDOM.jsxsKeyed( "div", {children: React.array([ReactDOM.jsx("br", {}), ReactDOM.jsx("br", {})])}, diff --git a/tests/syntax_tests/data/ppx/react/expected/returnConstraint.res.txt b/tests/syntax_tests/data/ppx/react/expected/returnConstraint.res.txt index 43e3ca14aef..ddd4b721102 100644 --- a/tests/syntax_tests/data/ppx/react/expected/returnConstraint.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/returnConstraint.res.txt @@ -5,6 +5,7 @@ module Standard = { type props = {} let make = (_: props): React.element => React.string("ok") + let make = React.component({ let \"ReturnConstraint$Standard" = props => make(props) @@ -17,6 +18,7 @@ module ForwardRef = { type props = {} let make = (_: props, _ref): React.element => ReactDOM.jsx("div", {}) + let make = React.forwardRef({ let \"ReturnConstraint$ForwardRef" = (props, ref) => make(props, ref) @@ -29,6 +31,7 @@ module WithProps = { let make = (props: props): React.element => ReactDOM.jsx("span", {children: ?ReactDOM.someElement({React.int(props.value)})}) + let make = React.component({ let \"ReturnConstraint$WithProps" = (props: props): React.element => make(props) \"ReturnConstraint$WithProps" @@ -41,6 +44,7 @@ module Async = { let make = async (_: props): React.element => ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.string("async")})}) + let make = React.component({ let \"ReturnConstraint$Async" = props => Jsx.promise(make(props)) diff --git a/tests/syntax_tests/data/ppx/react/expected/sharedProps.res.txt b/tests/syntax_tests/data/ppx/react/expected/sharedProps.res.txt index 34d29a757e4..202be4471b1 100644 --- a/tests/syntax_tests/data/ppx/react/expected/sharedProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/sharedProps.res.txt @@ -4,6 +4,7 @@ module V4A1 = { type props = sharedProps let make = ({x, y, _}: props): React.element => React.string(x ++ y) + let make = React.component({ let \"SharedProps$V4A1" = props => make(props) @@ -15,6 +16,7 @@ module V4A2 = { type props<'a> = sharedProps<'a> let make = ({x, y, _}: props<_>): React.element => React.string(x ++ y) + let make = React.component({ let \"SharedProps$V4A2" = (props: props<_>) => make(props) @@ -26,6 +28,7 @@ module V4A3 = { type props<'a> = sharedProps let make = ({x, y, _}: props<_>): React.element => React.string(x ++ y) + let make = React.component({ let \"SharedProps$V4A3" = (props: props<_>) => make(props) @@ -37,6 +40,7 @@ module V4A4 = { type props = sharedProps let make = ({x, y, _}: props): React.element => React.string(x ++ y) + let make = React.component({ let \"SharedProps$V4A4" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/sharedPropsWithProps.res.txt b/tests/syntax_tests/data/ppx/react/expected/sharedPropsWithProps.res.txt index 91eea5058fc..094cc964ddf 100644 --- a/tests/syntax_tests/data/ppx/react/expected/sharedPropsWithProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/sharedPropsWithProps.res.txt @@ -18,6 +18,7 @@ let f = a => Promise.resolve(a + a) module V4A1 = { type props = sharedProps let make = (props): React.element => React.string(props.x ++ props.y) + let make = React.component({ let \"SharedPropsWithProps$V4A1" = (props): React.element => make(props) \"SharedPropsWithProps$V4A1" @@ -27,6 +28,7 @@ module V4A1 = { module V4A2 = { type props = sharedProps let make = (props: props): React.element => React.string(props.x ++ props.y) + let make = React.component({ let \"SharedPropsWithProps$V4A2" = (props: props): React.element => make(props) \"SharedPropsWithProps$V4A2" @@ -36,6 +38,7 @@ module V4A2 = { module V4A3 = { type props<'a> = sharedProps<'a> let make = ({x, y}: props<_>): React.element => React.string(x ++ y) + let make = React.component({ let \"SharedPropsWithProps$V4A3" = (props: props<_>): React.element => make(props) \"SharedPropsWithProps$V4A3" @@ -45,6 +48,7 @@ module V4A3 = { module V4A4 = { type props<'a> = sharedProps let make = ({x, y}: props<_>): React.element => React.string(x ++ y) + let make = React.component({ let \"SharedPropsWithProps$V4A4" = (props: props<_>): React.element => make(props) \"SharedPropsWithProps$V4A4" @@ -53,10 +57,12 @@ module V4A4 = { module V4A5 = { type props<'a> = {a: 'a} + let make = async ({a}: props<_>): React.element => { let a = await f(a) ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})}) } + let make = React.component({ let \"SharedPropsWithProps$V4A5" = (props: props<_>): React.element => Jsx.promise(make(props)) \"SharedPropsWithProps$V4A5" @@ -65,12 +71,14 @@ module V4A5 = { module V4A6 = { type props<'status> = {status: 'status} + let make = async ({status}: props<_>): React.element => { switch status { | #on => React.string("on") | #off => React.string("off") } } + let make = React.component({ let \"SharedPropsWithProps$V4A6" = (props: props<_>): React.element => Jsx.promise(make(props)) \"SharedPropsWithProps$V4A6" @@ -83,6 +91,7 @@ module V4A7 = { let make = (props): React.element => { React.int(props.count) } + let make = React.component({ let \"SharedPropsWithProps$V4A7" = @directive("'use memo'") (props): React.element => make(props) @@ -95,6 +104,7 @@ module V4A8 = { // The payload has no effect; it is accepted with a deprecation warning. let make = (props): React.element => React.string(props.x) + let make = React.component({ let \"SharedPropsWithProps$V4A8" = (props): React.element => make(props) \"SharedPropsWithProps$V4A8" diff --git a/tests/syntax_tests/data/ppx/react/expected/topLevel.res.txt b/tests/syntax_tests/data/ppx/react/expected/topLevel.res.txt index bc712ece06e..886d36bce63 100644 --- a/tests/syntax_tests/data/ppx/react/expected/topLevel.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/topLevel.res.txt @@ -11,6 +11,7 @@ module V4A = { Console.log("This function should be named 'TopLevel.react'") ReactDOM.jsx("div", {}) } + let make = React.component({ let \"TopLevel$V4A" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/typeConstraint.res.txt b/tests/syntax_tests/data/ppx/react/expected/typeConstraint.res.txt index 491f5c7d191..8586b2d5d3a 100644 --- a/tests/syntax_tests/data/ppx/react/expected/typeConstraint.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/typeConstraint.res.txt @@ -8,6 +8,7 @@ module V4A = { } let make = (type a, {a, b, _}: props<_, _>): React.element => ReactDOM.jsx("div", {}) + let make = React.component({ let \"TypeConstraint$V4A" = (props: props<_>) => make(props) 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 9e635bafdd6..a7a1dff341a 100644 --- a/tests/syntax_tests/data/ppx/react/expected/uncurriedProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/uncurriedProps.res.txt @@ -1,4 +1,5 @@ @@jsxConfig({version: 4}) + @res.jsxComponentProps type props<'a> = { a?: 'a, @@ -12,6 +13,7 @@ let make = ({a: ?__a, _}: props unit>) => { let a: unit => unit = __a_value (React.null: React.element) } + let make = React.component({ let \"UncurriedProps" = (props: props<_>) => make(props) @@ -46,6 +48,7 @@ module Foo = { }: React.element ) } + let make = React.component({ let \"UncurriedProps$Foo" = (props: props<_>) => make(props) @@ -58,6 +61,7 @@ module Bar = { type props = {} let make = (_: props): React.element => React.jsx(Foo.make, {callback: {(_, _, _) => ()}}) + let make = React.component({ let \"UncurriedProps$Bar" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/v4.res.txt b/tests/syntax_tests/data/ppx/react/expected/v4.res.txt index a23517ad7dd..dbf4c5c06a6 100644 --- a/tests/syntax_tests/data/ppx/react/expected/v4.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/v4.res.txt @@ -3,7 +3,9 @@ type props<'x, 'y> = { x: 'x, // Component with type constraint y: 'y, } + let make = ({x, y, _}: props): React.element => React.string(x ++ y) + let make = React.component({ let \"V4" = (props: props<_>) => make(props) \"V4" @@ -16,6 +18,7 @@ module Braced = { } let make = ({name, _}: props<_>): React.element => React.string(name) + let make = React.component({ let \"V4$Braced" = (props: props<_>) => make(props) @@ -31,6 +34,7 @@ module AnotherName = { } let anotherName = ({x, _}: props<_>): React.element => React.string(x) + let anotherName = React.component({ let \"V4$AnotherName$anotherName" = (props: props<_>) => anotherName(props) @@ -45,6 +49,7 @@ module Uncurried = { } let make = ({x, _}: props<_>): React.element => React.string(x) + let make = React.component({ let \"V4$Uncurried" = (props: props<_>) => make(props) @@ -86,6 +91,7 @@ module Rec = { let rec make = (_: props): React.element => { make(({}: props)) } + let make = React.component({ let \"V4$Rec" = props => make(props) @@ -100,6 +106,7 @@ module Rec1 = { let rec make = (_: props): React.element => { React.null } + let make = React.component({ let \"V4$Rec1" = props => make(props) @@ -116,6 +123,7 @@ module Rec2 = { } and mm = x => make(x) + let make = React.component({ let \"V4$Rec2" = props => make(props) diff --git a/tests/syntax_tests/data/printer/comments/expected/callbackTrailing.res.txt b/tests/syntax_tests/data/printer/comments/expected/callbackTrailing.res.txt index 852da869a7c..340e934d17a 100644 --- a/tests/syntax_tests/data/printer/comments/expected/callbackTrailing.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/callbackTrailing.res.txt @@ -50,13 +50,16 @@ let labeled = call(~fn=x => x /* keep labeled */) let optional = call(~fn=?x => x /* keep optional */) let labeledFirst = call(~fn=x => x /* keep first */, value) let optionalLast = call(value, ~fn=?x => x /* keep last */) + let labeledBelow = call( ~fn=x => x, /* keep below */ ) + let optionalLine = call( ~fn=?x => x, // keep line ) + let labeledNested = call(~fn=x => call(~fn=y => y /* keep nested */)) let leadingLabeled = call(/* keep leading label */ ~fn=x => x) @@ -71,11 +74,13 @@ outer(x => x => x, // keep nested line ) ) + outer(x => call( ~fn=x => x, // keep nested labeled line ) ) + outer(x => call( ~fn=?x => x, // keep nested optional line diff --git a/tests/syntax_tests/data/printer/comments/expected/expr.res.txt b/tests/syntax_tests/data/printer/comments/expected/expr.res.txt index 99434ca5865..6ebae0f227f 100644 --- a/tests/syntax_tests/data/printer/comments/expected/expr.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/expr.res.txt @@ -71,6 +71,7 @@ let x = (/* c0 */ "string" /* c1 */: /* c2 */ string /* c3 */) // after let x = /* before */ true /* after */ let x = /* before */ Red /* after */ let x = /* before */ Red(/* c0 */ shade /* c1 */) /* after */ + let x = /* before */ Red /* after Red */( /* c0 */ r /* c1 */, /* c2 */ g /* c3 */, @@ -93,6 +94,7 @@ let x = /* c0 */ list{/* c1 */ a /* c2 */, /* c3 */ b /* c4 */, /* c5 */ c /* c6 // Pexp_array let x = [/* c0 */ a /* c1 */, /* c2 */ b /* c3 */, /* c4 */ c /* c5 */] let x = [/* a */] + let x = [ // test ] @@ -213,6 +215,7 @@ for await /* c0 */ x /* c1 */ of /* c2 */ xs /* c3 */ { // Pexp_fun let f = (/* c0 */ a /* c1 */, /* c2 */ b /* c3 */): /* c4 */ int /* c5 */ => /* c6 */ 20 /* c7 */ + let multiply = (/* c0 */ m1 /* c1 */, /* c2 */ m2 /* c3 */) => { // here open Matrix4D @@ -236,6 +239,7 @@ let f = ( ) => () let multiply = (type /* c-2 */ t /* c-1 */, /* c0 */ m1 /* c1 */, /* c2 */ m2 /* c3 */) => () + let multiply = ( type /* c-4 */ t /* c-3 */ /* c-2 */ s /* c-1 */, /* c0 */ m1 /* c1 */, @@ -273,6 +277,7 @@ f(() => 1) f(_ => 1) // c2 f(a => 1) + // c3 f((~a) => // c4 @@ -311,6 +316,7 @@ Doc.concat( rows, /* a */ ) + Doc.concat(list{ privateFlag, rows, diff --git a/tests/syntax_tests/data/printer/comments/expected/modExpr.res.txt b/tests/syntax_tests/data/printer/comments/expected/modExpr.res.txt index d802464dec6..10142c27705 100644 --- a/tests/syntax_tests/data/printer/comments/expected/modExpr.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/modExpr.res.txt @@ -24,10 +24,12 @@ /* c6 */ Arg2 /* c7 */, /* c8 */ Arg3 /* c9 */, ) /* c10 */ + /* c0 */ module /* c1 */ X /* c2 */ = /* c3 */ F( /* c4 */ A /* c5 */: /* c6 */ SetLike /* c7 */, /* c7 */ B /* c8 */: /* c9 */ TreeLike /* c10 */, ) /* c11 */ + /* c0 */ module /* c1 */ S0 /* c2 */ = /* c3 */ Make /* c4 */(/* lbrace */ { type t = int /* c5 */ let eq /* c6 */ = (x, y) => x == y diff --git a/tests/syntax_tests/data/printer/comments/expected/modType.res.txt b/tests/syntax_tests/data/printer/comments/expected/modType.res.txt index 7f0ff61abc4..c319a2e029c 100644 --- a/tests/syntax_tests/data/printer/comments/expected/modType.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/modType.res.txt @@ -19,10 +19,12 @@ // Pmty_functor /* c0 */ module type /* c1 */ Functor /* c2 */ = /* c3 */ SetLike /* c4 */ => /* c5 */ Set /* c6 */ + module type Functor = /* before */ ( /* before S */ S /* after S */: /* before */ SetLike /* after */, /* before B */ B /* after B */: /* before */ BtreeLike /* after */, ) => /* before NeoTree */ NeoTree // after NeoTree + module type Functor = ( /* c0 */ /* c1 */ /* c2 */ SetLike /* c3 */, /* c4 */ /* c5 */ /* c6 */ BtreeLike /* c7 */, diff --git a/tests/syntax_tests/data/printer/comments/expected/namedArgs.res.txt b/tests/syntax_tests/data/printer/comments/expected/namedArgs.res.txt index c74b892f8a5..5f77a8b4789 100644 --- a/tests/syntax_tests/data/printer/comments/expected/namedArgs.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/namedArgs.res.txt @@ -80,6 +80,7 @@ let f = (~x /* a */ /* a2 */=? /* b */ /* b2 */, ~y) => x let f = (~x as y=? /* a */, ~z) => y let f = (~x=?, /* a */ ~y) => x let f = (~x=? /* a */, ~y) => x + let f = ( ~x: int /* a */=? /* b */, ~someLongParameterName, diff --git a/tests/syntax_tests/data/printer/comments/expected/pattern.res.txt b/tests/syntax_tests/data/printer/comments/expected/pattern.res.txt index 3b4a79fb8e0..2934955ae27 100644 --- a/tests/syntax_tests/data/printer/comments/expected/pattern.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/pattern.res.txt @@ -23,6 +23,7 @@ let /* here */ Black /* there */ = color let /* here */ Black(/* inside */) /* there */ = color let Black(/* inside */ /* inside2 */) = color let Black(/* inside */ /* inside2 */ /* inside 3 */) = color + let Black( // singleLineComment ) = color diff --git a/tests/syntax_tests/data/printer/comments/expected/structureItem.res.txt b/tests/syntax_tests/data/printer/comments/expected/structureItem.res.txt index 5dfc7e189e3..8ee240e95b4 100644 --- a/tests/syntax_tests/data/printer/comments/expected/structureItem.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/structureItem.res.txt @@ -6,6 +6,7 @@ // Pstr_include /* c0 */ include /* c1 */ Belt /* c2 */ + /* c0 */ include /* c1 */ { let a /* inside */ = 2 } /* c2 */ diff --git a/tests/syntax_tests/data/printer/comments/expected/typeDefinition.res.txt b/tests/syntax_tests/data/printer/comments/expected/typeDefinition.res.txt index 87ba674da8a..6e200d03ada 100644 --- a/tests/syntax_tests/data/printer/comments/expected/typeDefinition.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/typeDefinition.res.txt @@ -12,6 +12,7 @@ /* before */ type t = /* before manifest */ string /* after */ /* before */ type /* before name */ t /* after name */ = /* before manifest */ string /* after */ + /* before */ type /* before name */ t /* after name */< /* c0 */ 'err /* c1 */, /* c2 */ 'success /* c3 */, diff --git a/tests/syntax_tests/data/printer/comments/expected/typexpr.res.txt b/tests/syntax_tests/data/printer/comments/expected/typexpr.res.txt index c02f7ebe0b4..b428d5baa71 100644 --- a/tests/syntax_tests/data/printer/comments/expected/typexpr.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/typexpr.res.txt @@ -42,10 +42,12 @@ type add = /* before */ ( /* c0 */ int /* c1 */, /* c2 */ int /* c3 */, ) => /* before return */ int /* after */ + type add = /* before */ ( /* c0 */ ~a: int /* c1 */, /* c2 */ ~b: int /* c3 */, ) => /* before return */ int /* after */ + type multiply = /* before */ ( /* c0 */ ~fn: ( /* cinner0 */ int /* cinner1 */, @@ -53,6 +55,7 @@ type multiply = /* before */ ( ) => /* cx */ int /* c1 */, /* c2 */ ~b: int /* c3 */, ) => int /* after */ + type make = ( ~activity: ActivityFlow_Activity.t, ~showExpert: (string, string) => unit, @@ -95,6 +98,7 @@ external another_test: ( // comment 2 int, ) => unit = "test" + type optionalArg = (~x: int /* a */=?, unit) => int type lastOptionalArg = (~x: int /* a */=?) => int external optionalArgExternal: (~x: int /* a */=?, unit) => int = "f" @@ -103,6 +107,7 @@ type lastOptionalArgAfter = (~x: int=? /* a */) => int type optionalArgAround = (~x: int /* a */ /* a2 */=? /* b */, ~y: int) => int type optionalArgThenComma = (~x: int=?, /* a */ ~y: int) => int external optionalArgAfterExternal: (~x: int=? /* a */, unit) => int = "f" + type optionalArgAfterMultiline = ( ~x: int=? /* a */, ~someLongParameterName: int, diff --git a/tests/syntax_tests/data/printer/comments/expected/valueBindings.res.txt b/tests/syntax_tests/data/printer/comments/expected/valueBindings.res.txt index e5cac613d77..659594eab40 100644 --- a/tests/syntax_tests/data/printer/comments/expected/valueBindings.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/valueBindings.res.txt @@ -3,6 +3,7 @@ let x = 1 // leading snd value-binding and y = 2 + /* leading snd value-binding */ let walkList: 'node. unit = comments => { diff --git a/tests/syntax_tests/data/printer/expected/regexp.res.txt b/tests/syntax_tests/data/printer/expected/regexp.res.txt index b1d7791474b..44d55caca38 100644 --- a/tests/syntax_tests/data/printer/expected/regexp.res.txt +++ b/tests/syntax_tests/data/printer/expected/regexp.res.txt @@ -4,8 +4,10 @@ let characterClass = /[/\]]+/u let unicode = /世界+/g let dot = /./s let flags = /a/dgimsuy + @foo let attributed = /a/g + let comments = [/* before */ /a/g /* after */, /b/] let use = f(/a/i, /b/m) let expressionAttributes = @foo /a/g diff --git a/tests/syntax_tests/data/printer/expected/regexpStatements.res.txt b/tests/syntax_tests/data/printer/expected/regexpStatements.res.txt index a5193971eca..7ecd139add4 100644 --- a/tests/syntax_tests/data/printer/expected/regexpStatements.res.txt +++ b/tests/syntax_tests/data/printer/expected/regexpStatements.res.txt @@ -191,8 +191,10 @@ let afterOpenExpression = () => { } let beforeStatementAttribute = 0 + @foo /a/->ignore + /**Keep the documentation attribute.*/ /b/->ignore diff --git a/tests/syntax_tests/data/printer/expr/expected/DocComments.res.txt b/tests/syntax_tests/data/printer/expr/expected/DocComments.res.txt index 6f9b61a2bc1..2f24e1d0bc8 100644 --- a/tests/syntax_tests/data/printer/expr/expected/DocComments.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/DocComments.res.txt @@ -2,8 +2,10 @@ let doc1: ( /** ddd */ ~x: int, ) => int = (~x) => x + 1 + let doc2: /** ddd */ int => int = x => x + 1 let doc3: /** ddd */ int => int = x => x + 1 + let doc4: ( /** ddd */ ~x: int, diff --git a/tests/syntax_tests/data/printer/expr/expected/apply.res.txt b/tests/syntax_tests/data/printer/expr/expected/apply.res.txt index d506eb95381..3b26610af88 100644 --- a/tests/syntax_tests/data/printer/expr/expected/apply.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/apply.res.txt @@ -20,6 +20,7 @@ let cmp = rbt.compare2(Array.getUnsafe(old, oldIter.contents), longerNode.longVa let uncurriedUnit = apply() let coordinate = make2dCoordinate({x: 1, y: 2}) + let coordinate = make3dCoordinate({ ...base, field1: thisIsAPrettyLongNameHere, @@ -28,6 +29,7 @@ let coordinate = make3dCoordinate({ }) let coordinate = make2dCoordinateArray([x, y]) + let coordinate = make3dCoordinateArray([ thisIsAPrettyLongNameHere, thisIsAPrettyLongNameHere, @@ -35,6 +37,7 @@ let coordinate = make3dCoordinateArray([ ]) let coordinate = make2dCoordinateTuple((x, y)) + let coordinate = make3dCoordinateTuple(( thisIsAPrettyLongNameHere, thisIsAPrettyLongNameHere, @@ -42,6 +45,7 @@ let coordinate = make3dCoordinateTuple(( )) let coordinate = make2dCoordinateList(list{x, y}) + let coordinate = make3dCoordinateList(list{ thisIsAPrettyLongNameHere, thisIsAPrettyLongNameHere, @@ -50,6 +54,7 @@ let coordinate = make3dCoordinateList(list{ }) let coordinate = makeJsCoordinate({"x": 1, "y": 1}) + let user = makeJsUser({ "name": "steve", "age": 32, @@ -67,27 +72,35 @@ document.createElementWithOptions("div", elementProps(~onClick=_ => Console.log( f(1) f([1, 2, 3]) + f([ suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuperLong, suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuperLong, suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuperLong, ]) + f((1, 2, 3)) f({"a": 1}) f(list{1}) + f(` template string `) + f(`single line`) + f(" template string ") + f({ expr }) + f({expr}) + f({ exception Exit throw(Exit) diff --git a/tests/syntax_tests/data/printer/expr/expected/array.res.txt b/tests/syntax_tests/data/printer/expr/expected/array.res.txt index f317af7a860..01389f0d9f2 100644 --- a/tests/syntax_tests/data/printer/expr/expected/array.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/array.res.txt @@ -1,5 +1,6 @@ let x = [] let x = [a, b, c] + let x = [ superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, diff --git a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt index 93d7d60d5ca..6e191225776 100644 --- a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt @@ -21,6 +21,7 @@ let x = assert(apply(arg1, arg2)) let x = assert(-1) let x = assert(!true) let x = assert(x => print(x)) + let x = assert(switch x { | Blue => () | Yello => () diff --git a/tests/syntax_tests/data/printer/expr/expected/assignment.res.txt b/tests/syntax_tests/data/printer/expr/expected/assignment.res.txt index 887afd4b4c9..37d08c38184 100644 --- a/tests/syntax_tests/data/printer/expr/expected/assignment.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/assignment.res.txt @@ -2,10 +2,12 @@ f := { first: one, second: two, } + f.contents = { first: one, second: two, } + obj["value"] = { first: one, second: two, @@ -17,12 +19,14 @@ f := [ thirdVeryLongArrayElement, fourthVeryLongArrayElement, ] + f.contents = [ firstVeryLongArrayElement, secondVeryLongArrayElement, thirdVeryLongArrayElement, fourthVeryLongArrayElement, ] + obj["value"] = [ firstVeryLongArrayElement, secondVeryLongArrayElement, @@ -34,10 +38,12 @@ f := () => { doA() doB() } + f.contents = () => { doA() doB() } + obj["value"] = () => { doA() doB() @@ -47,10 +53,12 @@ f := @attr () => { doA() doB() } + f.contents = @attr () => { doA() doB() } + obj["value"] = @attr () => { doA() doB() @@ -61,11 +69,13 @@ f := | Some(value) => value | None => fallback } + f.contents = switch value { | Some(value) => value | None => fallback } + obj["value"] = switch value { | Some(value) => value @@ -73,27 +83,33 @@ obj["value"] = } f := firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand + f.contents = firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand + obj["value"] = firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand f := {firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand} + f.contents = { firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand } + obj["value"] = { firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand } // Assignments used as operands retain their grouping. let nested = (f := {first: one, second: two})->ignore + let field = ( f.contents = { first: one, second: two, } )->ignore + let object = ( obj["value"] = { first: one, diff --git a/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt b/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt index c02694d1508..8b9df042023 100644 --- a/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt @@ -48,16 +48,19 @@ let _ = await %extension let _ = await "test" let _ = await ((a, b) => a + b) let _ = await (async (a, b) => a + b) + let _ = await ( switch x { | A => () | B => () } ) + let _ = await [1, 2, 3] let _ = await (1, 2, 3) let _ = await {name: "Steve", age: 32} let _ = await (user.name = "Steve") + let _ = await ( if 20 { true @@ -65,25 +68,30 @@ let _ = await ( false } ) + let _ = await (condition() ? true : false) let _ = await f(x) let _ = await f(x) let _ = await (f(x): Promise.t) + let _ = await ( while true { infiniteLoop() } ) + let _ = await ( try ok() catch { | _ => logError() } ) + let _ = await ( for i in 0 to 10 { sideEffect() } ) + let _ = await (assert(x)) let _ = await promises[0] let _ = await promises["resolved"] @@ -96,6 +104,7 @@ let _ = await Promise(status) // braces are being dropped, because the ast only has space to record braces surrounding the await let _ = await x + // here braces stay, because of precedence let _ = await { let x = 1 diff --git a/tests/syntax_tests/data/printer/expr/expected/binary.res.txt b/tests/syntax_tests/data/printer/expr/expected/binary.res.txt index 2185cc1955f..669b2e887e2 100644 --- a/tests/syntax_tests/data/printer/expr/expected/binary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/binary.res.txt @@ -31,16 +31,19 @@ let x = foo ++ bar let x = 1 + 1 let x = (a => a + 1) + (b => b + 2) let x = -1 + -1 + let x = switch z { | Red => 1 }->switch y { | Blue => 2 } + let x = try z catch { | Exit => 1 }->try y catch { | Blue => 2 } + let x = if true { 1 @@ -51,6 +54,7 @@ let x = } else { 3 } + let x = for i in 0 to 10 { () }->for i in 0 to 10 { @@ -84,6 +88,7 @@ let rotateX = (range / rect.height * refY - range / 2) * getXMultiplication(rect let rotateY = (range / rect.width * refX - range / 2) * getYMultiplication(rect.width) let x = longIdentifier + longIdentifier + longIdentifier + let x = longIdentifier + longIdentifier + @@ -91,12 +96,14 @@ let x = longIdentifier - longIdentifier + longIdentifier + let x = longIdentifier + longIdentifier * longIdentifier + longIdentifier - longIdentifier + longIdentifier + let x = longIdentifier + longIdentifier * longIdentifier * longIdentifier / longIdentifier + @@ -109,6 +116,7 @@ let x = longIdentifier && longIdentifier && longIdentifier + let x = (longIdentifier && longIdentifier) || longIdentifier && longIdentifier || @@ -140,6 +148,7 @@ while continuePrefix.contents && aPrefixLen.contents <= aLen && bPrefixLen.conte let nextNonwhiteA = nextNonWhiteChar(aStr, 1, aPrefixLen.contents - 1) let nextNonwhiteB = nextNonWhiteChar(bStr, 1, bPrefixLen.contents - 1) } + let () = { let () = sideEffect() if ( @@ -205,12 +214,14 @@ let x = a && a.b let x = a && x.y && g.h let x = a && true let x = a && true && true + let x = a && { let a = true let b = true a || b } + let x = a && { @@ -244,6 +255,7 @@ let x = | Blue => "blue" | Red => "red" } + let x = a && switch color { @@ -292,6 +304,7 @@ let x = } else { false } + let x = a && if true { @@ -309,6 +322,7 @@ let x = sideEffect() do() } + let x = a && { @@ -323,6 +337,7 @@ let x = a && while true { do() } + let x = a && while true { @@ -335,6 +350,7 @@ let x = a && for i in 0 to 10 { true } + let x = a && for i in 0 to 10 { @@ -351,6 +367,7 @@ let x = module L = Log L.log() } + let x = a && { @@ -366,6 +383,7 @@ let x = exception Exit throw(Exit) } + let x = a && { @@ -384,6 +402,7 @@ let x = open React killPerform() } + let x = a && { @@ -462,6 +481,7 @@ x->(y->z) x->(y->(z->w)) let x = "z" ++ a->f ++ "x" + let toString = functionArgs => { functionArgs == [] ? "" : "<" ++ functionArgs->List.map(argToString)->String.concat(",") ++ ">" } @@ -521,5 +541,6 @@ let make = (~keycap) => + + Belt.Array.getExn(0) + @doesNotRaise []->Belt.Array.getExn(0) diff --git a/tests/syntax_tests/data/printer/expr/expected/block.res.txt b/tests/syntax_tests/data/printer/expr/expected/block.res.txt index f9331a10a51..3dff5c4b22e 100644 --- a/tests/syntax_tests/data/printer/expr/expected/block.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/block.res.txt @@ -18,6 +18,7 @@ let reifyStyle = (type a, x: 'a): (style, a) => { type rec constructor @val external canvasGradient: constructor = "CanvasGradient" /* internal */ @val external canvasPattern: constructor = "CanvasPattern" /* internal */ + let instanceOf = ( %raw(`function(x,y) {return +(x instanceof y)}`): ('a, constructor) => bool ) /* internal */ diff --git a/tests/syntax_tests/data/printer/expr/expected/braced.res.txt b/tests/syntax_tests/data/printer/expr/expected/braced.res.txt index aa0af975709..4d402d37596 100644 --- a/tests/syntax_tests/data/printer/expr/expected/braced.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/braced.res.txt @@ -29,16 +29,19 @@ let _ = {a} let _ = {"constant"} let _ = {() => Console.log("test")} + let _ = { switch b { | true => () | false => () } } + let _ = switch {b} { | true => () | false => () } + let _ = {apply(a, b)} let _ = {apply}(a, b) @@ -47,6 +50,7 @@ let _ = { | Exit => () } } + let _ = try {danger()} catch { | Exit => () } @@ -56,6 +60,7 @@ let _ = {({a}, {b}, {x + y})} let _ = {Rgb(r, g, b)} let _ = Rgb({r}, {g}, {b}) + let _ = Rgb( { r @@ -70,6 +75,7 @@ let _ = Rgb( let _ = {{name: "steve", age: 30}} let _ = {name: {"steve"}, age: {30}} + let _ = { name: { "steve" @@ -86,6 +92,7 @@ let _ = {{user.name}.first} let _ = {[a, b, c]} let _ = [{a}, {b}, {c}] + let _ = [ { a @@ -100,6 +107,7 @@ let _ = [ let _ = {list{a, b, c}} let _ = {list{{a}, {b}, {c}}} + let _ = { list{ { @@ -126,6 +134,7 @@ let _ = { () } } + let _ = { if {true} { () @@ -161,12 +170,15 @@ let _ = { () } } + let _ = while {true} { () } + while {/* c0 */ true /* c1 */} { () } + while ( { true @@ -174,6 +186,7 @@ while ( ) { () } + while ( { /* c0 */ true // c1 @@ -187,6 +200,7 @@ let _ = { () } } + for _ in { 0 } to { @@ -204,6 +218,7 @@ let localToGlobalX = ( ): coordinate => { x +. (Environment.width /. 2. -. centering.x) } + map((arr, i): coordinate => { x +. (Environment.width /. 2. -. centering.x) }) @@ -216,12 +231,15 @@ let _ = {module(ME)} let _ = {module(ME: MyMod)} {myArray}[{0}] + { myArray }[{ 0 }] + {myArray}[{0}] = {20} + { myArray }[{ @@ -236,6 +254,7 @@ myArray[20] = { {jsObject}["foo"] {jsObject}["foo"] = {"bar"} + {jsObject}["foo"] = { a + b } @@ -243,9 +262,11 @@ myArray[20] = { { jsObject }["foo"] + {jsObject}["foo"] = {"bar"} apply({a}, {b}, {c}) + apply( { a @@ -259,6 +280,7 @@ apply( ) Thing.map(foo, (arg1, arg2) => {MyModuleBlah.toList(argument)}) + Thing.map({foo}, (arg1, arg2) => { MyModuleBlah.toList(argument) }) @@ -277,9 +299,11 @@ arr->Belt.Array.map(x => { }) apply(~a={a}) + apply({ a }) + apply({ a }) @@ -311,6 +335,7 @@ let x = { } {a} + {b} + { a } + diff --git a/tests/syntax_tests/data/printer/expr/expected/bsObj.res.txt b/tests/syntax_tests/data/printer/expr/expected/bsObj.res.txt index 083bb52267f..572217ddf3b 100644 --- a/tests/syntax_tests/data/printer/expr/expected/bsObj.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/bsObj.res.txt @@ -17,11 +17,13 @@ let person = { let user = {"name": (ceo.name: string)} // braces should be preserved on rhs let user = {"name": {ceo.name}} + let user = { "name": { ceo.name }, } + // braced + constrained expr let user = {"name": {(ceo.name: string)}} diff --git a/tests/syntax_tests/data/printer/expr/expected/callback.res.txt b/tests/syntax_tests/data/printer/expr/expected/callback.res.txt index f0e0b96b3e0..2448937028e 100644 --- a/tests/syntax_tests/data/printer/expr/expected/callback.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/callback.res.txt @@ -1,5 +1,6 @@ array->Array.forEach(((value, height)) => add(rbt, value, ~height)->ignore) someArray->Array.forEach(((value, height)) => add(rbt, value, ~height)->ignore) + someArraaaaaaayWithAVeryLooooooooooooooooooooooooooooooooooooooongName->Array.forEach((( value, height, @@ -14,9 +15,11 @@ let make = (arr, ~compare) => { Thing.map(foo, (arg1, arg2) => MyModuleBlah.toList(argument)) Thing.map(foo, bar, baz, (aaaaaaaaaaarg1, aaaaarg2) => MyModuleBlah.toList(argument)) Thing.map(fooooooooooooooooooo, bar, baz, (abc, z) => MyModuleBlah.toList(argument)) + Thing.map(fooooooooooooooooooo, baaaaaaaaaaaaaaaaaar, baaaaaaaaaaaaaaaaaaaaaaaaaz, (abc, z) => MyModuleBlah.toList(argument) ) + Fooooooooooooooooooo.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(baaaz, quuuuux => something(here) ) @@ -119,6 +122,7 @@ Thing.map( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg3, ~fn=(param1, parm2) => doStuff(param1, parm2), ) + Thing.map( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg2, @@ -135,6 +139,7 @@ Thing.map(~fn=?(arg1, arg2) => MyModuleBlah.toList(argument), foo) Thing.map(~fn=(arg1, arg2) => { MyModuleBlah.toList(argument) }, longArgument, veryLooooongArgument) + Thing.map(~fn=?(arg1, arg2) => { MyModuleBlah.toList(argument) }, longArgument, veryLooooongArgument) @@ -146,6 +151,7 @@ Thing.map( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg3, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg4, ) + Thing.map( ~fn=?(param1, parm2) => doStuff(param1, parm2), aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg2, diff --git a/tests/syntax_tests/data/printer/expr/expected/coerce.res.txt b/tests/syntax_tests/data/printer/expr/expected/coerce.res.txt index 3c74ea4de5b..8e428ce567c 100644 --- a/tests/syntax_tests/data/printer/expr/expected/coerce.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/coerce.res.txt @@ -67,24 +67,29 @@ let arrayIndex = values[index :> int] values[index :> int] = (value :> b) let recordSpread = {...value :> b, field: value} let bracedOperand = ({value} :> b) + let blockSequence = { { foo() value } :> b } + let checked = assert(value :> bool) (value :> b) let ternaryCallback = condition ? (x => (x :> b)) : other let piped = (value :> b)->foo + let blockTail = { foo() (value :> b) } + let blockHead = { (value :> b) foo() } + let dictSpread = dict{...value :> dict, "field": value} // A constrained operand needs parentheses when the coercion is a binding RHS. @@ -101,9 +106,11 @@ let beforeJsx = () => { // These grammar positions don't parse a bare trailing coercion. let locallyAbstract: type a. a = (value :> a) + let guarded = switch value { | _ if (flag :> bool) => value } + let jsxSpread = propsType)} /> @attr(? value if (flag :> bool)) @@ -112,6 +119,7 @@ let attributeGuard = value // Attribute and extension payloads parse their contents as plain expressions. @attr((value :> b)) let attributePayload = value + let extensionPayload = %extension((value :> b)) // First-class module unpacking also parses a plain expression. diff --git a/tests/syntax_tests/data/printer/expr/expected/constructor.res.txt b/tests/syntax_tests/data/printer/expr/expected/constructor.res.txt index 929669fab0f..828d80590a4 100644 --- a/tests/syntax_tests/data/printer/expr/expected/constructor.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/constructor.res.txt @@ -3,12 +3,15 @@ let y = false let r = Reducer() let r = Reducer(state, nexState, sideEffect) + let r = Reducer( superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, ) + let r = Reducer([state, nexState, sideEffect]) + let r = Reducer([ superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, @@ -45,6 +48,7 @@ let c = ConstructorWithASuuuuuuuuuuuuuuuperLoooooooooooooooooooooooooooooongIiii let c = ConstructorWithASuuuuuuuuuuuuuuuperLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer(list{}) let coordinate = JsCoord({"x": 1, "y": 1}) + let user = JsUser({ "name": "steve", "age": 32, diff --git a/tests/syntax_tests/data/printer/expr/expected/extension.res.txt b/tests/syntax_tests/data/printer/expr/expected/extension.res.txt index c3536b19b4b..58c32ff73a4 100644 --- a/tests/syntax_tests/data/printer/expr/expected/extension.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/extension.res.txt @@ -4,10 +4,12 @@ let node = %raw(@attr ("0")) let node = %raw(@attrStructureLvl (@attrOnExpr "0")) let node = %raw(@attrStructureLvl @attrStructureLvl2 @attrStructureLvl3 (@attrOnExpr "0")) + let node = %raw( @attrStructureLvl @attrStructureLvl2 @attrStructureLvl3 (@attrOnExpr @attrOnExpr2 @attrOnExpr3 @attrOnExpr4 @attrOnExpr5 "unsafe raw js") ) + let f: (int, int) => int = %raw((a, b) => "{return a + b}") let f = (x, y) => { diff --git a/tests/syntax_tests/data/printer/expr/expected/field.res.txt b/tests/syntax_tests/data/printer/expr/expected/field.res.txt index f3e2fed8960..4d9b9271ecc 100644 --- a/tests/syntax_tests/data/printer/expr/expected/field.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/field.res.txt @@ -21,6 +21,7 @@ let x = apply(arg1, arg2).field let x = (-1).x let x = (!true).x let x = (x => print(x)).x + let x = ( switch x { | Blue => () @@ -49,6 +50,7 @@ let x = ( ).x let x = (assert(false)).x + let x = ( try sideEffect() catch { | Exit => () diff --git a/tests/syntax_tests/data/printer/expr/expected/firstClassModule.res.txt b/tests/syntax_tests/data/printer/expr/expected/firstClassModule.res.txt index d3fcbd534ed..12df0f06aa8 100644 --- a/tests/syntax_tests/data/printer/expr/expected/firstClassModule.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/firstClassModule.res.txt @@ -10,22 +10,27 @@ let x = @attr module(Foo: FirstClass) module(Teenager)[0] module(Teenager)->age->Console.log module(Teenager)[0]->Console.log + module(Teenager)->age->isAdult ? Console.log("has responsibilities") : Console.log("can play in the playground") + module(Streets)[0]->isExpensive ? Console.log("big money") : Console.log("affordable") let () = { module(Teenager)->age->Console.log } + let () = { module(Teenager)[0] } + let () = { module(Teenager)->age->isAdult ? Console.log("has responsibilities") : Console.log("can play in the playground") } + let () = { module(Streets)[0]->isExpensive ? Console.log("big money") : Console.log("affordable") } diff --git a/tests/syntax_tests/data/printer/expr/expected/fun.res.txt b/tests/syntax_tests/data/printer/expr/expected/fun.res.txt index d5f7e02218d..ef186493143 100644 --- a/tests/syntax_tests/data/printer/expr/expected/fun.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/fun.res.txt @@ -190,6 +190,7 @@ let make = (~onChange: option<({"testing": bool}, array) => unit>=?, chi let add = (a, b): int => a + b let add = (a, b): {"field1": int, "field2": string, "field3": int, "field4": int} => a + b + let add = (superLongParameterName1, superLongParameterName2, superLongParameterName3): { "field1": int, "field2": string, @@ -206,12 +207,14 @@ let add = (superLongParameterName1, superLongParameterName2, superLongParameterN } => a + b let add = ((a, b)): (int, string, int, int) => a + b + let add = ((a, b)): ( intWithSuperLongName, stringWithSuperLongName, intWithSuperLongName, intWithSuperLongName, ) => a + b + let add = (( superLongParameterName, bsuperLongParameterName, @@ -226,6 +229,7 @@ let add = (list{a, b}): list< intWithSuperLongName, intWithSuperLongName, > => a + b + let add = (list{ superLongParameterName, bsuperLongParameterName, @@ -244,6 +248,7 @@ let add = ([a, b]): array< intWithSuperLongName, intWithSuperLongName, > => a + b + let add = ([ superLongParameterName, bsuperLongParameterName, @@ -258,8 +263,10 @@ let add = ([ let add = ({x: superLongParameterName, y: superLongParameterName, z: superLongParameterName}) => x + y + z + let add = ({x: superLongParameterName, y: superLongParameterName, z: superLongParameterName}) => x + y + z + let add = ({ x: x as superLongParameterName, y: y as superLongParameterName, @@ -268,6 +275,7 @@ let add = ({ let add = (Color(superLongParameterName, superLongParameterName, superLongParameterNameeeeeee)) => x + y + z + let add = (Color( superLongParameterName, superLongParameterName, diff --git a/tests/syntax_tests/data/printer/expr/expected/functionLayouts.res.txt b/tests/syntax_tests/data/printer/expr/expected/functionLayouts.res.txt index 96e60317212..e38bd37b75a 100644 --- a/tests/syntax_tests/data/printer/expr/expected/functionLayouts.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/functionLayouts.res.txt @@ -7,14 +7,17 @@ let fragment = value => <> + consume(value => <> ) + consume(value => <> , argument) + consume(argument, value => <> @@ -25,10 +28,12 @@ let block = // Keep the body comment. await compute(first, second) } + consume(argument, @attr async (~first, ~second=defaultValue): result => { // Keep the callback comment. await compute(first, second) }) + consume(firstVeryLongArgument, secondVeryLongArgument, (firstParameter, secondParameter) => compute(firstParameter, secondParameter) ) diff --git a/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt b/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt index 53c4801ddef..104c753885d 100644 --- a/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt @@ -21,27 +21,33 @@ let x = + let x = {children} + let x = {children} + let x = {a} + let x = {a} {b} + let x = {a} + let x = {a} @@ -302,9 +308,11 @@ let x = {test}} nav={} /> // https://github.com/rescript-lang/syntax/issues/113
{Console.log(a <= 10)}
+
{Console.log(a <= 10)}
+
Console.log(a <= 10)}>
{Console.log(a <= 10)}
diff --git a/tests/syntax_tests/data/printer/expr/expected/jsxChildren.res.txt b/tests/syntax_tests/data/printer/expr/expected/jsxChildren.res.txt index dd90f2bd1c3..d0cc4f90d5c 100644 --- a/tests/syntax_tests/data/printer/expr/expected/jsxChildren.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/jsxChildren.res.txt @@ -31,6 +31,7 @@ let x = {hello} {user.name} + let x = <> @@ -38,13 +39,16 @@ let x = + let x = <>{hello} let x = <>{hello} + let x = <> {hello} {world} + let x = <> let x = @@ -52,6 +56,7 @@ let x = let x = {render(hello)} let x = {hello->render} let x = {condition ? hello : world} + let x = {switch value { @@ -59,6 +64,7 @@ let x = | None => fallback }} + let x = { @@ -66,6 +72,7 @@ let x = child } + let x = { @@ -73,6 +80,7 @@ let x = hello } + let x = { @@ -80,6 +88,7 @@ let x = child } + let x = { @@ -87,6 +96,7 @@ let x = Hello.child } + let x = { @@ -94,7 +104,9 @@ let x = hello } + let x = {@label hello} + let x = { @@ -105,13 +117,16 @@ let x = } } + let x = {} + let x = {/* before braced JSX */} {} {/* after braced JSX */} + let x = <> {/* before braced fragment */} @@ -123,11 +138,13 @@ let x = let x = {/* before bare */ hello /* after bare */} let x = {/* inside */ hello /* still inside */} let x = <>{/* inside fragment */ hello /* still in fragment */} + let x = {hello /* between children */} {world} + let x = {{/* record field */ name: hello}} // Child comments and their line breaks stay inside expression braces. let x = {hello /* bare child */} @@ -135,12 +152,15 @@ let x = <>{hello /* bare fragment child */} let x = {user.name /* field child */} let x = {"hello" /* string child */} let x = {{name: hello} /* record child */} + let x = {hello} {/* already braced child */} + let x = {hello /* block comment */ /* line comment */} + let x = { @@ -148,7 +168,9 @@ let x = hello // Contains */ and must remain a line comment. } + let x = <>{/* before record */ {name: hello} /* after record */} + let x = {/* before a block */} @@ -158,12 +180,14 @@ let x = } {/* after a block */} + let x = {/* before a call */} {render(hello)} {/* after a call */} + let x = { @@ -172,7 +196,9 @@ let x = } {/* after bare child */} + let x = {hello /* trailing inside braces */} + let x = <> { @@ -180,6 +206,7 @@ let x = hello } + let x = { @@ -187,20 +214,24 @@ let x = {name: hello} /* after record */ } + let x = {aLongChildIdentifierThatWillNeedToWrapAtNarrowWidths} let emptyWithBlockComment = {/* empty */} + let emptyWithLineComment = { // contains */ } + let emptyFragmentWithInlineBlockComment = <>{/* inside */} let emptyFragmentWithInlineLineComment = <>{/* inside */} + let emptyFragmentWithMixedComments = <> { @@ -209,7 +240,9 @@ let emptyFragmentWithMixedComments = /* third */ } + let emptyFragmentWithOutsideComment = <>{/* inside */} // outside + let emptyFragmentWithComments = <> { @@ -217,6 +250,7 @@ let emptyFragmentWithComments = /* second */ } + let nestedStandaloneComments =
{/* before */} @@ -231,12 +265,14 @@ let nestedStandaloneComments = {/* last */}
+ let nestedInlineComments =
{/* before */} {/* after */}
+ let explicitCommentContainers = <> {/* before */} @@ -247,17 +283,20 @@ let explicitCommentContainers = {/* after */} + let adjacentCommentContainers = {/* one */} {/* two */} + let commentBeforeExpression = {/* before */} {hello} {/* after */} + let emptyRecordChild = {{}} let wrappedEmptyRecordChild = {{/* record */}} diff --git a/tests/syntax_tests/data/printer/expr/expected/jsxChildrenComments.res.txt b/tests/syntax_tests/data/printer/expr/expected/jsxChildrenComments.res.txt index 048e837ca7c..903ea3e1dfb 100644 --- a/tests/syntax_tests/data/printer/expr/expected/jsxChildrenComments.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/jsxChildrenComments.res.txt @@ -3,6 +3,7 @@ let a = {x} {/* a */}
+ let b =
{x} @@ -10,6 +11,7 @@ let b = {/* c */} {y}
+ let c =
@@ -17,6 +19,7 @@ let c =
+ let d =
{/* a */} @@ -24,34 +27,40 @@ let d = {/* b */}
+ let e =
{/* a */} {/* b */}
+ let f =
{x} {/* c */} {y}
+ let g =
{/* c */} {x}
+ let h =
{/* a */ /* b */}
+ let i =
{x} {/* a */}
+ let j =
{ @@ -59,6 +68,7 @@ let j = x }
+ let k =
{ @@ -66,11 +76,13 @@ let k = /* trailing */ }
+ let l =
{x} {/* trailing */}
+ let m =
{ @@ -78,11 +90,13 @@ let m = x }
+ let n =
{/* a */ /* b */}
+ let o =
{ @@ -98,6 +112,7 @@ let a = {x} {/* a */} + let b = <> {x} @@ -105,6 +120,7 @@ let b = {/* c */} {y} + let c = <> @@ -112,6 +128,7 @@ let c = + let d = <> {/* a */} @@ -119,34 +136,40 @@ let d = {/* b */} + let e = <> {/* a */} {/* b */} + let f = <> {x} {/* c */} {y} + let g = <> {/* c */} {x} + let h = <> {/* a */ /* b */} + let i = <> {x} {/* a */} + let j = <> { @@ -154,6 +177,7 @@ let j = x } + let k = <> { @@ -161,11 +185,13 @@ let k = /* trailing */ } + let l = <> {x} {/* trailing */} + let m = <> { @@ -173,11 +199,13 @@ let m = x } + let n = <> {/* a */ /* b */} + let o = <> { @@ -197,6 +225,7 @@ let spanningContainer = } {y}
+ let spanningFragmentContainer = <> {x} @@ -215,6 +244,7 @@ let multilineExpressionComment = } {y}
+ let leadingExpressionComment = + let mixedTrailingContainers =
{x} {/* b */} {/* a */}
+ let mixedLeadingFragmentContainers = <> {/* a */} {/* b */} {y} + let mixedTrailingFragmentContainers = <> {x} {/* b */} {/* a */} + let mixedBetweenContainers =
{x /* a */} {/* b */} {/* c */ y}
+ let mixedBetweenFragmentContainers = <> {x /* a */} @@ -263,30 +298,35 @@ let mixedBetweenFragmentContainers = let safeLineComment = {value /* note */} let safeInnerLineComment = {value /* note */} + let unsafeOpeningDelimiter = { // starts /* } + let unsafeClosingDelimiter = { // closes */ } + let unsafeNestedBlock = <> { // /* nested */ } + let unsafeReversedDelimiters = <> { // */ before /* } + let emptyLineComment = {/* */} let starLineComment = {/* * */} let slashLineComment = <>{/* / */} diff --git a/tests/syntax_tests/data/printer/expr/expected/newtype.res.txt b/tests/syntax_tests/data/printer/expr/expected/newtype.res.txt index e8480471a65..f5a59bd175e 100644 --- a/tests/syntax_tests/data/printer/expr/expected/newtype.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/newtype.res.txt @@ -6,6 +6,7 @@ let f = (type t u v, xs: list<(t, u, v)>) => () let f = @attr (type t u v, xs: list<(t, u, v)>) => () let f = (type t u v s w z, xs: list<(t, u, v)>, ys: list<(s, w, z)>) => () let f = @attr (type t u v, @attr2 type s w z, xs: list<(t, u, v)>, ys: list<(s, w, z)>) => () + let f = ( @attr type t, @attr type s, diff --git a/tests/syntax_tests/data/printer/expr/expected/polyvariant.res.txt b/tests/syntax_tests/data/printer/expr/expected/polyvariant.res.txt index f7c4fa0e296..b97d9d60410 100644 --- a/tests/syntax_tests/data/printer/expr/expected/polyvariant.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/polyvariant.res.txt @@ -1,11 +1,14 @@ let r = #Reducer() let r = #Reducer(state, nexState, sideEffect) + let r = #Reducer( superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, ) + let r = #Reducer([state, nexState, sideEffect]) + let r = #Reducer([ superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, @@ -42,6 +45,7 @@ let c = #ConstructorWithASuuuuuuuuuuuuuuuperLoooooooooooooooooooooooooooooongIii let c = #ConstructorWithASuuuuuuuuuuuuuuuperLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer(list{}) let coordinate = #JsCoord({"x": 1, "y": 1}) + let user = #JsUser({ "name": "steve", "age": 32, diff --git a/tests/syntax_tests/data/printer/expr/expected/record.res.txt b/tests/syntax_tests/data/printer/expr/expected/record.res.txt index d33ef76db57..83d1b5a83ee 100644 --- a/tests/syntax_tests/data/printer/expr/expected/record.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/record.res.txt @@ -1,4 +1,5 @@ let coord = {x: 3.13, y: 3.14} + let record = { firstField: superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, secondField: superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, @@ -11,6 +12,7 @@ let forceBreak = { } let withSpread = {...initialState, time: nextTime} + let withSpreadAndForceBreak = { ...initialState, time: nextTime, @@ -25,6 +27,7 @@ let withSpreadAndNaturalBreak = { let x = @attr {x: 1, y: 2} let x = @attr {...initialState, superLongName: 1, superLongName: 2, superLongName: 5} + let x = @attr {...initialState, superLongName: 1, superLongName: 2, superLongName: 5, superLongName: 20} @@ -32,11 +35,13 @@ let x = let user = {name: (ceo.name: string)} // braces should be preserved on rhs let user = {name: {ceo.name}} + let user = { name: { ceo.name }, } + // braced + constrained expr let user = {name: {(ceo.name: string)}} @@ -58,20 +63,24 @@ let r = { // b b, } + let r = { a, // a b, // b } + let r = { /* a */ a, /* b */ b, } + let r = { a /* a */, b /* b */, } + let r = {a /* a */, b /* b */} let r = {x: ?None, y: ?None, z: ?(None: tt)} @@ -122,13 +131,16 @@ let optParen = {x: 3, y: ?(() => 3)} let optParen = {x: 3, y: ?-3} let x = {a: 2} + let x = { a: 2, bbbbbbbbbbbbbbbbbbbbb: 22222222222, ccccccccccccccccccccc: 22222222222222222, ddddddddddddddddddddd: 2222222222222, } + let x = {a: 2} + let x = { a: 2, } diff --git a/tests/syntax_tests/data/printer/expr/expected/refFunction.res.txt b/tests/syntax_tests/data/printer/expr/expected/refFunction.res.txt index 9f94c7ef7d4..f3cbff74c92 100644 --- a/tests/syntax_tests/data/printer/expr/expected/refFunction.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/refFunction.res.txt @@ -4,6 +4,7 @@ f.contents = () => { doA() doB() } + f := () => { doA() doB() @@ -13,6 +14,7 @@ f.contents = @attr () => { doA() doB() } + f := @attr () => { doA() doB() @@ -20,11 +22,14 @@ f := @attr () => { f := () => doA() f := @first @second () => doA() + f := async () => { await doA() doB() } + f := (value: int): int => value + 1 + f := (firstArgument, secondArgument, thirdArgument, fourthArgument, fifthArgument) => { doA(firstArgument, secondArgument) doB(thirdArgument, fourthArgument, fifthArgument) @@ -36,10 +41,12 @@ f := /* function */ () => { doA() doB() } + f.contents = /* attribute */ @attr () => { doA() doB() } + f := @attr () => { doA() doB() @@ -52,6 +59,7 @@ f := { doB() } } + f := (() => doA(): unit => unit) // Other operators still need parentheses around functions. @@ -63,5 +71,6 @@ let equal = doB() } ) + let left = (() => doA()) == f.contents let nested = (f := () => doA())->ignore diff --git a/tests/syntax_tests/data/printer/expr/expected/setfield.res.txt b/tests/syntax_tests/data/printer/expr/expected/setfield.res.txt index 06f4bf90873..d1cb0f161b0 100644 --- a/tests/syntax_tests/data/printer/expr/expected/setfield.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/setfield.res.txt @@ -1,4 +1,5 @@ user.name = "steve" + config.shouldSkip = !filePath.includes(allMlSuffixesCategory) && !filePath.endsWith(allScriptDirectoriesCategory) diff --git a/tests/syntax_tests/data/printer/expr/expected/ternary.res.txt b/tests/syntax_tests/data/printer/expr/expected/ternary.res.txt index cf3ea657fb0..85885fff1fc 100644 --- a/tests/syntax_tests/data/printer/expr/expected/ternary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/ternary.res.txt @@ -26,6 +26,7 @@ let paymentMessage = : "There was an issue with the payment. Please contact support." let record = truth ? {x: 1, y: 2} : {x: 3, y: 5} + let record = truth ? { thisIsASuperLongFieldHere: loooooooooooooongIdentifier, @@ -37,6 +38,7 @@ let record = truth } let arr = truth ? [1, 2, 3, 4] : [4, 5, 6, 7] + let arr = truth ? [ thisIsASuperLongIdentifieeeeeeeer, @@ -50,6 +52,7 @@ let arr = truth ] let lst = truth ? list{1, 2, 3, 4} : list{4, 5, 6, 7} + let lst = truth ? list{ thisIsASuperLongIdentifieeeeeeeer, @@ -63,6 +66,7 @@ let lst = truth } let construct = truth ? Constructor(1, 2, 3, 4) : Constructor(4, 5, 6, 7) + let construct = truth ? Constructor( thisIsASuperLongIdentifieeeeeeeer, @@ -86,6 +90,7 @@ let x = truth let b = 2 a + b } + let x = truth ? { let a = 1 @@ -99,6 +104,7 @@ let x = truth } let x = truth ? create(a, b) : create(b, c) + let x = truth ? create( thisIsASuperLongIdentifieeeeeeeer, @@ -110,7 +116,9 @@ let x = truth thisIsASuperLongIdentifieeeeeeeer2, thisIsASuperLongIdentifieeeeeeeer3, ) + let x = truth ? create(a, b) : create(b, c) + let x = truth ? create( thisIsASuperLongIdentifieeeeeeeer, @@ -150,6 +158,7 @@ let x = exceptionLike } let tuple = truth ? (1, 2, 3, 4) : (4, 5, 6, 7) + let tuple = truth ? ( thisIsASuperLongIdentifieeeeeeeer, @@ -163,11 +172,13 @@ let tuple = truth ) let x = condition1 ? node.left : node.right + let x = condition1 ? nodeWithVeryLooooooooooooooooongNameHere.left : nodeWithVeryLooooooooooooooooongNameHere.right let x = condition ? node.left = Some(newNode) : node.right = Some(newNode) + let x = condition1 ? nodeWithVeryLooooooooooooooooongNameHere.left = Some(newNode) : nodeWithVeryLooooooooooooooooongNameHere.right = Some(newNode) @@ -183,6 +194,7 @@ let x = condition1 } else { () } + let () = condition1 ? { sideEffect() @@ -200,6 +212,7 @@ let () = condition1 : while true { doOtherThing() } + let () = condition1 ? for i in 0 to 10 { () @@ -219,9 +232,11 @@ let () = condition exception Exit throw(Exit) } + let () = condition ? foo() : assert(false) let x = condition ? module(Foo) : module(Int: Number) + let x = condition ? module(ModuleWithVeryLooooooooooooooooongNameHere) : module(ModuleWithVeryLooooooooooooooooongNameHereInt: Number) @@ -235,10 +250,12 @@ let x = condition open React render() } + let x = condition ? %eval("console.log") : %eval("console.err") let x = condition ? %eval("consoooooooooooooooooooooole.log") : %eval("consoleeeeeeeeeeeeeee.err") let jsObj = condition ? {"x": 1, "y": 2} : {"x": 20, "y": 100} + let jsObj = truth ? { "thisIsASuperLongFieldHere": loooooooooooooongIdentifier, diff --git a/tests/syntax_tests/data/printer/expr/expected/unary.res.txt b/tests/syntax_tests/data/printer/expr/expected/unary.res.txt index e3c7fd69176..63bb3d5eac9 100644 --- a/tests/syntax_tests/data/printer/expr/expected/unary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/unary.res.txt @@ -47,6 +47,7 @@ let x = -apply(arg) let x = -Foo(a, b, c) let x = -{x: 1, y: 2} let x = -list{1, 2, 3} + let x = -( if true { 1 @@ -54,27 +55,33 @@ let x = -( 2 } ) + let x = -( for i in 0 to 10 { () } ) + let x = -( switch x { | Foo => 1 } ) + let x = -( while i < 10 { i.contents = 20 } ) + let x = -(1, 2, 3) + let x = -{ let a = 1 let b = 2 a + b } + let x = -{ sideEffect() generateNumber() diff --git a/tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt index 1179ae4849c..a7768c331d0 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt @@ -1,8 +1,10 @@ module A = @attr F module B = @attr {} + module C = @attr { let x = 1 } + module D = @a @b F // on a functor application, its functor, or an argument @@ -12,12 +14,15 @@ module H = @attr F(A, B) module I = (@attr F(A))(B) module J = F(@attr X) module Q = F(@attr {}) + include @attr F({ type t = int }) + include (@attr F)({ type t = int }) + include F(@attr { type t = int }) diff --git a/tests/syntax_tests/data/printer/modExpr/expected/functor.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/functor.res.txt index 312c49ecd41..c2559191aba 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/functor.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/functor.res.txt @@ -11,17 +11,21 @@ include (@functorAttr2 @functorAttr X: Map, @attr3 Y: Set) => Zzzzzzzzzzzzzzzzzz module Make = (A: X, B: Y) => { let a = A.a + B.b } + // constraint on return type module Make = (A: X, B: Y): Set => { let a = A.a + B.b } + include (@functorAttr X: Map, Y: Set, Z: SuperLongModuleTypeName, Foo: Baaaaaaaaar): Set => { let a = A.a + B.b } + // with attributes module Make = (@functorAttr A: X, B: Y): Set => { let a = A.a + B.b } + module Make = (@functorAttr A: X, @functorAttr2 B: Y): Set => { let a = A.a + B.b } @@ -46,6 +50,7 @@ module Make = ( type key = t type coll = list let empty = list{} + let add = (y: coll, e: key) => if List.exists(x => eq(x, e), y) { y @@ -57,6 +62,7 @@ module Make = ( module Make = (A: X, B: Y): ((Set, Set) => Set) => { let a = A.a + B.b } + module Make = (SuperLongNaaaaaaaame: X, SuperLongNaaaaaaaame: Y, SuperLongNaaaaaaaame: Z): ( ( Seeeeeeeeeeeeeeeeeeeeeeeeeeeeet, diff --git a/tests/syntax_tests/data/printer/modExpr/expected/include.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/include.res.txt index a1fec610ccf..3e01e2720c2 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/include.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/include.res.txt @@ -2,9 +2,11 @@ type t include Sprite.Comp({type t = t}) include Color.Comp({type t = t}) + include Pos.Comp({ type t = superLooooooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnngggggTyyyyyyypeeeNaaaaaammeee }) + include Area.Comp({type t = t}) include Anchor.Comp({type t = t}) include Move.Comp({type t = t}) diff --git a/tests/syntax_tests/data/printer/modExpr/expected/parens.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/parens.res.txt index 641f1508293..477e568e8df 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/parens.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/parens.res.txt @@ -9,6 +9,7 @@ let e2 = (module(await (@a X)): module(S)) let e3 = (module(await (X: S1)): module(S2)) let e4 = (module(await @a (await X)): module(S)) let e5 = module(await @a X: S) + let f = () => { module M: T = (X: S) () diff --git a/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt index 14e1ecd1f67..31cc4493f41 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt @@ -31,6 +31,7 @@ module M7: { module N: { let x: int } + module N' = N }) @@ -62,8 +63,10 @@ module M6 = { module D = { let y = 3 } + module N = { let x = 1 } + module N' = N } diff --git a/tests/syntax_tests/data/printer/modType/expected/moduleTypeOf.res.txt b/tests/syntax_tests/data/printer/modType/expected/moduleTypeOf.res.txt index 2c1f4c85161..ed1236c4ca0 100644 --- a/tests/syntax_tests/data/printer/modType/expected/moduleTypeOf.res.txt +++ b/tests/syntax_tests/data/printer/modType/expected/moduleTypeOf.res.txt @@ -1,3 +1,4 @@ module type LinkedList = module type of List + module type LinkedList = @attr module type of List diff --git a/tests/syntax_tests/data/printer/modType/expected/withConstraints.res.txt b/tests/syntax_tests/data/printer/modType/expected/withConstraints.res.txt index 45b429ef33e..42f7f950c60 100644 --- a/tests/syntax_tests/data/printer/modType/expected/withConstraints.res.txt +++ b/tests/syntax_tests/data/printer/modType/expected/withConstraints.res.txt @@ -4,6 +4,7 @@ module type A = Foo with type t<'a> = string module type A = Foo with type t<'a, 'b> = string module type A = Foo with type t = 'st constraint 'st = int module type A = Foo with type t = 'st constraint 'st = int constraint 'x = int + module type A = Foo with type t = 'st constraint 'st = int constraint 'x = int and type t = 'st constraint 'st = int constraint 'x = int @@ -13,6 +14,7 @@ module type A = Foo with type t := string module type A = Foo with type t<'a> := string module type A = Foo with type t<'a, 'b> := string module type A = Foo with type Bar.t<'a, 'b> := string + module type A = Foo with type Bar.t<'a, 'b> := string and type Bar.t<'a, 'b> := string @@ -21,6 +23,7 @@ module type A = Foo module type A = Foo with module Bar = Array module type A = Foo with module Bar = Belt.Array module type A = Foo with module X.Bar = Belt.Array + module type A = Foo with module X.Bar = Belt.Array and module X.Bar = Belt.Array @@ -28,6 +31,7 @@ module type A = Foo module type A = Foo with module Bar := Array module type A = Foo with module Bar := Belt.Array + module type A = Foo with module X.Bar := Belt.Array and module X.Bar := Belt.Array @@ -36,12 +40,14 @@ module type A = Foo module Same = (Na: N, Nb: N): ((S with type number1 = Na.number) with type number2 = Nb.number) => { type number1 = Na.number type number2 = Nb.number + let rec sim = ((n, m)) => if Na.is_zero(n) { Nb.is_zero(m) } else { sim((Na.pred(n), Nb.pred(m))) } + let similar = ((n, m)) => try sim((n, m)) catch { | Na.Too_small => false diff --git a/tests/syntax_tests/data/printer/other/expected/StaticReactTypes.res.txt b/tests/syntax_tests/data/printer/other/expected/StaticReactTypes.res.txt index dd479c4a0a4..d7b8a1bf936 100644 --- a/tests/syntax_tests/data/printer/other/expected/StaticReactTypes.res.txt +++ b/tests/syntax_tests/data/printer/other/expected/StaticReactTypes.res.txt @@ -1,4 +1,5 @@ type empty = Empty_ + /* * Also create another form for splicing in nodes into otherwise fixed length * sets. diff --git a/tests/syntax_tests/data/printer/other/expected/attributes.res.txt b/tests/syntax_tests/data/printer/other/expected/attributes.res.txt index b34daf6830c..5f5be3c028e 100644 --- a/tests/syntax_tests/data/printer/other/expected/attributes.res.txt +++ b/tests/syntax_tests/data/printer/other/expected/attributes.res.txt @@ -8,6 +8,7 @@ let x = 1 let x = 1 %ext(: let x: int) + %ext(: let x: int let y: float diff --git a/tests/syntax_tests/data/printer/other/expected/fatSlider.res.txt b/tests/syntax_tests/data/printer/other/expected/fatSlider.res.txt index 784733579ff..94515d673e1 100644 --- a/tests/syntax_tests/data/printer/other/expected/fatSlider.res.txt +++ b/tests/syntax_tests/data/printer/other/expected/fatSlider.res.txt @@ -6,6 +6,7 @@ module Range = { /* See https://github.com/reasonml/reason-react/blob/master/docs/clone-element.md */ /* We'll need to spread both the style inside the props, and the props object itself using ReasonReact.cloneElement. */ type rec propsThatNeedSpreading = {style: ReactDOMRe.Style.t} + type rec renderTrackParams = { props: propsThatNeedSpreading, children: React.element, diff --git a/tests/syntax_tests/data/printer/pattern/expected/alias.res.txt b/tests/syntax_tests/data/printer/pattern/expected/alias.res.txt index f55c7b27eac..0d4e0f811b7 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/alias.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/alias.res.txt @@ -13,5 +13,6 @@ let f = x => | Some(@a ()) => 5 | _ => 6 } + let g = (@a _) => 1 let h = (@a ()) => 1 diff --git a/tests/syntax_tests/data/printer/pattern/expected/firstClassModules.res.txt b/tests/syntax_tests/data/printer/pattern/expected/firstClassModules.res.txt index 6712935cbc9..060efb6a329 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/firstClassModules.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/firstClassModules.res.txt @@ -1,6 +1,7 @@ let module(Set) = z let module(Set: Set.S with type elt = s) = y let module(Set: Set.S with type elt = s and type elt2 = t) = x + let module(Set: Set.S with type elt = s and type elt2 = t diff --git a/tests/syntax_tests/data/printer/pattern/expected/list.res.txt b/tests/syntax_tests/data/printer/pattern/expected/list.res.txt index 66d3131e082..9131949d31f 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/list.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/list.res.txt @@ -5,6 +5,7 @@ let list{1, 2, 3} = 1 let list{1, 2, ...tail} = 1 let list{aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc} = 1 + let list{ aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, diff --git a/tests/syntax_tests/data/printer/pattern/expected/record.res.txt b/tests/syntax_tests/data/printer/pattern/expected/record.res.txt index b1861d258b0..41b86b0bb7d 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/record.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/record.res.txt @@ -23,6 +23,7 @@ let get_age3 = ({age: "100", name: _}) => age2 let get_age3 = ({age: 1 .. 2, name: _}) => age2 let get_age3 = ({age: 'a' .. 'z', name: _}) => age2 let get_age3 = ({age: (a, b, c, d), name: _}) => age2 + let get_age3 = ({ age: ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, @@ -32,9 +33,11 @@ let get_age3 = ({ ), name: _, }) => age2 + let get_age3 = ({age: Rgb(r, g, b), name: _}) => age2 let get_age3 = ({age: Rgb({r, g, b}), name: _}) => age2 let get_age3 = ({age: Rgb({r: red, g: green, b: black}), name: _}) => age2 + let get_age3 = ({ age: Rgb( rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, @@ -43,6 +46,7 @@ let get_age3 = ({ ), name: _, }) => age2 + let get_age3 = ({ age: Rgb({ r: rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, @@ -55,6 +59,7 @@ let get_age3 = ({ let get_age3 = ({age: #red, name: _}) => age2 let get_age3 = ({age: #Blue, name: _}) => age2 let get_age3 = ({age: #Rgb(r, g, b), name: _}) => age2 + let get_age3 = ({ age: #Rgb( rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, @@ -63,6 +68,7 @@ let get_age3 = ({ ), name: _, }) => age2 + let get_age3 = ({ age: #Rgb({ r: rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, @@ -71,7 +77,9 @@ let get_age3 = ({ }), name: _, }) => age2 + let get_age3 = ({age: {birthDay: day, birthMonth: month}, name: _}) => age2 + let get_age3 = ({ age: { birthDay: daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay, @@ -82,6 +90,7 @@ let get_age3 = ({ let get_age3 = ({age: [], name: _}) => age2 let get_age3 = ({age: [a, b, c, d], name: _}) => age2 + let get_age3 = ({ age: [ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, @@ -94,6 +103,7 @@ let get_age3 = ({ let get_age3 = ({age: list{}, name: _}) => age2 let get_age3 = ({age: list{a, b, c, d}, name: _}) => age2 + let get_age3 = ({ age: list{ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, @@ -117,10 +127,12 @@ let get_age3 = ({age: %raw("__GC"), name: _}) => age2 let get_age3 = ({age, _}) => age let get_age3 = ({_}) => "" + let get_age3 = () => switch x { | {age, _} => age } + let get_age3 = () => switch x { | {_} => "" diff --git a/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt b/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt index a2d580c8a34..3583204bb43 100644 --- a/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt +++ b/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt @@ -8,5 +8,6 @@ exception Exit = Ns.Lib.Terminate /** doc comment */ exception ExitEarly({x: int}) + /** doc comment */ exception ExitEarly({x: int, y: string}) diff --git a/tests/syntax_tests/data/printer/signature/expected/externalObjectSpread.resi.txt b/tests/syntax_tests/data/printer/signature/expected/externalObjectSpread.resi.txt index 3e3e77034b8..0219e18d5b3 100644 --- a/tests/syntax_tests/data/printer/signature/expected/externalObjectSpread.resi.txt +++ b/tests/syntax_tests/data/printer/signature/expected/externalObjectSpread.resi.txt @@ -1,3 +1,4 @@ type user = {"name": string} + @val external steve: {...user, "age": int} = "steve" diff --git a/tests/syntax_tests/data/printer/signature/expected/multilineSpacing.resi.txt b/tests/syntax_tests/data/printer/signature/expected/multilineSpacing.resi.txt new file mode 100644 index 00000000000..28194c311d2 --- /dev/null +++ b/tests/syntax_tests/data/printer/signature/expected/multilineSpacing.resi.txt @@ -0,0 +1,19 @@ +type t +let a: int + +type r = { + x: int, +} + +let b: int +// a comment does not count +let c: int + +/** Documented */ +let d: int + +module M: { + let x: int +} + +let e: int diff --git a/tests/syntax_tests/data/printer/signature/multilineSpacing.resi b/tests/syntax_tests/data/printer/signature/multilineSpacing.resi new file mode 100644 index 00000000000..820ef4a6c11 --- /dev/null +++ b/tests/syntax_tests/data/printer/signature/multilineSpacing.resi @@ -0,0 +1,14 @@ +type t +let a: int +type r = { + x: int, +} +let b: int +// a comment does not count +let c: int +/** Documented */ +let d: int +module M: { + let x: int +} +let e: int diff --git a/tests/syntax_tests/data/printer/structure/expected/exception.res.txt b/tests/syntax_tests/data/printer/structure/expected/exception.res.txt index 03f26bf5c0e..8dd547aeb7a 100644 --- a/tests/syntax_tests/data/printer/structure/expected/exception.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/exception.res.txt @@ -8,10 +8,12 @@ exception ExitEarly({@attr "jsExit": int, @attr "code": int}) exception ExitEarly({"jsExit": int}) exception ExitEarly({"jsExit": int}, {"code": int}) exception ExitEarly({"jsExit": int}, int, {"code": int}) + exception ExitEarly( {@attr "jsExit": int, @attr "code": int}, {@attr "jsExit": int, @attr "code": int}, ) + exception ExitJsStyle({..}) exception ExitJsStyle({.."code": int}) exception ExitJsStyle({.."code": int}) @@ -33,8 +35,10 @@ exception GadtExit(int): exit /** doc comment */ exception ExitEarly({x: int}) + /** doc comment */ exception ExitEarly({x: int, y: string}) + /** doc comment */ exception ExitEarlyWithManyFields({ firstFieldName: int, diff --git a/tests/syntax_tests/data/printer/structure/expected/externalObjectSpread.res.txt b/tests/syntax_tests/data/printer/structure/expected/externalObjectSpread.res.txt index 3e3e77034b8..0219e18d5b3 100644 --- a/tests/syntax_tests/data/printer/structure/expected/externalObjectSpread.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/externalObjectSpread.res.txt @@ -1,3 +1,4 @@ type user = {"name": string} + @val external steve: {...user, "age": int} = "steve" diff --git a/tests/syntax_tests/data/printer/structure/expected/include.res.txt b/tests/syntax_tests/data/printer/structure/expected/include.res.txt index 3e013044097..12c0144fe66 100644 --- a/tests/syntax_tests/data/printer/structure/expected/include.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/include.res.txt @@ -8,6 +8,7 @@ include ( { @val @module("react") external createElementInternalHack: 'a = "createElement" + @send external apply: ('theFunction, 'theContext, 'arguments) => 'returnTypeOfTheFunction = "apply" diff --git a/tests/syntax_tests/data/printer/structure/expected/multilineSpacing.res.txt b/tests/syntax_tests/data/printer/structure/expected/multilineSpacing.res.txt new file mode 100644 index 00000000000..85d07733e06 --- /dev/null +++ b/tests/syntax_tests/data/printer/structure/expected/multilineSpacing.res.txt @@ -0,0 +1,58 @@ +module Details = { + @react.component + let make = (~input as {filePath}: input) => React.string(filePath) +} + +module Body = { + @react.component + let make = (~input as {filePath, oldString}: input) => <> + + + +} + +module Output = Tool.TextResult.Output +let failed = Tool.TextResult.failed + +// one-line items stay together, a comment above one does not count +let a = 1 +// about b +let b = 2 + +/** a doc comment prints on its own line */ +let c = 3 + +let d = 4 // trailing + +// an item that only breaks because of the line width is multi-line +let long = someFunctionWithAVeryLongName( + argumentNumberOne, + argumentNumberTwo, + argumentNumber3, + argument4, +) + +let e = 5 + +type r = { + x: int, +} + +let f = 6 + +// an own-line trailing comment of the previous item goes below the blank line +f(a => 1) + +// relocated +let g = { + 1 +} + +// blocks are not affected +let h = () => { + let x = 1 + let y = { + 2 + } + x + y +} diff --git a/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt b/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt index e2909556320..54908550526 100644 --- a/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt @@ -26,37 +26,49 @@ type t += private Foo = Bar | Circle = Geo.Circle2 type t += Foo = Geo.Metry.Bar @attr type t += @attr1 Foo + @attr type t += @attr1 Foo + @attr type t += @attr1 Foo | @attr2 Bar + @attr type t += @attr1 Foo | @attr2 Bar @attr type t += private @attr1 Foo + @attr type t += private @attr1 Foo + @attr type t += private @attr1 Foo | @attr2 Bar + @attr type t += private @attr1 Foo | @attr2 Bar @attr type t += @attr1 Foo = Bar + @attr type t += @attr1 Foo = Bar + @attr type t += @attr1 Foo = Foo2 | @attr2 Bar = Bar2 + @attr type t += @attr1 Foo = Foo2 | @attr2 Bar = Bar2 @attr type t += private @attr1 Foo = Foo2 + @attr type t += private @attr1 Foo = Foo2 + @attr type t += private @attr1 Foo = Foo2 | @attr2 Bar = Bar2 + @attr type t += private @attr1 Foo = Foo2 | @attr2 Bar = Bar2 diff --git a/tests/syntax_tests/data/printer/structure/multilineSpacing.res b/tests/syntax_tests/data/printer/structure/multilineSpacing.res new file mode 100644 index 00000000000..da593d06159 --- /dev/null +++ b/tests/syntax_tests/data/printer/structure/multilineSpacing.res @@ -0,0 +1,46 @@ +module Details = { + @react.component + let make = (~input as {filePath}: input) => React.string(filePath) +} +module Body = { + @react.component + let make = (~input as {filePath, oldString}: input) => <> + + + +} +module Output = Tool.TextResult.Output +let failed = Tool.TextResult.failed + +// one-line items stay together, a comment above one does not count +let a = 1 +// about b +let b = 2 +/** a doc comment prints on its own line */ +let c = 3 +let d = 4 // trailing + +// an item that only breaks because of the line width is multi-line +let long = someFunctionWithAVeryLongName(argumentNumberOne, argumentNumberTwo, argumentNumber3, argument4) +let e = 5 +type r = { + x: int, +} +let f = 6 + +// an own-line trailing comment of the previous item goes below the blank line +f(a + // relocated + => 1) +let g = { + 1 +} + +// blocks are not affected +let h = () => { + let x = 1 + let y = { + 2 + } + x + y +} diff --git a/tests/syntax_tests/data/printer/typeDef/expected/abstract.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/abstract.res.txt index 013424b094e..8fa11270b40 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/abstract.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/abstract.res.txt @@ -10,6 +10,7 @@ type t = Module.Long.With.Very.VeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryLongName type t = private Module.Long.With.Very.VeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryLongName.t type t<'superlongthing, 'superlongthing, 'superlongthing, 'superlongthing, 'superlongthing> = string + type t< 'superlongthing, 'superlongthing, diff --git a/tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt index 9d0bbabbe54..2389c3db29d 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt @@ -1,8 +1,10 @@ @attr type t = float + @attr type t = float @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr type t = int + @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr type t = int @@ -11,6 +13,7 @@ type t = int @attrWithSuperLongIdentifeirName @attrWithSuperLongIdentifeirName type t = string + @attrWithSuperLongIdentifeirName @attrWithSuperLongIdentifeirName @attrWithSuperLongIdentifeirName diff --git a/tests/syntax_tests/data/printer/typeDef/expected/inlineRecordMultiline.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/inlineRecordMultiline.res.txt index b4418c5b800..d8344d91b05 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/inlineRecordMultiline.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/inlineRecordMultiline.res.txt @@ -39,6 +39,7 @@ type rec gadt<_> = }): gadt type ext = .. + type ext += | C({ name: string, diff --git a/tests/syntax_tests/data/printer/typeDef/expected/record.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/record.res.txt index a2fea60a25a..a91778ea651 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/record.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/record.res.txt @@ -1,11 +1,13 @@ type user = {name: string, age: int} type result<'success, 'failure> = {ok: 'success, fail: 'failure} + type result<'success1, 'failure1, 'success2, 'failure2, 'success3, 'failure3> = { ok: 'success1, fail: 'failure2, } type user = {name: string, age: int, a: string, lot: string, more: string, fields: string} + type user<'lotsOfTypeVars, 'lotsOfTypeVars2, 'lotsOfTypeVars3, 'lotsOfTypeVars4> = { name: string, age: int, @@ -30,6 +32,7 @@ type user = { } constraint 't = string type t = private {name: string, age: int} + type t = private { name: string, age: int, @@ -37,6 +40,7 @@ type t = private { type t = User.t = private {name: string, age: int} type t = @attr User.t = private {name: string, age: int} + type t = User.t = private { name: string, age: int, diff --git a/tests/syntax_tests/data/printer/typeDef/expected/variant.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/variant.res.txt index 3ca25274ad0..17b36d1db8f 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/variant.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/variant.res.txt @@ -2,27 +2,32 @@ type color = Red | Blue type color = Red | Blue | SuperLongColooooooooooooooourName | AnotherSuuuuuuuuuuuuuuperLongName type color = private Red | Blue + type color = private | Red | Blue | Green + type color = private Red | Blue | SuperLongColooooooooooooooourName | AnotherSuuuuuuuuuuuuuperLongName type color = Colour.t = private Red | Blue + type color = Colour.t = private | Red | Blue | Green + type color = Colour.t = private Red | Blue | SuperLongColoooooooooooooourName | AnotherSuuuuuuuuuuuuuperLongName // gadt type color = Red: color | Blue: color + type color = | Red: color | Blue: color @@ -30,6 +35,7 @@ type color = | AnotherSuuuuuuuuuperLongName: color type color = Rgb(float, float, float) | Hex(int) + type color = | Rgb(superLongTypeName, superLongTypeName, superLongTypeName, superLongTypeName) | Hex(superLongTypeName, superLongTypeName, superLongTypeName, superLongTypeName) @@ -115,5 +121,6 @@ type color = module S = { type s = Five | Six } + type aa = One | Two type bb = | ...aa | Three | Four | ...S.s diff --git a/tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt index 9708f5202fd..56b47f765a8 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt @@ -185,10 +185,12 @@ external debounce: (int, unit => unit, unit => unit) => unit => unit = "debounce external debounce: (int, unit => unit, unit => unit => unit) => unit => unit = "debounce" type returnTyp = (int, int) => @magic float + type returnTyp = ( intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, ) => @magic float + type returnTyp = ( intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, diff --git a/tests/syntax_tests/data/printer/typexpr/expected/bsObject.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/bsObject.res.txt index f854d538574..afc1c8d8222 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/bsObject.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/bsObject.res.txt @@ -1,5 +1,6 @@ type user = {"age": int} type user = {"age": int, "name": string} + type user = { "age": int, "name": string, @@ -10,6 +11,7 @@ type user = { type magic = {..} type t = {.."age": int} + type magicallyLong = {.. "age": int, "name": string, @@ -53,6 +55,7 @@ type t = {.} type t = private {.} type t = constr<{.}, {.}, {.}> + type t = { hr: React.component<{.}>, } diff --git a/tests/syntax_tests/data/printer/typexpr/expected/firstClassModule.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/firstClassModule.res.txt index bf3ca0f4d23..3a42bc4e1e3 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/firstClassModule.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/firstClassModule.res.txt @@ -1,6 +1,7 @@ type t = module(S) type t = module(Hashmap with type key = string) type t = module(Hashmap with type key = string and type value = int) + type t = module(Hashmap with type key = string and type value = int diff --git a/tests/syntax_tests/data/printer/typexpr/expected/objectTypeSpreading.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/objectTypeSpreading.res.txt index 3531336594e..71ae407c5ad 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/objectTypeSpreading.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/objectTypeSpreading.res.txt @@ -33,6 +33,7 @@ type taggedUser = | Ceo({...user, "age": int, "direction": bool}, {...salary, "taxFraud": bool}) type polyTaggedUser = [#User({...user, "age": int})] + type polyTaggedUser2 = [ | #User({...user, "age": int}) | #Ceo({...user, "age": int, "direction": bool}, {...salary, "taxFraud": bool}) @@ -41,6 +42,7 @@ type polyTaggedUser2 = [ // notice .. and ..., they should have a space type u<'a> = {.. ...hi} as 'a type u<'a> = {.. ...hi, "superLongFieldName": string, "superLongFieldName22222222222": int} as 'a + type u<'a> = {.. ...hi, "superLongFieldName": string, diff --git a/tests/syntax_tests/data/printer/typexpr/expected/typeConstr.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/typeConstr.res.txt index c4ee5cb61b5..c3754eef9af 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/typeConstr.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/typeConstr.res.txt @@ -1,5 +1,6 @@ type t = Option.t type t = Mod.Sub.t + type t = Mod.Sub.t< soooooLoooooong, soooooLoooooong, @@ -19,6 +20,7 @@ type t = Mod.Sub.t< b, c, > + type t = Mod.Sub.t< Mod.Sub.t, Nested.Module.t, @@ -45,6 +47,7 @@ let t: list< > = x type t = Option.t<(tupleTyp1, tupleTyp2, tupleTyp3)> + type t = Option.t<( tupleTyp1, tupleTyp2, @@ -57,6 +60,7 @@ type t = Option.t<( tupleTyp3, tupleTyp3, )> + let t: Option.t<( tupleTyp1, tupleTyp2, diff --git a/tests/syntax_tests/data/printer/typexpr/expected/variant.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/variant.res.txt index 4837afcf085..46298f6afb8 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/variant.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/variant.res.txt @@ -11,6 +11,7 @@ let id = (x: [> #Red | #Green | #Blue]) => x let upper = (x: [< #Red | #Green]) => true type point = [#Point(float, float)] type \"type" = [#"Point🗿"(\"let", float)] + type shape = [ | #Rectangle(point, point) | #Circle(point, float) @@ -78,6 +79,7 @@ module type Conjunctive = { let f: [< #T([< u2]) & ([< u2]) & ([< u1])] => unit let g: [< #S & ([< u2]) & ([< u2]) & ([< u1])] => unit + let g: [< | #"Exotic-S+" & ([< #"Exotic-u2+"]) & ([< #"Exotic-u2-"]) & ([< #"Exotic-u1+++"]) ] => unit @@ -92,6 +94,7 @@ type currencyPoly = [ // should not break, user wrote it on one line type currencyPoly = [#USD | #CAD | #EUR] + // // should break, line length exceeded type currencyPoly = [ @@ -126,6 +129,7 @@ type foo = [ // doc comments on inherited polyvariant types type rgb = [#Red | #Green | #Blue] + type color = [ | /** Primary colors from RGB */ rgb /** A warm color */ From fcda8d73ac06b4bace005c0d5c2ca9ddbca0aabe Mon Sep 17 00:00:00 2001 From: Roland Peelen Date: Fri, 23 Oct 2026 14:25:27 +0200 Subject: [PATCH 2/5] Make multi-line item spacing the experimental feature MultilineItemSpacing Why: Spacing multi-line module items changes the output of `rescript format` for most existing projects (341 files in this repository alone), so it is opt-in, like `let?` (LetUnwrap). Without the feature the formatter prints exactly as before, and the snapshots of the previous commit return to their master state. Format modified (multi-line item spacing, opt-in): Example: module A = { let x = 1 } let y = 2 Before (rescript): always, since the previous commit module A = { let x = 1 } let y = 2 After (rescript): "experimental-features": {"MultilineItemSpacing": true} module A = { let x = 1 } let y = 2 Format unchanged (default): Example: module A = { let x = 1 } let y = 2 After (rescript): without the feature module A = { let x = 1 } let y = 2 Diagnostic modified (unknown experimental feature): Example: "experimental-features": {"FooBar": true} Before (diagnostic): Unknown experimental feature 'FooBar'. Available features: LetUnwrap After (diagnostic): Unknown experimental feature 'FooBar'. Available features: LetUnwrap, MultilineItemSpacing Review: How does `rescript format` learn about the feature? Both build systems pass the root project's experimental flags, the same ones a build passes, to `bsc` before `-format`; `-format` runs as soon as bsc reads it, so the order matters. Outside a project, format runs without them, as before. Covered by rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh, which passes for both rescript.exe and rescript-rust.exe. Review: How do the syntax tests enable it? `res_parser` accepts `-enable-experimental`, and scripts/test_syntax.sh prints and round-trips each file under tests/syntax_tests/data/experimental// with that feature enabled. Review: What about tools that call `bsc -format` directly instead of `rescript format`? They format without the feature unless they pass `-enable-experimental MultilineItemSpacing` before `-format`. Signed-off-by: Roland Peelen --- ...formatter-multiline-item-spacing.polish.md | 2 +- compiler/bsc/rescript_compiler_driver.ml | 3 +- compiler/ml/experimental_features.ml | 4 +- compiler/ml/experimental_features.mli | 6 ++- compiler/syntax/cli/res_cli.ml | 3 ++ compiler/syntax/src/res_printer.ml | 7 ++- docs/docson/build-schema.json | 4 ++ rewatch-ocaml/config.ml | 4 +- rewatch-ocaml/format.ml | 21 +++++++-- rewatch/CompilerConfigurationSpec.md | 1 + rewatch/src/config.rs | 5 +- rewatch/src/format.rs | 24 +++++++--- .../01-invalid-experimental-key.sh | 2 +- ...mat-experimental-multiline-item-spacing.sh | 47 +++++++++++++++++++ rewatch/tests/suite.sh | 1 + scripts/test_syntax.sh | 18 +++++-- .../data/ast-mapping/expected/Braces.res.txt | 2 - .../expected/FunctionsAndArrows.res.txt | 1 - .../ast-mapping/expected/JSXElements.res.txt | 2 - .../ast-mapping/expected/JSXFragments.res.txt | 2 - .../expected/JsxComponents.res.txt | 7 --- .../expected/RawExtensions.res.txt | 2 - .../expected/TernaryExpressions.res.txt | 1 - .../data/ast-mapping/expected/regexp.res.txt | 2 - .../reason/expected/bracedJsx.res.txt | 4 -- .../reason/expected/comments.res.txt | 11 ----- .../reason/expected/modType.res.txt | 2 - .../conversion/reason/expected/ppx.res.txt | 3 -- .../expected/multilineSpacing.res.txt | 0 .../expected/multilineSpacing.resi.txt | 0 .../multilineSpacing.res | 0 .../multilineSpacing.resi | 0 .../ppx/react/expected/aliasProps.res.txt | 8 ---- .../ppx/react/expected/asyncAwait.res.txt | 3 -- .../ppx/react/expected/commentAtTop.res.txt | 1 - .../react/expected/defaultPatternProp.res.txt | 3 -- .../react/expected/defaultValueProp.res.txt | 6 --- .../react/expected/fileLevelConfig.res.txt | 1 - .../react/expected/firstClassModules.resi.txt | 1 - .../ppx/react/expected/forwardRef.res.txt | 6 --- .../data/ppx/react/expected/fragment.res.txt | 5 -- .../data/ppx/react/expected/interface.res.txt | 3 -- .../ppx/react/expected/interface.resi.txt | 1 - .../react/expected/interfaceWithRef.res.txt | 2 - .../react/expected/interfaceWithRef.resi.txt | 1 - .../ppx/react/expected/mangleKeyword.res.txt | 2 - .../data/ppx/react/expected/nested.res.txt | 3 -- .../data/ppx/react/expected/newtype.res.txt | 7 --- .../ppx/react/expected/noPropsWithKey.res.txt | 2 - .../expected/optimizeAutomaticMode.res.txt | 2 - .../react/expected/optionalKeyType.res.txt | 3 -- .../react/expected/returnConstraint.res.txt | 4 -- .../ppx/react/expected/sharedProps.res.txt | 4 -- .../expected/sharedPropsWithProps.res.txt | 10 ---- .../data/ppx/react/expected/topLevel.res.txt | 1 - .../ppx/react/expected/typeConstraint.res.txt | 1 - .../ppx/react/expected/uncurriedProps.res.txt | 4 -- .../data/ppx/react/expected/v4.res.txt | 8 ---- .../expected/callbackTrailing.res.txt | 5 -- .../printer/comments/expected/expr.res.txt | 6 --- .../printer/comments/expected/modExpr.res.txt | 2 - .../printer/comments/expected/modType.res.txt | 2 - .../comments/expected/namedArgs.res.txt | 1 - .../printer/comments/expected/pattern.res.txt | 1 - .../comments/expected/structureItem.res.txt | 1 - .../comments/expected/typeDefinition.res.txt | 1 - .../printer/comments/expected/typexpr.res.txt | 5 -- .../comments/expected/valueBindings.res.txt | 1 - .../data/printer/expected/regexp.res.txt | 2 - .../printer/expected/regexpStatements.res.txt | 2 - .../printer/expr/expected/DocComments.res.txt | 2 - .../data/printer/expr/expected/apply.res.txt | 13 ----- .../data/printer/expr/expected/array.res.txt | 1 - .../data/printer/expr/expected/assert.res.txt | 1 - .../printer/expr/expected/assignment.res.txt | 16 ------- .../printer/expr/expected/asyncAwait.res.txt | 9 ---- .../data/printer/expr/expected/binary.res.txt | 21 --------- .../data/printer/expr/expected/block.res.txt | 1 - .../data/printer/expr/expected/braced.res.txt | 25 ---------- .../data/printer/expr/expected/bsObj.res.txt | 2 - .../printer/expr/expected/callback.res.txt | 6 --- .../data/printer/expr/expected/coerce.res.txt | 8 ---- .../printer/expr/expected/constructor.res.txt | 4 -- .../printer/expr/expected/extension.res.txt | 2 - .../data/printer/expr/expected/field.res.txt | 2 - .../expr/expected/firstClassModule.res.txt | 5 -- .../data/printer/expr/expected/fun.res.txt | 8 ---- .../expr/expected/functionLayouts.res.txt | 5 -- .../data/printer/expr/expected/jsx.res.txt | 8 ---- .../printer/expr/expected/jsxChildren.res.txt | 39 --------------- .../expr/expected/jsxChildrenComments.res.txt | 40 ---------------- .../printer/expr/expected/newtype.res.txt | 1 - .../printer/expr/expected/polyvariant.res.txt | 4 -- .../data/printer/expr/expected/record.res.txt | 12 ----- .../printer/expr/expected/refFunction.res.txt | 9 ---- .../printer/expr/expected/setfield.res.txt | 1 - .../printer/expr/expected/ternary.res.txt | 17 ------- .../data/printer/expr/expected/unary.res.txt | 7 --- .../modExpr/expected/attributes.res.txt | 5 -- .../printer/modExpr/expected/functor.res.txt | 6 --- .../printer/modExpr/expected/include.res.txt | 2 - .../printer/modExpr/expected/parens.res.txt | 1 - .../modExpr/expected/structure.res.txt | 3 -- .../modType/expected/moduleTypeOf.res.txt | 1 - .../modType/expected/withConstraints.res.txt | 6 --- .../other/expected/StaticReactTypes.res.txt | 1 - .../printer/other/expected/attributes.res.txt | 1 - .../printer/other/expected/fatSlider.res.txt | 1 - .../printer/pattern/expected/alias.res.txt | 1 - .../expected/firstClassModules.res.txt | 1 - .../printer/pattern/expected/list.res.txt | 1 - .../printer/pattern/expected/record.res.txt | 12 ----- .../signature/expected/exception.resi.txt | 1 - .../expected/externalObjectSpread.resi.txt | 1 - .../structure/expected/exception.res.txt | 4 -- .../expected/externalObjectSpread.res.txt | 1 - .../structure/expected/include.res.txt | 1 - .../structure/expected/typeExtension.res.txt | 12 ----- .../printer/typeDef/expected/abstract.res.txt | 1 - .../typeDef/expected/attributes.res.txt | 3 -- .../expected/inlineRecordMultiline.res.txt | 1 - .../printer/typeDef/expected/record.res.txt | 4 -- .../printer/typeDef/expected/variant.res.txt | 7 --- .../printer/typexpr/expected/arrow.res.txt | 2 - .../printer/typexpr/expected/bsObject.res.txt | 3 -- .../typexpr/expected/firstClassModule.res.txt | 1 - .../expected/objectTypeSpreading.res.txt | 2 - .../typexpr/expected/typeConstr.res.txt | 4 -- .../printer/typexpr/expected/variant.res.txt | 4 -- 129 files changed, 129 insertions(+), 546 deletions(-) create mode 100755 rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh rename tests/syntax_tests/data/{printer/structure => experimental/MultilineItemSpacing}/expected/multilineSpacing.res.txt (100%) rename tests/syntax_tests/data/{printer/signature => experimental/MultilineItemSpacing}/expected/multilineSpacing.resi.txt (100%) rename tests/syntax_tests/data/{printer/structure => experimental/MultilineItemSpacing}/multilineSpacing.res (100%) rename tests/syntax_tests/data/{printer/signature => experimental/MultilineItemSpacing}/multilineSpacing.resi (100%) diff --git a/changes/formatter-multiline-item-spacing.polish.md b/changes/formatter-multiline-item-spacing.polish.md index 35142e74164..b5d71338686 100644 --- a/changes/formatter-multiline-item-spacing.polish.md +++ b/changes/formatter-multiline-item-spacing.polish.md @@ -1 +1 @@ -- Format a blank line before and after a top-level or module-level item that spans several lines. +- Add the experimental feature `MultilineItemSpacing`: with `"experimental-features": {"MultilineItemSpacing": true}`, `rescript format` puts a blank line before and after a module item that spans several lines. diff --git a/compiler/bsc/rescript_compiler_driver.ml b/compiler/bsc/rescript_compiler_driver.ml index 95b681469c6..c8c8dbff3e0 100644 --- a/compiler/bsc/rescript_compiler_driver.ml +++ b/compiler/bsc/rescript_compiler_driver.ml @@ -492,7 +492,8 @@ let command_line_flags () : (string * Bsc_args.spec * string) array = ( "-enable-experimental", string_call Experimental_features.enable_from_string, "Enable experimental features: repeatable, e.g. -enable-experimental \ - LetUnwrap" ); + LetUnwrap. Pass it before -format to format with a feature such as \ + MultilineItemSpacing" ); (* Not used, the build system did the expansion *) ( "-bs-no-bin-annot", clear (Clflags.current ()).binary_annotations, diff --git a/compiler/ml/experimental_features.ml b/compiler/ml/experimental_features.ml index 5ec591c740f..67de5b9ce1f 100644 --- a/compiler/ml/experimental_features.ml +++ b/compiler/ml/experimental_features.ml @@ -1,12 +1,14 @@ -type feature = LetUnwrap +type feature = LetUnwrap | MultilineItemSpacing let to_string (f : feature) : string = match f with | LetUnwrap -> "LetUnwrap" + | MultilineItemSpacing -> "MultilineItemSpacing" let from_string (s : string) : feature option = match s with | "LetUnwrap" -> Some LetUnwrap + | "MultilineItemSpacing" -> Some MultilineItemSpacing | _ -> None module Feature_set = Set.Make (struct diff --git a/compiler/ml/experimental_features.mli b/compiler/ml/experimental_features.mli index ad3fdd925c2..e5900d1dfe4 100644 --- a/compiler/ml/experimental_features.mli +++ b/compiler/ml/experimental_features.mli @@ -1,4 +1,8 @@ -type feature = LetUnwrap +type feature = + | LetUnwrap + | MultilineItemSpacing + (** The formatter separates module items that span several lines with a + blank line. *) val enable_from_string : string -> unit diff --git a/compiler/syntax/cli/res_cli.ml b/compiler/syntax/cli/res_cli.ml index da701416e81..01317f092b9 100644 --- a/compiler/syntax/cli/res_cli.ml +++ b/compiler/syntax/cli/res_cli.ml @@ -55,6 +55,9 @@ end = struct ( "-test-ast-conversion", Arg.Unit (fun () -> test_ast_conversion := true), "Test the ast conversion" ); + ( "-enable-experimental", + Arg.String Experimental_features.enable_from_string, + "Enable an experimental feature, e.g. MultilineItemSpacing" ); ] let parse () = Arg.parse spec (fun f -> file := f) usage diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index fede41d2f6e..52891025f13 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -687,12 +687,15 @@ module State = struct let should_break_callback t = t.custom_layout > custom_layout_threshold end +let space_multiline () = + Experimental_features.is_enabled Experimental_features.MultilineItemSpacing + let rec print_structure ~state (s : Parsetree.structure) t = match s with | [] -> print_comments_inside_file t | structure -> let previous_can_continue = ref false in - print_list ~space_multiline:true + print_list ~space_multiline:(space_multiline ()) ~get_loc:(fun s -> s.Parsetree.pstr_loc) ~nodes:structure ~print:(fun item cmt_tbl -> @@ -1110,7 +1113,7 @@ and print_signature ~state signature cmt_tbl = match signature with | [] -> print_comments_inside_file cmt_tbl | signature -> - print_list ~space_multiline:true + print_list ~space_multiline:(space_multiline ()) ~get_loc:(fun s -> s.Parsetree.psig_loc) ~nodes:signature ~print:(print_signature_item ~state) diff --git a/docs/docson/build-schema.json b/docs/docson/build-schema.json index 21f48b1f223..4be54e2af44 100644 --- a/docs/docson/build-schema.json +++ b/docs/docson/build-schema.json @@ -556,6 +556,10 @@ "LetUnwrap": { "type": "boolean", "description": "Enable `let?` syntax." + }, + "MultilineItemSpacing": { + "type": "boolean", + "description": "Format a blank line before and after a module item that spans several lines." } }, "additionalProperties": false diff --git a/rewatch-ocaml/config.ml b/rewatch-ocaml/config.ml index eb5fd35d5d7..e386b4bbeca 100644 --- a/rewatch-ocaml/config.ml +++ b/rewatch-ocaml/config.ml @@ -246,11 +246,11 @@ let decode_experimental_features path fields = reject_duplicates path "experimental-features" features; features |> List.concat_map (fun (name, value) -> - if name <> "LetUnwrap" then + if not (List.mem name ["LetUnwrap"; "MultilineItemSpacing"]) then fail path (Printf.sprintf "Unknown experimental feature '%s'. Available features: \ - LetUnwrap" + LetUnwrap, MultilineItemSpacing" name); match value with | `Bool true -> ["-enable-experimental"; name] diff --git a/rewatch-ocaml/format.ml b/rewatch-ocaml/format.ml index a79bfb5740c..be27926f944 100644 --- a/rewatch-ocaml/format.ml +++ b/rewatch-ocaml/format.ml @@ -115,11 +115,22 @@ let files_in_scope ~verbosity = let formatting_error target stderr = Printf.sprintf "Error formatting %s: %s" target stderr -let format_request path = - Compiler_process.{args = ["-format"; path]; cwd = Sys.getcwd ()} +(* The experimental features of the current project, such as + MultilineItemSpacing, as bsc flags. They must precede -format. Outside a + project, format runs without them, like Rust rewatch. *) +let experimental_args () = + try + let current = Config.load_root (Sys.getcwd ()) in + (Project_context.workspace_config_for current).experimental_args + with Config.Error _ -> [] + +let format_request ~experimental_args path = + Compiler_process. + {args = experimental_args @ ["-format"; path]; cwd = Sys.getcwd ()} let formatted ?poll ~target path = - let result = Compiler_process.run ?poll (format_request path) in + let request = format_request ~experimental_args:(experimental_args ()) path in + let result = Compiler_process.run ?poll request in if not (Process.succeeded result) then raise (Error (formatting_error target result.stderr)); result.stdout @@ -129,6 +140,7 @@ let format_check_summary = function | count -> Printf.sprintf "The %d files listed above need formatting" count let format_files ?poll ~check files = + let experimental_args = experimental_args () in let incorrect = ref 0 in let works = files @@ -137,7 +149,8 @@ let format_files ?poll ~check files = {key = Printf.sprintf "%08d" index; dependencies = []; value = path}) in let next path = function - | None -> Some (Compiler_process.task (format_request path)) + | None -> + Some (Compiler_process.task (format_request ~experimental_args path)) | Some result -> if not (Process.succeeded result) then raise (Error (formatting_error path result.stderr)); diff --git a/rewatch/CompilerConfigurationSpec.md b/rewatch/CompilerConfigurationSpec.md index ca172caaaee..3e156c93457 100644 --- a/rewatch/CompilerConfigurationSpec.md +++ b/rewatch/CompilerConfigurationSpec.md @@ -122,6 +122,7 @@ An object of feature flags to enable experimental compiler behavior. Only suppor Currently supported features: - LetUnwrap: Enable `let?` syntax. +- MultilineItemSpacing: `rescript format` puts a blank line before and after a module item that spans several lines. ### Warnings diff --git a/rewatch/src/config.rs b/rewatch/src/config.rs index 20f772b33b0..256ea7c0832 100644 --- a/rewatch/src/config.rs +++ b/rewatch/src/config.rs @@ -505,6 +505,7 @@ pub enum DeprecationWarning { #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub enum ExperimentalFeature { LetUnwrap, + MultilineItemSpacing, } impl<'de> serde::Deserialize<'de> for ExperimentalFeature { @@ -524,8 +525,9 @@ impl<'de> serde::Deserialize<'de> for ExperimentalFeature { { match v { "LetUnwrap" => Ok(ExperimentalFeature::LetUnwrap), + "MultilineItemSpacing" => Ok(ExperimentalFeature::MultilineItemSpacing), other => { - let available = ["LetUnwrap"].join(", "); + let available = ["LetUnwrap", "MultilineItemSpacing"].join(", "); Err(DeError::custom(format!( "Unknown experimental feature '{other}'. Available features: {available}", ))) @@ -963,6 +965,7 @@ impl Config { "-enable-experimental".to_string(), match feature { ExperimentalFeature::LetUnwrap => "LetUnwrap", + ExperimentalFeature::MultilineItemSpacing => "MultilineItemSpacing", } .to_string(), ] diff --git a/rewatch/src/format.rs b/rewatch/src/format.rs index eed70f0812f..44a50cdd837 100644 --- a/rewatch/src/format.rs +++ b/rewatch/src/format.rs @@ -16,10 +16,11 @@ use clap::ValueEnum; #[instrument(name = "format.format", skip_all)] pub fn format(stdin_extension: Option, check: bool, files: Vec) -> Result<()> { let bsc_path = helpers::get_bsc(); + let experimental_args = experimental_args(); match stdin_extension { Some(extension) => { - format_stdin(&bsc_path, extension)?; + format_stdin(&bsc_path, &experimental_args, extension)?; } None => { let files = if files.is_empty() { @@ -27,13 +28,24 @@ pub fn format(stdin_extension: Option, check: bool, files: Vec Vec { + std::env::current_dir() + .ok() + .and_then(|dir| project_context::ProjectContext::new(&dir).ok()) + .map(|context| context.get_root_config().get_experimental_features_args()) + .unwrap_or_default() +} + fn get_files_in_scope() -> Result> { let current_dir = std::env::current_dir()?; let project_context = project_context::ProjectContext::new(¤t_dir)?; @@ -59,7 +71,7 @@ fn get_files_in_scope() -> Result> { Ok(files) } -fn format_stdin(bsc_exe: &Path, extension: FileExtension) -> Result<()> { +fn format_stdin(bsc_exe: &Path, experimental_args: &[String], extension: FileExtension) -> Result<()> { let extension_value = extension .to_possible_value() .ok_or(anyhow::anyhow!("Could not get extension arg value"))?; @@ -71,7 +83,7 @@ fn format_stdin(bsc_exe: &Path, extension: FileExtension) -> Result<()> { let temp_path = temp_file.path(); let mut cmd = Command::new(bsc_exe); - cmd.arg("-format").arg(temp_path); + cmd.args(experimental_args).arg("-format").arg(temp_path); let output = cmd.output()?; @@ -85,7 +97,7 @@ fn format_stdin(bsc_exe: &Path, extension: FileExtension) -> Result<()> { Ok(()) } -fn format_files(bsc_exe: &Path, files: Vec, check: bool) -> Result<()> { +fn format_files(bsc_exe: &Path, experimental_args: &[String], files: Vec, check: bool) -> Result<()> { let batch_size = 4 * num_cpus::get(); let incorrectly_formatted_files = AtomicUsize::new(0); @@ -93,7 +105,7 @@ fn format_files(bsc_exe: &Path, files: Vec, check: bool) -> Result<()> { batch.iter().try_for_each(|file| { let mut cmd = Command::new(bsc_exe); // Always get formatted output to stdout for comparison - cmd.arg("-format").arg(file); + cmd.args(experimental_args).arg("-format").arg(file); let output = cmd.output()?; diff --git a/rewatch/tests/experimental-invalid/01-invalid-experimental-key.sh b/rewatch/tests/experimental-invalid/01-invalid-experimental-key.sh index ae52f70ae7d..0df1238a304 100755 --- a/rewatch/tests/experimental-invalid/01-invalid-experimental-key.sh +++ b/rewatch/tests/experimental-invalid/01-invalid-experimental-key.sh @@ -25,7 +25,7 @@ if [ $status -eq 0 ]; then exit 1 fi -echo "$out" | grep -q "Unknown experimental feature 'FooBar'. Available features: LetUnwrap" +echo "$out" | grep -q "Unknown experimental feature 'FooBar'. Available features: LetUnwrap, MultilineItemSpacing" if [ $? -ne 0 ]; then error "Missing helpful message for unknown experimental feature" echo "$out" diff --git a/rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh b/rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh new file mode 100755 index 00000000000..71c985638e5 --- /dev/null +++ b/rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh @@ -0,0 +1,47 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: format spaces multi-line items only with MultilineItemSpacing" + +input='module A = { + let x = 1 +} +let y = 2 +let z = 3 +' +expected='module A = { + let x = 1 +} + +let y = 2 +let z = 3' + +without=$(printf '%s' "$input" | "$REWATCH_EXECUTABLE" format --stdin .res) +# $(...) drops the trailing newline, so compare against the input without it +if [ $? -ne 0 ] || [ "$without" != "${input%$'\n'}" ]; then + error "Format changed spacing without the experimental feature" + echo "$without" + exit 1 +fi + +cp rescript.json rescript.json.bak +node -e ' +const fs=require("fs"); +const j=JSON.parse(fs.readFileSync("rescript.json","utf8")); +j["experimental-features"]={MultilineItemSpacing:true}; +fs.writeFileSync("rescript.json", JSON.stringify(j,null,2)); +' + +with=$(printf '%s' "$input" | "$REWATCH_EXECUTABLE" format --stdin .res) +status=$? +mv rescript.json.bak rescript.json + +if [ $status -ne 0 ] || [ "$with" != "$expected" ]; then + error "Format did not space multi-line items with MultilineItemSpacing" + echo "$with" + exit 1 +fi + +success "MultilineItemSpacing is opt-in for format" diff --git a/rewatch/tests/suite.sh b/rewatch/tests/suite.sh index a1551ffcc97..418724c8bbc 100755 --- a/rewatch/tests/suite.sh +++ b/rewatch/tests/suite.sh @@ -120,6 +120,7 @@ fi ./format/02-format-single-file.sh && ./format/03-format-stdin.sh && ./format/04-format-current-project.sh && +./format/05-format-experimental-multiline-item-spacing.sh && # Clean tests ./clean/01-clean-single-project.sh && diff --git a/scripts/test_syntax.sh b/scripts/test_syntax.sh index c615a3b9f0a..2bac2862b06 100755 --- a/scripts/test_syntax.sh +++ b/scripts/test_syntax.sh @@ -60,6 +60,17 @@ while read file; do $DUNE_BIN_DIR/res_parser -test-ast-conversion -jsx-version 4 $file &> $(exp $file) & maybeWait done / +function experimentalFlags { + case $1 in + syntax_tests/data/experimental/*) echo "-enable-experimental $(echo $1 | cut -d/ -f4)" ;; + esac +} +find syntax_tests/data/experimental -name "*.res" -o -name "*.resi" >temp/files.txt +while read file; do + $DUNE_BIN_DIR/res_parser $(experimentalFlags $file) $file &> $(exp $file) & maybeWait +done temp/files.txt while read file; do @@ -88,7 +99,7 @@ if [[ $ROUNDTRIP_TEST = 1 ]]; then roundtripTestsResult="temp/result.txt" touch $roundtripTestsResult - find syntax_tests/data/{idempotency,printer} -name "*.res" -o -name "*.resi" >temp/files.txt + find syntax_tests/data/{idempotency,printer,experimental} -name "*.res" -o -name "*.resi" >temp/files.txt while read file; do { mkdir -p temp/$(dirname $file) rescript1=temp/$file.res @@ -100,8 +111,9 @@ if [[ $ROUNDTRIP_TEST = 1 ]]; then esac # Format the original file, then format the result again - $DUNE_BIN_DIR/res_parser $resIntf -print res $file > $rescript1 - $DUNE_BIN_DIR/res_parser $resIntf -print res $rescript1 > $rescript2 + flags="$resIntf $(experimentalFlags $file)" + $DUNE_BIN_DIR/res_parser $flags -print res $file > $rescript1 + $DUNE_BIN_DIR/res_parser $flags -print res $rescript1 > $rescript2 # Check idempotency: formatting the formatted text must not change it diff --unified $rescript1 $rescript2 diff --git a/tests/syntax_tests/data/ast-mapping/expected/Braces.res.txt b/tests/syntax_tests/data/ast-mapping/expected/Braces.res.txt index 32986b560c3..94ec22a3e38 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/Braces.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/Braces.res.txt @@ -1,11 +1,9 @@ let value = {42} - let branch = if true { 1 } else { 2 } - let case = switch value { | 42 => value | _ => 0 diff --git a/tests/syntax_tests/data/ast-mapping/expected/FunctionsAndArrows.res.txt b/tests/syntax_tests/data/ast-mapping/expected/FunctionsAndArrows.res.txt index 4763329d388..508c2860fb2 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/FunctionsAndArrows.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/FunctionsAndArrows.res.txt @@ -7,7 +7,6 @@ let id = x => x // labeled, optional, and default parameters let labeled = (~x, ~y) => x - y - let optional = (~x=?, ~y=1, z) => { switch x { | Some(x) => x + y + z diff --git a/tests/syntax_tests/data/ast-mapping/expected/JSXElements.res.txt b/tests/syntax_tests/data/ast-mapping/expected/JSXElements.res.txt index 2cbfcb9c121..835aab0f9f5 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/JSXElements.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/JSXElements.res.txt @@ -39,9 +39,7 @@ let elementWithConditionalChildren = ReactDOM.jsx( }), }, ) - let commentOnly = ReactDOM.jsx("div", {/* no child */}) - let commentsBetweenElements = ReactDOM.jsx( "div", { diff --git a/tests/syntax_tests/data/ast-mapping/expected/JSXFragments.res.txt b/tests/syntax_tests/data/ast-mapping/expected/JSXFragments.res.txt index e2c9e22a1e2..b80a42ace16 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/JSXFragments.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/JSXFragments.res.txt @@ -22,9 +22,7 @@ let nestedFragments = React.jsxs( ]), }, ) - let commentOnly = React.jsx(React.jsxFragment, {}) // no child - let commentsBetweenElements = React.jsxs( React.jsxFragment /* between */, {children: React.array([ReactDOM.jsx("span", {}), ReactDOM.jsx("span", {})])}, diff --git a/tests/syntax_tests/data/ast-mapping/expected/JsxComponents.res.txt b/tests/syntax_tests/data/ast-mapping/expected/JsxComponents.res.txt index a2383bfba1e..b463e41a075 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/JsxComponents.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/JsxComponents.res.txt @@ -3,9 +3,7 @@ module A = { type props<'x> = { x: 'x, } - let make = ({x, _}: props<_>): React.element => React.string(x) - let make = React.component({ let \"JsxComponents$A" = (props: props<_>) => make(props) \"JsxComponents$A" @@ -17,7 +15,6 @@ module B = { /** Doc */ @deprecated @genType let make = ({x, _}: props): React.element => React.string(x) - /** Doc */ @deprecated @genType let make = React.component({ @@ -29,7 +26,6 @@ module B = { module C = { let make = (props: props): React.element => React.string(props.x) - let make = React.component({ let \"JsxComponents$C" = (props: props): React.element => make(props) \"JsxComponents$C" @@ -38,7 +34,6 @@ module C = { module D = { let make = (props: props): React.element => React.string(props.x) - let make = React.component({ let \"JsxComponents$D" = (props: props): React.element => make(props) \"JsxComponents$D" @@ -62,7 +57,6 @@ module F: { } let make: React.component> - @jsx.componentWithProps let other: props => React.element } = { @@ -72,7 +66,6 @@ module F: { } let make = ({x, _}: props<_>): React.element => React.string(x) - let make = React.component({ let \"JsxComponents$F" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ast-mapping/expected/RawExtensions.res.txt b/tests/syntax_tests/data/ast-mapping/expected/RawExtensions.res.txt index 6e9b07042e1..3b21442b871 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/RawExtensions.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/RawExtensions.res.txt @@ -1,9 +1,7 @@ let add = %raw("(a, b) => a + b") - let template = %raw(`function (a) { return "x" + a }`) - let escaped = %raw(`"a\`b\${c}"`) let fn = %ffi("(a) => a + 1") let applied = %ffi(`(a, b) => a * b`)(2, 3) diff --git a/tests/syntax_tests/data/ast-mapping/expected/TernaryExpressions.res.txt b/tests/syntax_tests/data/ast-mapping/expected/TernaryExpressions.res.txt index 2c2c02bb2a4..3fb4f4dbcaf 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/TernaryExpressions.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/TernaryExpressions.res.txt @@ -2,7 +2,6 @@ let choose = (condition, yes, no) => condition ? yes : no let nested = (first, second, a, b, c) => first ? a : second ? b : c let inCondition = (first, second, a, b, c) => (first ? second : false) ? a : b + c - let mixed = (condition, yes, no) => if condition { condition ? yes : no diff --git a/tests/syntax_tests/data/ast-mapping/expected/regexp.res.txt b/tests/syntax_tests/data/ast-mapping/expected/regexp.res.txt index 16806da9d3b..5818664601b 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/regexp.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/regexp.res.txt @@ -4,10 +4,8 @@ let characterClass = /[/\]]+/u let unicode = /世界+/g let dot = /./s let flags = /a/dgimsuy - @foo let attributed = /a/g - let comments = [/* before */ /a/g /* after */, /b/] let use = f(/a/i, /b/m) let expressionAttributes = @foo /a/g diff --git a/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt b/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt index c7dc9e340d6..241cb963078 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/bracedJsx.res.txt @@ -15,7 +15,6 @@ type state = { module Styles = { open Css - let terminal = style(list{ margin(10->px), backgroundColor("222"->hex), @@ -27,9 +26,7 @@ module Styles = { fontFamily(#custom(Theme.codeFontFamily)), unsafe("WebkitOverflowScrolling", "touch"), }) - let line = style(list{whiteSpace(#preWrap)}) - let input = style(list{ backgroundColor("222"->hex), fontFamily(#custom(Theme.codeFontFamily)), @@ -40,7 +37,6 @@ module Styles = { padding(zero), outlineStyle(none), }) - let title = style(list{ fontSize(48->px), fontWeight(extraBold), diff --git a/tests/syntax_tests/data/conversion/reason/expected/comments.res.txt b/tests/syntax_tests/data/conversion/reason/expected/comments.res.txt index 5065f0e7637..948e3ba49be 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/comments.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/comments.res.txt @@ -5,7 +5,6 @@ let /* a */ x /* b */ = /* c */ 1 /* comment 2 */ // comment 4 let x = 1 /* 5 */ - /* 6 */ let f = ( @@ -19,7 +18,6 @@ let f = ( // 7 y: 2, // 8 } - /* **** comment */ /* ** comment */ /* comment */ @@ -70,7 +68,6 @@ type variant = | X(int) /* End of line on X */ /* Comment above Y */ | Y(int) /* End of line on Y */ - /* Comment on entire type def for variant */ type rec x = { @@ -142,14 +139,12 @@ let store_attributes = arg => { Temp.logIt(proc_name, ()) } } - 3 // - 3 //- 3 //- 3 /* - */ - // **** comment /* ** comment */ @ocaml.doc(" docstring ") @@ -295,7 +290,6 @@ type t3 = (int, int) // End of line on (int, int) type variant = | X(int, int) // End of line on X | Y(int, int) // End of line on Y - // Comment on entire type def for variant // Before let @@ -427,7 +421,6 @@ let result = @ocaml.doc("") (2 + 3) // }; let a = () - for i in 0 to 10 { // bla a @@ -441,7 +434,6 @@ type color = | Red(int) // After red end of line | Black(int) // After black end of line | Green(int) // After green end of line - // On next line after color type def let blahCurriedX = (x, x) => @@ -453,7 +445,6 @@ let blahCurriedX = (x, x) => | Black(x) => 0 // After black | Green(x) => 0 } // After second green - // On next line after blahCurriedX def let name_equal = (x, y) => x == y @@ -640,7 +631,6 @@ while trueThing { // does work ) } - while trueThing { f( // a @@ -671,7 +661,6 @@ ignore((_xxx, _yyy) => { type tester<'a, 'b> = | TwoArgsConstructor('a, 'b) | OneTupleArgConstructor(('a, 'b)) - let callFunctionTwoArgs = (a, b) => () let callFunctionOneTuple = tuple => () diff --git a/tests/syntax_tests/data/conversion/reason/expected/modType.res.txt b/tests/syntax_tests/data/conversion/reason/expected/modType.res.txt index a3454a224b9..260265ccf4d 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/modType.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/modType.res.txt @@ -1,14 +1,12 @@ module Same = (Na: N, Nb: N): ((S with type number1 = Na.number) with type number2 = Nb.number) => { type number1 = Na.number type number2 = Nb.number - let rec sim = ((n, m)) => if Na.is_zero(n) { Nb.is_zero(m) } else { sim((Na.pred(n), Nb.pred(m))) } - let similar = ((n, m)) => try sim((n, m)) catch { | Na.Too_small => false diff --git a/tests/syntax_tests/data/conversion/reason/expected/ppx.res.txt b/tests/syntax_tests/data/conversion/reason/expected/ppx.res.txt index 3800c8052d9..3f0dda10e0a 100644 --- a/tests/syntax_tests/data/conversion/reason/expected/ppx.res.txt +++ b/tests/syntax_tests/data/conversion/reason/expected/ppx.res.txt @@ -10,7 +10,6 @@ } } ` - {taggedTemplate: false} ) @@ -22,9 +21,7 @@ module Form = %form( @as("form-name") formName: string, } - type output = input - let validators = { name: { strategy: OnFirstBlur, diff --git a/tests/syntax_tests/data/printer/structure/expected/multilineSpacing.res.txt b/tests/syntax_tests/data/experimental/MultilineItemSpacing/expected/multilineSpacing.res.txt similarity index 100% rename from tests/syntax_tests/data/printer/structure/expected/multilineSpacing.res.txt rename to tests/syntax_tests/data/experimental/MultilineItemSpacing/expected/multilineSpacing.res.txt diff --git a/tests/syntax_tests/data/printer/signature/expected/multilineSpacing.resi.txt b/tests/syntax_tests/data/experimental/MultilineItemSpacing/expected/multilineSpacing.resi.txt similarity index 100% rename from tests/syntax_tests/data/printer/signature/expected/multilineSpacing.resi.txt rename to tests/syntax_tests/data/experimental/MultilineItemSpacing/expected/multilineSpacing.resi.txt diff --git a/tests/syntax_tests/data/printer/structure/multilineSpacing.res b/tests/syntax_tests/data/experimental/MultilineItemSpacing/multilineSpacing.res similarity index 100% rename from tests/syntax_tests/data/printer/structure/multilineSpacing.res rename to tests/syntax_tests/data/experimental/MultilineItemSpacing/multilineSpacing.res diff --git a/tests/syntax_tests/data/printer/signature/multilineSpacing.resi b/tests/syntax_tests/data/experimental/MultilineItemSpacing/multilineSpacing.resi similarity index 100% rename from tests/syntax_tests/data/printer/signature/multilineSpacing.resi rename to tests/syntax_tests/data/experimental/MultilineItemSpacing/multilineSpacing.resi diff --git a/tests/syntax_tests/data/ppx/react/expected/aliasProps.res.txt b/tests/syntax_tests/data/ppx/react/expected/aliasProps.res.txt index f85b0d3f5b3..cf1e0bc6ad1 100644 --- a/tests/syntax_tests/data/ppx/react/expected/aliasProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/aliasProps.res.txt @@ -15,7 +15,6 @@ module C0 = { let text = __text_value (React.string(text): React.element) } - let make = React.component({ let \"AliasProps$C0" = (props: props<_>) => make(props) @@ -38,7 +37,6 @@ module C1 = { let text = __text_value (React.string(p ++ text): React.element) } - let make = React.component({ let \"AliasProps$C1" = (props: props<_>) => make(props) @@ -60,7 +58,6 @@ module C2 = { let bar = __foo_value (React.string(bar): React.element) } - let make = React.component({ let \"AliasProps$C2" = (props: props<_>) => make(props) @@ -93,7 +90,6 @@ module C3 = { }: React.element ) } - let make = React.component({ let \"AliasProps$C3" = (props: props<_>) => make(props) @@ -116,7 +112,6 @@ module C4 = { let x = __x_value (ReactDOM.jsx("div", {children: ?ReactDOM.someElement(b)}): React.element) } - let make = React.component({ let \"AliasProps$C4" = (props: props<_>) => make(props) @@ -139,7 +134,6 @@ module C5 = { let z = __z_value (x + y + z: React.element) } - let make = React.component({ let \"AliasProps$C5" = (props: props<_>) => make(props) @@ -154,7 +148,6 @@ module C6 = { let make: React.component } - @res.jsxComponentProps type props<'comp, 'x> = { comp: 'comp, @@ -163,7 +156,6 @@ module C6 = { let make = ({comp: module(Comp: Comp), x: (a, b), _}: props<_, _>): React.element => React.jsx(Comp.make, {}) - let make = React.component({ let \"AliasProps$C6" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt b/tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt index d9e7f3b5eb0..f0dce005e25 100644 --- a/tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt @@ -10,7 +10,6 @@ module C0 = { let a = await f(a) ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})}) } - let make = React.component({ let \"AsyncAwait$C0" = (props: props<_>) => Jsx.promise(make(props)) @@ -30,7 +29,6 @@ module C1 = { | #off => React.string("off") } } - let make = React.component({ let \"AsyncAwait$C1" = (props: props<_>) => Jsx.promise(make(props)) @@ -48,7 +46,6 @@ module Braced = { let a = await f(a) ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})}) } - let make = React.component({ let \"AsyncAwait$Braced" = (props: props<_>) => Jsx.promise(make(props)) diff --git a/tests/syntax_tests/data/ppx/react/expected/commentAtTop.res.txt b/tests/syntax_tests/data/ppx/react/expected/commentAtTop.res.txt index c0a48e04662..033f9b418d6 100644 --- a/tests/syntax_tests/data/ppx/react/expected/commentAtTop.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/commentAtTop.res.txt @@ -6,7 +6,6 @@ type props<'msg> = { let make = ({msg, _}: props<_>): React.element => { ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})}) } - let make = React.component({ let \"CommentAtTop" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/defaultPatternProp.res.txt b/tests/syntax_tests/data/ppx/react/expected/defaultPatternProp.res.txt index ddf93b36486..b1ea9117691 100644 --- a/tests/syntax_tests/data/ppx/react/expected/defaultPatternProp.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/defaultPatternProp.res.txt @@ -6,7 +6,6 @@ module C0 = { type props = {} let make = (_: props): React.element => React.null - let make = React.component({ let \"DefaultPatternProp$C0$M" = props => make(props) @@ -15,7 +14,6 @@ module C0 = { } module type S = module type of M - @res.jsxComponentProps type props<'component> = { component?: 'component, @@ -29,7 +27,6 @@ module C0 = { let module(C: S) = __component_value (React.jsx(C.make, {}): React.element) } - let make = React.component({ let \"DefaultPatternProp$C0" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/defaultValueProp.res.txt b/tests/syntax_tests/data/ppx/react/expected/defaultValueProp.res.txt index ba31d682b2e..5406c7724d4 100644 --- a/tests/syntax_tests/data/ppx/react/expected/defaultValueProp.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/defaultValueProp.res.txt @@ -4,7 +4,6 @@ module C0 = { a?: 'a, b?: 'b, } - let make = ({a: ?__a, b: ?__b, _}: props<_, _>) => { let __a_value = switch __a { | Some(a) => a @@ -18,7 +17,6 @@ module C0 = { let b = __b_value (React.int(a + b): React.element) } - let make = React.component({ let \"DefaultValueProp$C0" = (props: props<_>) => make(props) \"DefaultValueProp$C0" @@ -40,7 +38,6 @@ module C1 = { let a = __a_value (React.int(a + b): React.element) } - let make = React.component({ let \"DefaultValueProp$C1" = (props: props<_>) => make(props) @@ -50,7 +47,6 @@ module C1 = { module C2 = { let a = "foo" - @res.jsxComponentProps type props<'a> = { a?: 'a, @@ -64,7 +60,6 @@ module C2 = { let a = __a_value (React.string(a): React.element) } - let make = React.component({ let \"DefaultValueProp$C2" = (props: props<_>) => make(props) @@ -90,7 +85,6 @@ module C3 = { }: React.element ) } - let make = React.component({ let \"DefaultValueProp$C3" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/fileLevelConfig.res.txt b/tests/syntax_tests/data/ppx/react/expected/fileLevelConfig.res.txt index eeec4feefd4..2cd52b3ac31 100644 --- a/tests/syntax_tests/data/ppx/react/expected/fileLevelConfig.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/fileLevelConfig.res.txt @@ -9,7 +9,6 @@ module V4A = { let make = ({msg, _}: props<_>): Preact.element => { Preact.Elements.jsx("div", {children: ?Preact.Elements.someElement({msg->React.string})}) } - let make = Preact.component({ let \"FileLevelConfig$V4A" = (props: props<_>) => make(props) 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 1b0812a8c6c..feabbdaf5f4 100644 --- a/tests/syntax_tests/data/ppx/react/expected/firstClassModules.resi.txt +++ b/tests/syntax_tests/data/ppx/react/expected/firstClassModules.resi.txt @@ -5,7 +5,6 @@ module Select: { type key type t } - @res.jsxComponentProps type props<'model, 'selected, 'onChange, 'items> = { model: 'model, 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 34b6281e1c7..f23f859040f 100644 --- a/tests/syntax_tests/data/ppx/react/expected/forwardRef.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/forwardRef.res.txt @@ -29,14 +29,12 @@ module V4A = { ]), }, ) - let make = React.forwardRef({ let \"ForwardRef$V4A$FancyInput" = (props: props<_>, ref) => make(props, ref) \"ForwardRef$V4A$FancyInput" }) } - @res.jsxComponentProps type props = {} @@ -52,7 +50,6 @@ module V4A = { }, ) } - let make = React.component({ let \"ForwardRef$V4A" = props => make(props) @@ -89,14 +86,12 @@ module V4AUncurried = { ]), }, ) - let make = React.forwardRef({ let \"ForwardRef$V4AUncurried$FancyInput" = (props: props<_>, ref) => make(props, ref) \"ForwardRef$V4AUncurried$FancyInput" }) } - @res.jsxComponentProps type props = {} @@ -112,7 +107,6 @@ module V4AUncurried = { }, ) } - let make = React.component({ let \"ForwardRef$V4AUncurried" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/fragment.res.txt b/tests/syntax_tests/data/ppx/react/expected/fragment.res.txt index 67f207d12a5..80c3bb1d868 100644 --- a/tests/syntax_tests/data/ppx/react/expected/fragment.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/fragment.res.txt @@ -2,26 +2,21 @@ let _ = React.jsx(React.jsxFragment, {}) let _ = React.jsx(React.jsxFragment, {children: ReactDOM.jsx("div", {})}) - let _ = React.jsxs( React.jsxFragment, {children: React.array([ReactDOM.jsx("div", {}), ReactDOM.jsx("div", {})])}, ) - let _ = React.jsx(React.jsxFragment, {children: React.jsx(React.jsxFragment, {})}) let _ = React.jsx(Z.make, {}) let _ = React.jsx(Z.make, {children: ReactDOM.jsx("div", {})}) let _ = React.jsx(Z.make, {a: "a", children: ReactDOM.jsx("div", {})}) - let _ = React.jsxs( Z.make, {children: React.array([ReactDOM.jsx("div", {}), ReactDOM.jsx("div", {})])}, ) - let _ = ReactDOM.jsx("div", {}) let _ = ReactDOM.jsx("div", {children: ?ReactDOM.someElement(ReactDOM.jsx("div", {}))}) let _ = ReactDOM.jsx("div", {id: "id", children: ?ReactDOM.someElement(ReactDOM.jsx("div", {}))}) - let _ = ReactDOM.jsxs( "div", {children: React.array([ReactDOM.jsx("div", {}), ReactDOM.jsx("div", {})])}, diff --git a/tests/syntax_tests/data/ppx/react/expected/interface.res.txt b/tests/syntax_tests/data/ppx/react/expected/interface.res.txt index 6f9981a815f..77b6e77aec2 100644 --- a/tests/syntax_tests/data/ppx/react/expected/interface.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/interface.res.txt @@ -3,9 +3,7 @@ module A = { type props<'x> = { x: 'x, } - let make = ({x, _}: props<_>): React.element => React.string(x) - let make = React.component({ let \"Interface$A" = (props: props<_>) => make(props) \"Interface$A" @@ -17,7 +15,6 @@ module NoProps = { type props = {} let make = (_: props): React.element => ReactDOM.jsx("div", {}) - let make = React.component({ let \"Interface$NoProps" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/interface.resi.txt b/tests/syntax_tests/data/ppx/react/expected/interface.resi.txt index b819ab34647..d0cc914abf7 100644 --- a/tests/syntax_tests/data/ppx/react/expected/interface.resi.txt +++ b/tests/syntax_tests/data/ppx/react/expected/interface.resi.txt @@ -3,7 +3,6 @@ module A: { type props<'x> = { x: 'x, } - let make: React.component> } diff --git a/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.res.txt b/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.res.txt index f3580c98d26..266f97d3281 100644 --- a/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.res.txt @@ -3,7 +3,6 @@ type props<'x, 'ref> = { x: 'x, ref?: 'ref, } - let make = ( {x, _}: props, ref: nullable, @@ -11,7 +10,6 @@ let make = ( let _ = ref->Nullable.toOption->Belt.Option.map(ReactDOM.Ref.domRef) React.string(x) } - let make = React.forwardRef({ let \"InterfaceWithRef" = (props: props<_>, ref) => make(props, ref) \"InterfaceWithRef" diff --git a/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.resi.txt b/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.resi.txt index cf547d26c66..462fa9d6404 100644 --- a/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.resi.txt +++ b/tests/syntax_tests/data/ppx/react/expected/interfaceWithRef.resi.txt @@ -3,5 +3,4 @@ type props<'x, 'ref> = { x: 'x, ref?: 'ref, } - let make: React.component> diff --git a/tests/syntax_tests/data/ppx/react/expected/mangleKeyword.res.txt b/tests/syntax_tests/data/ppx/react/expected/mangleKeyword.res.txt index 78eb9d2bdc8..fd905c590ba 100644 --- a/tests/syntax_tests/data/ppx/react/expected/mangleKeyword.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/mangleKeyword.res.txt @@ -9,14 +9,12 @@ module C4A0 = { let make = ({@as("open") _open, @as("type") _type, _}: props<_, string>): React.element => React.string(_open) - let make = React.component({ let \"MangleKeyword$C4A0" = (props: props<_>) => make(props) \"MangleKeyword$C4A0" }) } - module C4A1 = { @res.jsxComponentProps @live type props<'T_open, 'T_type> = { diff --git a/tests/syntax_tests/data/ppx/react/expected/nested.res.txt b/tests/syntax_tests/data/ppx/react/expected/nested.res.txt index 35f584aad73..4931436a500 100644 --- a/tests/syntax_tests/data/ppx/react/expected/nested.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/nested.res.txt @@ -1,14 +1,12 @@ module Outer = { @res.jsxComponentProps type props = {} - let make = (_: props): React.element => { module Inner = { @res.jsxComponentProps type props = {} let make = (_: props): React.element => ReactDOM.jsx("div", {}) - let make = React.component({ let \"Nested$Outer" = props => make(props) @@ -18,7 +16,6 @@ module Outer = { React.jsx(Inner.make, {}) } - let make = React.component({ let \"Nested$Outer" = props => make(props) \"Nested$Outer" diff --git a/tests/syntax_tests/data/ppx/react/expected/newtype.res.txt b/tests/syntax_tests/data/ppx/react/expected/newtype.res.txt index 92408363a66..5873c71b31e 100644 --- a/tests/syntax_tests/data/ppx/react/expected/newtype.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/newtype.res.txt @@ -10,7 +10,6 @@ module V4A = { let make = (type a, {a, b, c, _}: props>, 'a>): React.element => ReactDOM.jsx("div", {}) - let make = React.component({ let \"Newtype$V4A" = (props: props<_>) => make(props) @@ -28,7 +27,6 @@ module V4A1 = { let make = (type x y, {a, b, c, _}: props, 'a>): React.element => ReactDOM.jsx("div", {}) - let make = React.component({ let \"Newtype$V4A1" = (props: props<_>) => make(props) @@ -50,7 +48,6 @@ module V4A2 = { module T = unpack(foo) ReactDOM.jsx("div", {}) } - let make = React.component({ let \"Newtype$V4A2" = (props: props<_>) => make(props) @@ -68,14 +65,12 @@ module V4A3 = { module T = unpack(foo: T with type t = a) foo } - let make = React.component({ let \"Newtype$V4A3" = (props: props<_>) => make(props) \"Newtype$V4A3" }) } - @res.jsxComponentProps type props<'x, 'q> = { x: 'x, @@ -83,7 +78,6 @@ type props<'x, 'q> = { } let make = ({x, q, _}: props<('a, 'b), 'a>): React.element => [fst(x), q] - let make = React.component({ let \"Newtype" = (props: props<_>) => make(props) @@ -99,7 +93,6 @@ module Uncurried = { } let make = (type a, {?foo, _}: props<_>): React.element => React.null - let make = React.component({ let \"Newtype$Uncurried" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/noPropsWithKey.res.txt b/tests/syntax_tests/data/ppx/react/expected/noPropsWithKey.res.txt index 1a481fa6780..443bb57c62e 100644 --- a/tests/syntax_tests/data/ppx/react/expected/noPropsWithKey.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/noPropsWithKey.res.txt @@ -5,7 +5,6 @@ module V4CA = { type props = {} let make = (_: props): React.element => ReactDOM.jsx("div", {}) - let make = React.component({ let \"NoPropsWithKey$V4CA" = props => make(props) @@ -35,7 +34,6 @@ module V4C = { ]), }, ) - let make = React.component({ let \"NoPropsWithKey$V4C" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/optimizeAutomaticMode.res.txt b/tests/syntax_tests/data/ppx/react/expected/optimizeAutomaticMode.res.txt index 6ce4b5e17e3..7ccf95dfb35 100644 --- a/tests/syntax_tests/data/ppx/react/expected/optimizeAutomaticMode.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/optimizeAutomaticMode.res.txt @@ -4,7 +4,6 @@ module User = { type t = {firstName: string, lastName: string} let format = user => "Dr." ++ user.lastName - @res.jsxComponentProps type props<'doctor> = { doctor: 'doctor, @@ -13,7 +12,6 @@ module User = { let make = ({doctor, _}: props<_>): React.element => { ReactDOM.jsx("h1", {id: "h1", children: ?ReactDOM.someElement({React.string(format(doctor))})}) } - let make = React.component({ let \"OptimizeAutomaticMode$User" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/optionalKeyType.res.txt b/tests/syntax_tests/data/ppx/react/expected/optionalKeyType.res.txt index 16ee150124a..0420bce343e 100644 --- a/tests/syntax_tests/data/ppx/react/expected/optionalKeyType.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/optionalKeyType.res.txt @@ -8,21 +8,18 @@ let _ = React.jsxKeyed(C.make, {}, ~key?, ()) let _ = ReactDOM.jsxKeyed("div", {}, ~key="k", ()) let _ = ReactDOM.jsxKeyed("div", {}, ~key=?Some("k"), ()) let _ = ReactDOM.jsxKeyed("div", {}, ~key?, ()) - let _ = ReactDOM.jsxsKeyed( "div", {children: React.array([ReactDOM.jsx("br", {}), ReactDOM.jsx("br", {})])}, ~key="k", (), ) - let _ = ReactDOM.jsxsKeyed( "div", {children: React.array([ReactDOM.jsx("br", {}), ReactDOM.jsx("br", {})])}, ~key=?Some("k"), (), ) - let _ = ReactDOM.jsxsKeyed( "div", {children: React.array([ReactDOM.jsx("br", {}), ReactDOM.jsx("br", {})])}, diff --git a/tests/syntax_tests/data/ppx/react/expected/returnConstraint.res.txt b/tests/syntax_tests/data/ppx/react/expected/returnConstraint.res.txt index ddd4b721102..43e3ca14aef 100644 --- a/tests/syntax_tests/data/ppx/react/expected/returnConstraint.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/returnConstraint.res.txt @@ -5,7 +5,6 @@ module Standard = { type props = {} let make = (_: props): React.element => React.string("ok") - let make = React.component({ let \"ReturnConstraint$Standard" = props => make(props) @@ -18,7 +17,6 @@ module ForwardRef = { type props = {} let make = (_: props, _ref): React.element => ReactDOM.jsx("div", {}) - let make = React.forwardRef({ let \"ReturnConstraint$ForwardRef" = (props, ref) => make(props, ref) @@ -31,7 +29,6 @@ module WithProps = { let make = (props: props): React.element => ReactDOM.jsx("span", {children: ?ReactDOM.someElement({React.int(props.value)})}) - let make = React.component({ let \"ReturnConstraint$WithProps" = (props: props): React.element => make(props) \"ReturnConstraint$WithProps" @@ -44,7 +41,6 @@ module Async = { let make = async (_: props): React.element => ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.string("async")})}) - let make = React.component({ let \"ReturnConstraint$Async" = props => Jsx.promise(make(props)) diff --git a/tests/syntax_tests/data/ppx/react/expected/sharedProps.res.txt b/tests/syntax_tests/data/ppx/react/expected/sharedProps.res.txt index 202be4471b1..34d29a757e4 100644 --- a/tests/syntax_tests/data/ppx/react/expected/sharedProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/sharedProps.res.txt @@ -4,7 +4,6 @@ module V4A1 = { type props = sharedProps let make = ({x, y, _}: props): React.element => React.string(x ++ y) - let make = React.component({ let \"SharedProps$V4A1" = props => make(props) @@ -16,7 +15,6 @@ module V4A2 = { type props<'a> = sharedProps<'a> let make = ({x, y, _}: props<_>): React.element => React.string(x ++ y) - let make = React.component({ let \"SharedProps$V4A2" = (props: props<_>) => make(props) @@ -28,7 +26,6 @@ module V4A3 = { type props<'a> = sharedProps let make = ({x, y, _}: props<_>): React.element => React.string(x ++ y) - let make = React.component({ let \"SharedProps$V4A3" = (props: props<_>) => make(props) @@ -40,7 +37,6 @@ module V4A4 = { type props = sharedProps let make = ({x, y, _}: props): React.element => React.string(x ++ y) - let make = React.component({ let \"SharedProps$V4A4" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/sharedPropsWithProps.res.txt b/tests/syntax_tests/data/ppx/react/expected/sharedPropsWithProps.res.txt index 094cc964ddf..91eea5058fc 100644 --- a/tests/syntax_tests/data/ppx/react/expected/sharedPropsWithProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/sharedPropsWithProps.res.txt @@ -18,7 +18,6 @@ let f = a => Promise.resolve(a + a) module V4A1 = { type props = sharedProps let make = (props): React.element => React.string(props.x ++ props.y) - let make = React.component({ let \"SharedPropsWithProps$V4A1" = (props): React.element => make(props) \"SharedPropsWithProps$V4A1" @@ -28,7 +27,6 @@ module V4A1 = { module V4A2 = { type props = sharedProps let make = (props: props): React.element => React.string(props.x ++ props.y) - let make = React.component({ let \"SharedPropsWithProps$V4A2" = (props: props): React.element => make(props) \"SharedPropsWithProps$V4A2" @@ -38,7 +36,6 @@ module V4A2 = { module V4A3 = { type props<'a> = sharedProps<'a> let make = ({x, y}: props<_>): React.element => React.string(x ++ y) - let make = React.component({ let \"SharedPropsWithProps$V4A3" = (props: props<_>): React.element => make(props) \"SharedPropsWithProps$V4A3" @@ -48,7 +45,6 @@ module V4A3 = { module V4A4 = { type props<'a> = sharedProps let make = ({x, y}: props<_>): React.element => React.string(x ++ y) - let make = React.component({ let \"SharedPropsWithProps$V4A4" = (props: props<_>): React.element => make(props) \"SharedPropsWithProps$V4A4" @@ -57,12 +53,10 @@ module V4A4 = { module V4A5 = { type props<'a> = {a: 'a} - let make = async ({a}: props<_>): React.element => { let a = await f(a) ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})}) } - let make = React.component({ let \"SharedPropsWithProps$V4A5" = (props: props<_>): React.element => Jsx.promise(make(props)) \"SharedPropsWithProps$V4A5" @@ -71,14 +65,12 @@ module V4A5 = { module V4A6 = { type props<'status> = {status: 'status} - let make = async ({status}: props<_>): React.element => { switch status { | #on => React.string("on") | #off => React.string("off") } } - let make = React.component({ let \"SharedPropsWithProps$V4A6" = (props: props<_>): React.element => Jsx.promise(make(props)) \"SharedPropsWithProps$V4A6" @@ -91,7 +83,6 @@ module V4A7 = { let make = (props): React.element => { React.int(props.count) } - let make = React.component({ let \"SharedPropsWithProps$V4A7" = @directive("'use memo'") (props): React.element => make(props) @@ -104,7 +95,6 @@ module V4A8 = { // The payload has no effect; it is accepted with a deprecation warning. let make = (props): React.element => React.string(props.x) - let make = React.component({ let \"SharedPropsWithProps$V4A8" = (props): React.element => make(props) \"SharedPropsWithProps$V4A8" diff --git a/tests/syntax_tests/data/ppx/react/expected/topLevel.res.txt b/tests/syntax_tests/data/ppx/react/expected/topLevel.res.txt index 886d36bce63..bc712ece06e 100644 --- a/tests/syntax_tests/data/ppx/react/expected/topLevel.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/topLevel.res.txt @@ -11,7 +11,6 @@ module V4A = { Console.log("This function should be named 'TopLevel.react'") ReactDOM.jsx("div", {}) } - let make = React.component({ let \"TopLevel$V4A" = (props: props<_>) => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/typeConstraint.res.txt b/tests/syntax_tests/data/ppx/react/expected/typeConstraint.res.txt index 8586b2d5d3a..491f5c7d191 100644 --- a/tests/syntax_tests/data/ppx/react/expected/typeConstraint.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/typeConstraint.res.txt @@ -8,7 +8,6 @@ module V4A = { } let make = (type a, {a, b, _}: props<_, _>): React.element => ReactDOM.jsx("div", {}) - let make = React.component({ let \"TypeConstraint$V4A" = (props: props<_>) => make(props) 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 a7a1dff341a..9e635bafdd6 100644 --- a/tests/syntax_tests/data/ppx/react/expected/uncurriedProps.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/uncurriedProps.res.txt @@ -1,5 +1,4 @@ @@jsxConfig({version: 4}) - @res.jsxComponentProps type props<'a> = { a?: 'a, @@ -13,7 +12,6 @@ let make = ({a: ?__a, _}: props unit>) => { let a: unit => unit = __a_value (React.null: React.element) } - let make = React.component({ let \"UncurriedProps" = (props: props<_>) => make(props) @@ -48,7 +46,6 @@ module Foo = { }: React.element ) } - let make = React.component({ let \"UncurriedProps$Foo" = (props: props<_>) => make(props) @@ -61,7 +58,6 @@ module Bar = { type props = {} let make = (_: props): React.element => React.jsx(Foo.make, {callback: {(_, _, _) => ()}}) - let make = React.component({ let \"UncurriedProps$Bar" = props => make(props) diff --git a/tests/syntax_tests/data/ppx/react/expected/v4.res.txt b/tests/syntax_tests/data/ppx/react/expected/v4.res.txt index dbf4c5c06a6..a23517ad7dd 100644 --- a/tests/syntax_tests/data/ppx/react/expected/v4.res.txt +++ b/tests/syntax_tests/data/ppx/react/expected/v4.res.txt @@ -3,9 +3,7 @@ type props<'x, 'y> = { x: 'x, // Component with type constraint y: 'y, } - let make = ({x, y, _}: props): React.element => React.string(x ++ y) - let make = React.component({ let \"V4" = (props: props<_>) => make(props) \"V4" @@ -18,7 +16,6 @@ module Braced = { } let make = ({name, _}: props<_>): React.element => React.string(name) - let make = React.component({ let \"V4$Braced" = (props: props<_>) => make(props) @@ -34,7 +31,6 @@ module AnotherName = { } let anotherName = ({x, _}: props<_>): React.element => React.string(x) - let anotherName = React.component({ let \"V4$AnotherName$anotherName" = (props: props<_>) => anotherName(props) @@ -49,7 +45,6 @@ module Uncurried = { } let make = ({x, _}: props<_>): React.element => React.string(x) - let make = React.component({ let \"V4$Uncurried" = (props: props<_>) => make(props) @@ -91,7 +86,6 @@ module Rec = { let rec make = (_: props): React.element => { make(({}: props)) } - let make = React.component({ let \"V4$Rec" = props => make(props) @@ -106,7 +100,6 @@ module Rec1 = { let rec make = (_: props): React.element => { React.null } - let make = React.component({ let \"V4$Rec1" = props => make(props) @@ -123,7 +116,6 @@ module Rec2 = { } and mm = x => make(x) - let make = React.component({ let \"V4$Rec2" = props => make(props) diff --git a/tests/syntax_tests/data/printer/comments/expected/callbackTrailing.res.txt b/tests/syntax_tests/data/printer/comments/expected/callbackTrailing.res.txt index 340e934d17a..852da869a7c 100644 --- a/tests/syntax_tests/data/printer/comments/expected/callbackTrailing.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/callbackTrailing.res.txt @@ -50,16 +50,13 @@ let labeled = call(~fn=x => x /* keep labeled */) let optional = call(~fn=?x => x /* keep optional */) let labeledFirst = call(~fn=x => x /* keep first */, value) let optionalLast = call(value, ~fn=?x => x /* keep last */) - let labeledBelow = call( ~fn=x => x, /* keep below */ ) - let optionalLine = call( ~fn=?x => x, // keep line ) - let labeledNested = call(~fn=x => call(~fn=y => y /* keep nested */)) let leadingLabeled = call(/* keep leading label */ ~fn=x => x) @@ -74,13 +71,11 @@ outer(x => x => x, // keep nested line ) ) - outer(x => call( ~fn=x => x, // keep nested labeled line ) ) - outer(x => call( ~fn=?x => x, // keep nested optional line diff --git a/tests/syntax_tests/data/printer/comments/expected/expr.res.txt b/tests/syntax_tests/data/printer/comments/expected/expr.res.txt index 6ebae0f227f..99434ca5865 100644 --- a/tests/syntax_tests/data/printer/comments/expected/expr.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/expr.res.txt @@ -71,7 +71,6 @@ let x = (/* c0 */ "string" /* c1 */: /* c2 */ string /* c3 */) // after let x = /* before */ true /* after */ let x = /* before */ Red /* after */ let x = /* before */ Red(/* c0 */ shade /* c1 */) /* after */ - let x = /* before */ Red /* after Red */( /* c0 */ r /* c1 */, /* c2 */ g /* c3 */, @@ -94,7 +93,6 @@ let x = /* c0 */ list{/* c1 */ a /* c2 */, /* c3 */ b /* c4 */, /* c5 */ c /* c6 // Pexp_array let x = [/* c0 */ a /* c1 */, /* c2 */ b /* c3 */, /* c4 */ c /* c5 */] let x = [/* a */] - let x = [ // test ] @@ -215,7 +213,6 @@ for await /* c0 */ x /* c1 */ of /* c2 */ xs /* c3 */ { // Pexp_fun let f = (/* c0 */ a /* c1 */, /* c2 */ b /* c3 */): /* c4 */ int /* c5 */ => /* c6 */ 20 /* c7 */ - let multiply = (/* c0 */ m1 /* c1 */, /* c2 */ m2 /* c3 */) => { // here open Matrix4D @@ -239,7 +236,6 @@ let f = ( ) => () let multiply = (type /* c-2 */ t /* c-1 */, /* c0 */ m1 /* c1 */, /* c2 */ m2 /* c3 */) => () - let multiply = ( type /* c-4 */ t /* c-3 */ /* c-2 */ s /* c-1 */, /* c0 */ m1 /* c1 */, @@ -277,7 +273,6 @@ f(() => 1) f(_ => 1) // c2 f(a => 1) - // c3 f((~a) => // c4 @@ -316,7 +311,6 @@ Doc.concat( rows, /* a */ ) - Doc.concat(list{ privateFlag, rows, diff --git a/tests/syntax_tests/data/printer/comments/expected/modExpr.res.txt b/tests/syntax_tests/data/printer/comments/expected/modExpr.res.txt index 10142c27705..d802464dec6 100644 --- a/tests/syntax_tests/data/printer/comments/expected/modExpr.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/modExpr.res.txt @@ -24,12 +24,10 @@ /* c6 */ Arg2 /* c7 */, /* c8 */ Arg3 /* c9 */, ) /* c10 */ - /* c0 */ module /* c1 */ X /* c2 */ = /* c3 */ F( /* c4 */ A /* c5 */: /* c6 */ SetLike /* c7 */, /* c7 */ B /* c8 */: /* c9 */ TreeLike /* c10 */, ) /* c11 */ - /* c0 */ module /* c1 */ S0 /* c2 */ = /* c3 */ Make /* c4 */(/* lbrace */ { type t = int /* c5 */ let eq /* c6 */ = (x, y) => x == y diff --git a/tests/syntax_tests/data/printer/comments/expected/modType.res.txt b/tests/syntax_tests/data/printer/comments/expected/modType.res.txt index c319a2e029c..7f0ff61abc4 100644 --- a/tests/syntax_tests/data/printer/comments/expected/modType.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/modType.res.txt @@ -19,12 +19,10 @@ // Pmty_functor /* c0 */ module type /* c1 */ Functor /* c2 */ = /* c3 */ SetLike /* c4 */ => /* c5 */ Set /* c6 */ - module type Functor = /* before */ ( /* before S */ S /* after S */: /* before */ SetLike /* after */, /* before B */ B /* after B */: /* before */ BtreeLike /* after */, ) => /* before NeoTree */ NeoTree // after NeoTree - module type Functor = ( /* c0 */ /* c1 */ /* c2 */ SetLike /* c3 */, /* c4 */ /* c5 */ /* c6 */ BtreeLike /* c7 */, diff --git a/tests/syntax_tests/data/printer/comments/expected/namedArgs.res.txt b/tests/syntax_tests/data/printer/comments/expected/namedArgs.res.txt index 5f77a8b4789..c74b892f8a5 100644 --- a/tests/syntax_tests/data/printer/comments/expected/namedArgs.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/namedArgs.res.txt @@ -80,7 +80,6 @@ let f = (~x /* a */ /* a2 */=? /* b */ /* b2 */, ~y) => x let f = (~x as y=? /* a */, ~z) => y let f = (~x=?, /* a */ ~y) => x let f = (~x=? /* a */, ~y) => x - let f = ( ~x: int /* a */=? /* b */, ~someLongParameterName, diff --git a/tests/syntax_tests/data/printer/comments/expected/pattern.res.txt b/tests/syntax_tests/data/printer/comments/expected/pattern.res.txt index 2934955ae27..3b4a79fb8e0 100644 --- a/tests/syntax_tests/data/printer/comments/expected/pattern.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/pattern.res.txt @@ -23,7 +23,6 @@ let /* here */ Black /* there */ = color let /* here */ Black(/* inside */) /* there */ = color let Black(/* inside */ /* inside2 */) = color let Black(/* inside */ /* inside2 */ /* inside 3 */) = color - let Black( // singleLineComment ) = color diff --git a/tests/syntax_tests/data/printer/comments/expected/structureItem.res.txt b/tests/syntax_tests/data/printer/comments/expected/structureItem.res.txt index 8ee240e95b4..5dfc7e189e3 100644 --- a/tests/syntax_tests/data/printer/comments/expected/structureItem.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/structureItem.res.txt @@ -6,7 +6,6 @@ // Pstr_include /* c0 */ include /* c1 */ Belt /* c2 */ - /* c0 */ include /* c1 */ { let a /* inside */ = 2 } /* c2 */ diff --git a/tests/syntax_tests/data/printer/comments/expected/typeDefinition.res.txt b/tests/syntax_tests/data/printer/comments/expected/typeDefinition.res.txt index 6e200d03ada..87ba674da8a 100644 --- a/tests/syntax_tests/data/printer/comments/expected/typeDefinition.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/typeDefinition.res.txt @@ -12,7 +12,6 @@ /* before */ type t = /* before manifest */ string /* after */ /* before */ type /* before name */ t /* after name */ = /* before manifest */ string /* after */ - /* before */ type /* before name */ t /* after name */< /* c0 */ 'err /* c1 */, /* c2 */ 'success /* c3 */, diff --git a/tests/syntax_tests/data/printer/comments/expected/typexpr.res.txt b/tests/syntax_tests/data/printer/comments/expected/typexpr.res.txt index b428d5baa71..c02f7ebe0b4 100644 --- a/tests/syntax_tests/data/printer/comments/expected/typexpr.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/typexpr.res.txt @@ -42,12 +42,10 @@ type add = /* before */ ( /* c0 */ int /* c1 */, /* c2 */ int /* c3 */, ) => /* before return */ int /* after */ - type add = /* before */ ( /* c0 */ ~a: int /* c1 */, /* c2 */ ~b: int /* c3 */, ) => /* before return */ int /* after */ - type multiply = /* before */ ( /* c0 */ ~fn: ( /* cinner0 */ int /* cinner1 */, @@ -55,7 +53,6 @@ type multiply = /* before */ ( ) => /* cx */ int /* c1 */, /* c2 */ ~b: int /* c3 */, ) => int /* after */ - type make = ( ~activity: ActivityFlow_Activity.t, ~showExpert: (string, string) => unit, @@ -98,7 +95,6 @@ external another_test: ( // comment 2 int, ) => unit = "test" - type optionalArg = (~x: int /* a */=?, unit) => int type lastOptionalArg = (~x: int /* a */=?) => int external optionalArgExternal: (~x: int /* a */=?, unit) => int = "f" @@ -107,7 +103,6 @@ type lastOptionalArgAfter = (~x: int=? /* a */) => int type optionalArgAround = (~x: int /* a */ /* a2 */=? /* b */, ~y: int) => int type optionalArgThenComma = (~x: int=?, /* a */ ~y: int) => int external optionalArgAfterExternal: (~x: int=? /* a */, unit) => int = "f" - type optionalArgAfterMultiline = ( ~x: int=? /* a */, ~someLongParameterName: int, diff --git a/tests/syntax_tests/data/printer/comments/expected/valueBindings.res.txt b/tests/syntax_tests/data/printer/comments/expected/valueBindings.res.txt index 659594eab40..e5cac613d77 100644 --- a/tests/syntax_tests/data/printer/comments/expected/valueBindings.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/valueBindings.res.txt @@ -3,7 +3,6 @@ let x = 1 // leading snd value-binding and y = 2 - /* leading snd value-binding */ let walkList: 'node. unit = comments => { diff --git a/tests/syntax_tests/data/printer/expected/regexp.res.txt b/tests/syntax_tests/data/printer/expected/regexp.res.txt index 44d55caca38..b1d7791474b 100644 --- a/tests/syntax_tests/data/printer/expected/regexp.res.txt +++ b/tests/syntax_tests/data/printer/expected/regexp.res.txt @@ -4,10 +4,8 @@ let characterClass = /[/\]]+/u let unicode = /世界+/g let dot = /./s let flags = /a/dgimsuy - @foo let attributed = /a/g - let comments = [/* before */ /a/g /* after */, /b/] let use = f(/a/i, /b/m) let expressionAttributes = @foo /a/g diff --git a/tests/syntax_tests/data/printer/expected/regexpStatements.res.txt b/tests/syntax_tests/data/printer/expected/regexpStatements.res.txt index 7ecd139add4..a5193971eca 100644 --- a/tests/syntax_tests/data/printer/expected/regexpStatements.res.txt +++ b/tests/syntax_tests/data/printer/expected/regexpStatements.res.txt @@ -191,10 +191,8 @@ let afterOpenExpression = () => { } let beforeStatementAttribute = 0 - @foo /a/->ignore - /**Keep the documentation attribute.*/ /b/->ignore diff --git a/tests/syntax_tests/data/printer/expr/expected/DocComments.res.txt b/tests/syntax_tests/data/printer/expr/expected/DocComments.res.txt index 2f24e1d0bc8..6f9b61a2bc1 100644 --- a/tests/syntax_tests/data/printer/expr/expected/DocComments.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/DocComments.res.txt @@ -2,10 +2,8 @@ let doc1: ( /** ddd */ ~x: int, ) => int = (~x) => x + 1 - let doc2: /** ddd */ int => int = x => x + 1 let doc3: /** ddd */ int => int = x => x + 1 - let doc4: ( /** ddd */ ~x: int, diff --git a/tests/syntax_tests/data/printer/expr/expected/apply.res.txt b/tests/syntax_tests/data/printer/expr/expected/apply.res.txt index 3b26610af88..d506eb95381 100644 --- a/tests/syntax_tests/data/printer/expr/expected/apply.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/apply.res.txt @@ -20,7 +20,6 @@ let cmp = rbt.compare2(Array.getUnsafe(old, oldIter.contents), longerNode.longVa let uncurriedUnit = apply() let coordinate = make2dCoordinate({x: 1, y: 2}) - let coordinate = make3dCoordinate({ ...base, field1: thisIsAPrettyLongNameHere, @@ -29,7 +28,6 @@ let coordinate = make3dCoordinate({ }) let coordinate = make2dCoordinateArray([x, y]) - let coordinate = make3dCoordinateArray([ thisIsAPrettyLongNameHere, thisIsAPrettyLongNameHere, @@ -37,7 +35,6 @@ let coordinate = make3dCoordinateArray([ ]) let coordinate = make2dCoordinateTuple((x, y)) - let coordinate = make3dCoordinateTuple(( thisIsAPrettyLongNameHere, thisIsAPrettyLongNameHere, @@ -45,7 +42,6 @@ let coordinate = make3dCoordinateTuple(( )) let coordinate = make2dCoordinateList(list{x, y}) - let coordinate = make3dCoordinateList(list{ thisIsAPrettyLongNameHere, thisIsAPrettyLongNameHere, @@ -54,7 +50,6 @@ let coordinate = make3dCoordinateList(list{ }) let coordinate = makeJsCoordinate({"x": 1, "y": 1}) - let user = makeJsUser({ "name": "steve", "age": 32, @@ -72,35 +67,27 @@ document.createElementWithOptions("div", elementProps(~onClick=_ => Console.log( f(1) f([1, 2, 3]) - f([ suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuperLong, suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuperLong, suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuperLong, ]) - f((1, 2, 3)) f({"a": 1}) f(list{1}) - f(` template string `) - f(`single line`) - f(" template string ") - f({ expr }) - f({expr}) - f({ exception Exit throw(Exit) diff --git a/tests/syntax_tests/data/printer/expr/expected/array.res.txt b/tests/syntax_tests/data/printer/expr/expected/array.res.txt index 01389f0d9f2..f317af7a860 100644 --- a/tests/syntax_tests/data/printer/expr/expected/array.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/array.res.txt @@ -1,6 +1,5 @@ let x = [] let x = [a, b, c] - let x = [ superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, diff --git a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt index 6e191225776..93d7d60d5ca 100644 --- a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt @@ -21,7 +21,6 @@ let x = assert(apply(arg1, arg2)) let x = assert(-1) let x = assert(!true) let x = assert(x => print(x)) - let x = assert(switch x { | Blue => () | Yello => () diff --git a/tests/syntax_tests/data/printer/expr/expected/assignment.res.txt b/tests/syntax_tests/data/printer/expr/expected/assignment.res.txt index 37d08c38184..887afd4b4c9 100644 --- a/tests/syntax_tests/data/printer/expr/expected/assignment.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/assignment.res.txt @@ -2,12 +2,10 @@ f := { first: one, second: two, } - f.contents = { first: one, second: two, } - obj["value"] = { first: one, second: two, @@ -19,14 +17,12 @@ f := [ thirdVeryLongArrayElement, fourthVeryLongArrayElement, ] - f.contents = [ firstVeryLongArrayElement, secondVeryLongArrayElement, thirdVeryLongArrayElement, fourthVeryLongArrayElement, ] - obj["value"] = [ firstVeryLongArrayElement, secondVeryLongArrayElement, @@ -38,12 +34,10 @@ f := () => { doA() doB() } - f.contents = () => { doA() doB() } - obj["value"] = () => { doA() doB() @@ -53,12 +47,10 @@ f := @attr () => { doA() doB() } - f.contents = @attr () => { doA() doB() } - obj["value"] = @attr () => { doA() doB() @@ -69,13 +61,11 @@ f := | Some(value) => value | None => fallback } - f.contents = switch value { | Some(value) => value | None => fallback } - obj["value"] = switch value { | Some(value) => value @@ -83,33 +73,27 @@ obj["value"] = } f := firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand - f.contents = firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand - obj["value"] = firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand f := {firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand} - f.contents = { firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand } - obj["value"] = { firstVeryLongOperand + secondVeryLongOperand + thirdVeryLongOperand + fourthVeryLongOperand } // Assignments used as operands retain their grouping. let nested = (f := {first: one, second: two})->ignore - let field = ( f.contents = { first: one, second: two, } )->ignore - let object = ( obj["value"] = { first: one, diff --git a/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt b/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt index 8b9df042023..c02694d1508 100644 --- a/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt @@ -48,19 +48,16 @@ let _ = await %extension let _ = await "test" let _ = await ((a, b) => a + b) let _ = await (async (a, b) => a + b) - let _ = await ( switch x { | A => () | B => () } ) - let _ = await [1, 2, 3] let _ = await (1, 2, 3) let _ = await {name: "Steve", age: 32} let _ = await (user.name = "Steve") - let _ = await ( if 20 { true @@ -68,30 +65,25 @@ let _ = await ( false } ) - let _ = await (condition() ? true : false) let _ = await f(x) let _ = await f(x) let _ = await (f(x): Promise.t) - let _ = await ( while true { infiniteLoop() } ) - let _ = await ( try ok() catch { | _ => logError() } ) - let _ = await ( for i in 0 to 10 { sideEffect() } ) - let _ = await (assert(x)) let _ = await promises[0] let _ = await promises["resolved"] @@ -104,7 +96,6 @@ let _ = await Promise(status) // braces are being dropped, because the ast only has space to record braces surrounding the await let _ = await x - // here braces stay, because of precedence let _ = await { let x = 1 diff --git a/tests/syntax_tests/data/printer/expr/expected/binary.res.txt b/tests/syntax_tests/data/printer/expr/expected/binary.res.txt index 669b2e887e2..2185cc1955f 100644 --- a/tests/syntax_tests/data/printer/expr/expected/binary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/binary.res.txt @@ -31,19 +31,16 @@ let x = foo ++ bar let x = 1 + 1 let x = (a => a + 1) + (b => b + 2) let x = -1 + -1 - let x = switch z { | Red => 1 }->switch y { | Blue => 2 } - let x = try z catch { | Exit => 1 }->try y catch { | Blue => 2 } - let x = if true { 1 @@ -54,7 +51,6 @@ let x = } else { 3 } - let x = for i in 0 to 10 { () }->for i in 0 to 10 { @@ -88,7 +84,6 @@ let rotateX = (range / rect.height * refY - range / 2) * getXMultiplication(rect let rotateY = (range / rect.width * refX - range / 2) * getYMultiplication(rect.width) let x = longIdentifier + longIdentifier + longIdentifier - let x = longIdentifier + longIdentifier + @@ -96,14 +91,12 @@ let x = longIdentifier - longIdentifier + longIdentifier - let x = longIdentifier + longIdentifier * longIdentifier + longIdentifier - longIdentifier + longIdentifier - let x = longIdentifier + longIdentifier * longIdentifier * longIdentifier / longIdentifier + @@ -116,7 +109,6 @@ let x = longIdentifier && longIdentifier && longIdentifier - let x = (longIdentifier && longIdentifier) || longIdentifier && longIdentifier || @@ -148,7 +140,6 @@ while continuePrefix.contents && aPrefixLen.contents <= aLen && bPrefixLen.conte let nextNonwhiteA = nextNonWhiteChar(aStr, 1, aPrefixLen.contents - 1) let nextNonwhiteB = nextNonWhiteChar(bStr, 1, bPrefixLen.contents - 1) } - let () = { let () = sideEffect() if ( @@ -214,14 +205,12 @@ let x = a && a.b let x = a && x.y && g.h let x = a && true let x = a && true && true - let x = a && { let a = true let b = true a || b } - let x = a && { @@ -255,7 +244,6 @@ let x = | Blue => "blue" | Red => "red" } - let x = a && switch color { @@ -304,7 +292,6 @@ let x = } else { false } - let x = a && if true { @@ -322,7 +309,6 @@ let x = sideEffect() do() } - let x = a && { @@ -337,7 +323,6 @@ let x = a && while true { do() } - let x = a && while true { @@ -350,7 +335,6 @@ let x = a && for i in 0 to 10 { true } - let x = a && for i in 0 to 10 { @@ -367,7 +351,6 @@ let x = module L = Log L.log() } - let x = a && { @@ -383,7 +366,6 @@ let x = exception Exit throw(Exit) } - let x = a && { @@ -402,7 +384,6 @@ let x = open React killPerform() } - let x = a && { @@ -481,7 +462,6 @@ x->(y->z) x->(y->(z->w)) let x = "z" ++ a->f ++ "x" - let toString = functionArgs => { functionArgs == [] ? "" : "<" ++ functionArgs->List.map(argToString)->String.concat(",") ++ ">" } @@ -541,6 +521,5 @@ let make = (~keycap) => + + Belt.Array.getExn(0) - @doesNotRaise []->Belt.Array.getExn(0) diff --git a/tests/syntax_tests/data/printer/expr/expected/block.res.txt b/tests/syntax_tests/data/printer/expr/expected/block.res.txt index 3dff5c4b22e..f9331a10a51 100644 --- a/tests/syntax_tests/data/printer/expr/expected/block.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/block.res.txt @@ -18,7 +18,6 @@ let reifyStyle = (type a, x: 'a): (style
, a) => { type rec constructor @val external canvasGradient: constructor = "CanvasGradient" /* internal */ @val external canvasPattern: constructor = "CanvasPattern" /* internal */ - let instanceOf = ( %raw(`function(x,y) {return +(x instanceof y)}`): ('a, constructor) => bool ) /* internal */ diff --git a/tests/syntax_tests/data/printer/expr/expected/braced.res.txt b/tests/syntax_tests/data/printer/expr/expected/braced.res.txt index 4d402d37596..aa0af975709 100644 --- a/tests/syntax_tests/data/printer/expr/expected/braced.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/braced.res.txt @@ -29,19 +29,16 @@ let _ = {a} let _ = {"constant"} let _ = {() => Console.log("test")} - let _ = { switch b { | true => () | false => () } } - let _ = switch {b} { | true => () | false => () } - let _ = {apply(a, b)} let _ = {apply}(a, b) @@ -50,7 +47,6 @@ let _ = { | Exit => () } } - let _ = try {danger()} catch { | Exit => () } @@ -60,7 +56,6 @@ let _ = {({a}, {b}, {x + y})} let _ = {Rgb(r, g, b)} let _ = Rgb({r}, {g}, {b}) - let _ = Rgb( { r @@ -75,7 +70,6 @@ let _ = Rgb( let _ = {{name: "steve", age: 30}} let _ = {name: {"steve"}, age: {30}} - let _ = { name: { "steve" @@ -92,7 +86,6 @@ let _ = {{user.name}.first} let _ = {[a, b, c]} let _ = [{a}, {b}, {c}] - let _ = [ { a @@ -107,7 +100,6 @@ let _ = [ let _ = {list{a, b, c}} let _ = {list{{a}, {b}, {c}}} - let _ = { list{ { @@ -134,7 +126,6 @@ let _ = { () } } - let _ = { if {true} { () @@ -170,15 +161,12 @@ let _ = { () } } - let _ = while {true} { () } - while {/* c0 */ true /* c1 */} { () } - while ( { true @@ -186,7 +174,6 @@ while ( ) { () } - while ( { /* c0 */ true // c1 @@ -200,7 +187,6 @@ let _ = { () } } - for _ in { 0 } to { @@ -218,7 +204,6 @@ let localToGlobalX = ( ): coordinate => { x +. (Environment.width /. 2. -. centering.x) } - map((arr, i): coordinate => { x +. (Environment.width /. 2. -. centering.x) }) @@ -231,15 +216,12 @@ let _ = {module(ME)} let _ = {module(ME: MyMod)} {myArray}[{0}] - { myArray }[{ 0 }] - {myArray}[{0}] = {20} - { myArray }[{ @@ -254,7 +236,6 @@ myArray[20] = { {jsObject}["foo"] {jsObject}["foo"] = {"bar"} - {jsObject}["foo"] = { a + b } @@ -262,11 +243,9 @@ myArray[20] = { { jsObject }["foo"] - {jsObject}["foo"] = {"bar"} apply({a}, {b}, {c}) - apply( { a @@ -280,7 +259,6 @@ apply( ) Thing.map(foo, (arg1, arg2) => {MyModuleBlah.toList(argument)}) - Thing.map({foo}, (arg1, arg2) => { MyModuleBlah.toList(argument) }) @@ -299,11 +277,9 @@ arr->Belt.Array.map(x => { }) apply(~a={a}) - apply({ a }) - apply({ a }) @@ -335,7 +311,6 @@ let x = { } {a} + {b} - { a } + diff --git a/tests/syntax_tests/data/printer/expr/expected/bsObj.res.txt b/tests/syntax_tests/data/printer/expr/expected/bsObj.res.txt index 572217ddf3b..083bb52267f 100644 --- a/tests/syntax_tests/data/printer/expr/expected/bsObj.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/bsObj.res.txt @@ -17,13 +17,11 @@ let person = { let user = {"name": (ceo.name: string)} // braces should be preserved on rhs let user = {"name": {ceo.name}} - let user = { "name": { ceo.name }, } - // braced + constrained expr let user = {"name": {(ceo.name: string)}} diff --git a/tests/syntax_tests/data/printer/expr/expected/callback.res.txt b/tests/syntax_tests/data/printer/expr/expected/callback.res.txt index 2448937028e..f0e0b96b3e0 100644 --- a/tests/syntax_tests/data/printer/expr/expected/callback.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/callback.res.txt @@ -1,6 +1,5 @@ array->Array.forEach(((value, height)) => add(rbt, value, ~height)->ignore) someArray->Array.forEach(((value, height)) => add(rbt, value, ~height)->ignore) - someArraaaaaaayWithAVeryLooooooooooooooooooooooooooooooooooooooongName->Array.forEach((( value, height, @@ -15,11 +14,9 @@ let make = (arr, ~compare) => { Thing.map(foo, (arg1, arg2) => MyModuleBlah.toList(argument)) Thing.map(foo, bar, baz, (aaaaaaaaaaarg1, aaaaarg2) => MyModuleBlah.toList(argument)) Thing.map(fooooooooooooooooooo, bar, baz, (abc, z) => MyModuleBlah.toList(argument)) - Thing.map(fooooooooooooooooooo, baaaaaaaaaaaaaaaaaar, baaaaaaaaaaaaaaaaaaaaaaaaaz, (abc, z) => MyModuleBlah.toList(argument) ) - Fooooooooooooooooooo.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(baaaz, quuuuux => something(here) ) @@ -122,7 +119,6 @@ Thing.map( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg3, ~fn=(param1, parm2) => doStuff(param1, parm2), ) - Thing.map( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg2, @@ -139,7 +135,6 @@ Thing.map(~fn=?(arg1, arg2) => MyModuleBlah.toList(argument), foo) Thing.map(~fn=(arg1, arg2) => { MyModuleBlah.toList(argument) }, longArgument, veryLooooongArgument) - Thing.map(~fn=?(arg1, arg2) => { MyModuleBlah.toList(argument) }, longArgument, veryLooooongArgument) @@ -151,7 +146,6 @@ Thing.map( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg3, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg4, ) - Thing.map( ~fn=?(param1, parm2) => doStuff(param1, parm2), aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarg2, diff --git a/tests/syntax_tests/data/printer/expr/expected/coerce.res.txt b/tests/syntax_tests/data/printer/expr/expected/coerce.res.txt index 8e428ce567c..3c74ea4de5b 100644 --- a/tests/syntax_tests/data/printer/expr/expected/coerce.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/coerce.res.txt @@ -67,29 +67,24 @@ let arrayIndex = values[index :> int] values[index :> int] = (value :> b) let recordSpread = {...value :> b, field: value} let bracedOperand = ({value} :> b) - let blockSequence = { { foo() value } :> b } - let checked = assert(value :> bool) (value :> b) let ternaryCallback = condition ? (x => (x :> b)) : other let piped = (value :> b)->foo - let blockTail = { foo() (value :> b) } - let blockHead = { (value :> b) foo() } - let dictSpread = dict{...value :> dict, "field": value} // A constrained operand needs parentheses when the coercion is a binding RHS. @@ -106,11 +101,9 @@ let beforeJsx = () => { // These grammar positions don't parse a bare trailing coercion. let locallyAbstract: type a. a = (value :> a) - let guarded = switch value { | _ if (flag :> bool) => value } - let jsxSpread = propsType)} /> @attr(? value if (flag :> bool)) @@ -119,7 +112,6 @@ let attributeGuard = value // Attribute and extension payloads parse their contents as plain expressions. @attr((value :> b)) let attributePayload = value - let extensionPayload = %extension((value :> b)) // First-class module unpacking also parses a plain expression. diff --git a/tests/syntax_tests/data/printer/expr/expected/constructor.res.txt b/tests/syntax_tests/data/printer/expr/expected/constructor.res.txt index 828d80590a4..929669fab0f 100644 --- a/tests/syntax_tests/data/printer/expr/expected/constructor.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/constructor.res.txt @@ -3,15 +3,12 @@ let y = false let r = Reducer() let r = Reducer(state, nexState, sideEffect) - let r = Reducer( superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, ) - let r = Reducer([state, nexState, sideEffect]) - let r = Reducer([ superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, @@ -48,7 +45,6 @@ let c = ConstructorWithASuuuuuuuuuuuuuuuperLoooooooooooooooooooooooooooooongIiii let c = ConstructorWithASuuuuuuuuuuuuuuuperLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer(list{}) let coordinate = JsCoord({"x": 1, "y": 1}) - let user = JsUser({ "name": "steve", "age": 32, diff --git a/tests/syntax_tests/data/printer/expr/expected/extension.res.txt b/tests/syntax_tests/data/printer/expr/expected/extension.res.txt index 58c32ff73a4..c3536b19b4b 100644 --- a/tests/syntax_tests/data/printer/expr/expected/extension.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/extension.res.txt @@ -4,12 +4,10 @@ let node = %raw(@attr ("0")) let node = %raw(@attrStructureLvl (@attrOnExpr "0")) let node = %raw(@attrStructureLvl @attrStructureLvl2 @attrStructureLvl3 (@attrOnExpr "0")) - let node = %raw( @attrStructureLvl @attrStructureLvl2 @attrStructureLvl3 (@attrOnExpr @attrOnExpr2 @attrOnExpr3 @attrOnExpr4 @attrOnExpr5 "unsafe raw js") ) - let f: (int, int) => int = %raw((a, b) => "{return a + b}") let f = (x, y) => { diff --git a/tests/syntax_tests/data/printer/expr/expected/field.res.txt b/tests/syntax_tests/data/printer/expr/expected/field.res.txt index 4d9b9271ecc..f3e2fed8960 100644 --- a/tests/syntax_tests/data/printer/expr/expected/field.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/field.res.txt @@ -21,7 +21,6 @@ let x = apply(arg1, arg2).field let x = (-1).x let x = (!true).x let x = (x => print(x)).x - let x = ( switch x { | Blue => () @@ -50,7 +49,6 @@ let x = ( ).x let x = (assert(false)).x - let x = ( try sideEffect() catch { | Exit => () diff --git a/tests/syntax_tests/data/printer/expr/expected/firstClassModule.res.txt b/tests/syntax_tests/data/printer/expr/expected/firstClassModule.res.txt index 12df0f06aa8..d3fcbd534ed 100644 --- a/tests/syntax_tests/data/printer/expr/expected/firstClassModule.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/firstClassModule.res.txt @@ -10,27 +10,22 @@ let x = @attr module(Foo: FirstClass) module(Teenager)[0] module(Teenager)->age->Console.log module(Teenager)[0]->Console.log - module(Teenager)->age->isAdult ? Console.log("has responsibilities") : Console.log("can play in the playground") - module(Streets)[0]->isExpensive ? Console.log("big money") : Console.log("affordable") let () = { module(Teenager)->age->Console.log } - let () = { module(Teenager)[0] } - let () = { module(Teenager)->age->isAdult ? Console.log("has responsibilities") : Console.log("can play in the playground") } - let () = { module(Streets)[0]->isExpensive ? Console.log("big money") : Console.log("affordable") } diff --git a/tests/syntax_tests/data/printer/expr/expected/fun.res.txt b/tests/syntax_tests/data/printer/expr/expected/fun.res.txt index ef186493143..d5f7e02218d 100644 --- a/tests/syntax_tests/data/printer/expr/expected/fun.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/fun.res.txt @@ -190,7 +190,6 @@ let make = (~onChange: option<({"testing": bool}, array) => unit>=?, chi let add = (a, b): int => a + b let add = (a, b): {"field1": int, "field2": string, "field3": int, "field4": int} => a + b - let add = (superLongParameterName1, superLongParameterName2, superLongParameterName3): { "field1": int, "field2": string, @@ -207,14 +206,12 @@ let add = (superLongParameterName1, superLongParameterName2, superLongParameterN } => a + b let add = ((a, b)): (int, string, int, int) => a + b - let add = ((a, b)): ( intWithSuperLongName, stringWithSuperLongName, intWithSuperLongName, intWithSuperLongName, ) => a + b - let add = (( superLongParameterName, bsuperLongParameterName, @@ -229,7 +226,6 @@ let add = (list{a, b}): list< intWithSuperLongName, intWithSuperLongName, > => a + b - let add = (list{ superLongParameterName, bsuperLongParameterName, @@ -248,7 +244,6 @@ let add = ([a, b]): array< intWithSuperLongName, intWithSuperLongName, > => a + b - let add = ([ superLongParameterName, bsuperLongParameterName, @@ -263,10 +258,8 @@ let add = ([ let add = ({x: superLongParameterName, y: superLongParameterName, z: superLongParameterName}) => x + y + z - let add = ({x: superLongParameterName, y: superLongParameterName, z: superLongParameterName}) => x + y + z - let add = ({ x: x as superLongParameterName, y: y as superLongParameterName, @@ -275,7 +268,6 @@ let add = ({ let add = (Color(superLongParameterName, superLongParameterName, superLongParameterNameeeeeee)) => x + y + z - let add = (Color( superLongParameterName, superLongParameterName, diff --git a/tests/syntax_tests/data/printer/expr/expected/functionLayouts.res.txt b/tests/syntax_tests/data/printer/expr/expected/functionLayouts.res.txt index e38bd37b75a..96e60317212 100644 --- a/tests/syntax_tests/data/printer/expr/expected/functionLayouts.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/functionLayouts.res.txt @@ -7,17 +7,14 @@ let fragment = value => <> - consume(value => <> ) - consume(value => <> , argument) - consume(argument, value => <> @@ -28,12 +25,10 @@ let block = // Keep the body comment. await compute(first, second) } - consume(argument, @attr async (~first, ~second=defaultValue): result => { // Keep the callback comment. await compute(first, second) }) - consume(firstVeryLongArgument, secondVeryLongArgument, (firstParameter, secondParameter) => compute(firstParameter, secondParameter) ) diff --git a/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt b/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt index 104c753885d..53c4801ddef 100644 --- a/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/jsx.res.txt @@ -21,33 +21,27 @@ let x = - let x = {children} - let x = {children} - let x = {a} - let x = {a} {b} - let x = {a} - let x = {a} @@ -308,11 +302,9 @@ let x = {test}} nav={} /> // https://github.com/rescript-lang/syntax/issues/113
{Console.log(a <= 10)}
-
{Console.log(a <= 10)}
-
Console.log(a <= 10)}>
{Console.log(a <= 10)}
diff --git a/tests/syntax_tests/data/printer/expr/expected/jsxChildren.res.txt b/tests/syntax_tests/data/printer/expr/expected/jsxChildren.res.txt index d0cc4f90d5c..dd90f2bd1c3 100644 --- a/tests/syntax_tests/data/printer/expr/expected/jsxChildren.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/jsxChildren.res.txt @@ -31,7 +31,6 @@ let x = {hello} {user.name} - let x = <> @@ -39,16 +38,13 @@ let x = - let x = <>{hello} let x = <>{hello} - let x = <> {hello} {world} - let x = <> let x = @@ -56,7 +52,6 @@ let x = let x = {render(hello)} let x = {hello->render} let x = {condition ? hello : world} - let x = {switch value { @@ -64,7 +59,6 @@ let x = | None => fallback }} - let x = { @@ -72,7 +66,6 @@ let x = child } - let x = { @@ -80,7 +73,6 @@ let x = hello } - let x = { @@ -88,7 +80,6 @@ let x = child } - let x = { @@ -96,7 +87,6 @@ let x = Hello.child } - let x = { @@ -104,9 +94,7 @@ let x = hello } - let x = {@label hello} - let x = { @@ -117,16 +105,13 @@ let x = } } - let x = {} - let x = {/* before braced JSX */} {} {/* after braced JSX */} - let x = <> {/* before braced fragment */} @@ -138,13 +123,11 @@ let x = let x = {/* before bare */ hello /* after bare */} let x = {/* inside */ hello /* still inside */} let x = <>{/* inside fragment */ hello /* still in fragment */} - let x = {hello /* between children */} {world} - let x = {{/* record field */ name: hello}} // Child comments and their line breaks stay inside expression braces. let x = {hello /* bare child */} @@ -152,15 +135,12 @@ let x = <>{hello /* bare fragment child */} let x = {user.name /* field child */} let x = {"hello" /* string child */} let x = {{name: hello} /* record child */} - let x = {hello} {/* already braced child */} - let x = {hello /* block comment */ /* line comment */} - let x = { @@ -168,9 +148,7 @@ let x = hello // Contains */ and must remain a line comment. } - let x = <>{/* before record */ {name: hello} /* after record */} - let x = {/* before a block */} @@ -180,14 +158,12 @@ let x = } {/* after a block */} - let x = {/* before a call */} {render(hello)} {/* after a call */} - let x = { @@ -196,9 +172,7 @@ let x = } {/* after bare child */} - let x = {hello /* trailing inside braces */} - let x = <> { @@ -206,7 +180,6 @@ let x = hello } - let x = { @@ -214,24 +187,20 @@ let x = {name: hello} /* after record */ } - let x = {aLongChildIdentifierThatWillNeedToWrapAtNarrowWidths} let emptyWithBlockComment = {/* empty */} - let emptyWithLineComment = { // contains */ } - let emptyFragmentWithInlineBlockComment = <>{/* inside */} let emptyFragmentWithInlineLineComment = <>{/* inside */} - let emptyFragmentWithMixedComments = <> { @@ -240,9 +209,7 @@ let emptyFragmentWithMixedComments = /* third */ } - let emptyFragmentWithOutsideComment = <>{/* inside */} // outside - let emptyFragmentWithComments = <> { @@ -250,7 +217,6 @@ let emptyFragmentWithComments = /* second */ } - let nestedStandaloneComments =
{/* before */} @@ -265,14 +231,12 @@ let nestedStandaloneComments = {/* last */}
- let nestedInlineComments =
{/* before */} {/* after */}
- let explicitCommentContainers = <> {/* before */} @@ -283,20 +247,17 @@ let explicitCommentContainers = {/* after */} - let adjacentCommentContainers = {/* one */} {/* two */} - let commentBeforeExpression = {/* before */} {hello} {/* after */} - let emptyRecordChild = {{}} let wrappedEmptyRecordChild = {{/* record */}} diff --git a/tests/syntax_tests/data/printer/expr/expected/jsxChildrenComments.res.txt b/tests/syntax_tests/data/printer/expr/expected/jsxChildrenComments.res.txt index 903ea3e1dfb..048e837ca7c 100644 --- a/tests/syntax_tests/data/printer/expr/expected/jsxChildrenComments.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/jsxChildrenComments.res.txt @@ -3,7 +3,6 @@ let a = {x} {/* a */}
- let b =
{x} @@ -11,7 +10,6 @@ let b = {/* c */} {y}
- let c =
@@ -19,7 +17,6 @@ let c =
- let d =
{/* a */} @@ -27,40 +24,34 @@ let d = {/* b */}
- let e =
{/* a */} {/* b */}
- let f =
{x} {/* c */} {y}
- let g =
{/* c */} {x}
- let h =
{/* a */ /* b */}
- let i =
{x} {/* a */}
- let j =
{ @@ -68,7 +59,6 @@ let j = x }
- let k =
{ @@ -76,13 +66,11 @@ let k = /* trailing */ }
- let l =
{x} {/* trailing */}
- let m =
{ @@ -90,13 +78,11 @@ let m = x }
- let n =
{/* a */ /* b */}
- let o =
{ @@ -112,7 +98,6 @@ let a = {x} {/* a */} - let b = <> {x} @@ -120,7 +105,6 @@ let b = {/* c */} {y} - let c = <> @@ -128,7 +112,6 @@ let c = - let d = <> {/* a */} @@ -136,40 +119,34 @@ let d = {/* b */} - let e = <> {/* a */} {/* b */} - let f = <> {x} {/* c */} {y} - let g = <> {/* c */} {x} - let h = <> {/* a */ /* b */} - let i = <> {x} {/* a */} - let j = <> { @@ -177,7 +154,6 @@ let j = x } - let k = <> { @@ -185,13 +161,11 @@ let k = /* trailing */ } - let l = <> {x} {/* trailing */} - let m = <> { @@ -199,13 +173,11 @@ let m = x } - let n = <> {/* a */ /* b */} - let o = <> { @@ -225,7 +197,6 @@ let spanningContainer = } {y}
- let spanningFragmentContainer = <> {x} @@ -244,7 +215,6 @@ let multilineExpressionComment = } {y}
- let leadingExpressionComment = - let mixedTrailingContainers =
{x} {/* b */} {/* a */}
- let mixedLeadingFragmentContainers = <> {/* a */} {/* b */} {y} - let mixedTrailingFragmentContainers = <> {x} {/* b */} {/* a */} - let mixedBetweenContainers =
{x /* a */} {/* b */} {/* c */ y}
- let mixedBetweenFragmentContainers = <> {x /* a */} @@ -298,35 +263,30 @@ let mixedBetweenFragmentContainers = let safeLineComment = {value /* note */} let safeInnerLineComment = {value /* note */} - let unsafeOpeningDelimiter = { // starts /* } - let unsafeClosingDelimiter = { // closes */ } - let unsafeNestedBlock = <> { // /* nested */ } - let unsafeReversedDelimiters = <> { // */ before /* } - let emptyLineComment = {/* */} let starLineComment = {/* * */} let slashLineComment = <>{/* / */} diff --git a/tests/syntax_tests/data/printer/expr/expected/newtype.res.txt b/tests/syntax_tests/data/printer/expr/expected/newtype.res.txt index f5a59bd175e..e8480471a65 100644 --- a/tests/syntax_tests/data/printer/expr/expected/newtype.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/newtype.res.txt @@ -6,7 +6,6 @@ let f = (type t u v, xs: list<(t, u, v)>) => () let f = @attr (type t u v, xs: list<(t, u, v)>) => () let f = (type t u v s w z, xs: list<(t, u, v)>, ys: list<(s, w, z)>) => () let f = @attr (type t u v, @attr2 type s w z, xs: list<(t, u, v)>, ys: list<(s, w, z)>) => () - let f = ( @attr type t, @attr type s, diff --git a/tests/syntax_tests/data/printer/expr/expected/polyvariant.res.txt b/tests/syntax_tests/data/printer/expr/expected/polyvariant.res.txt index b97d9d60410..f7c4fa0e296 100644 --- a/tests/syntax_tests/data/printer/expr/expected/polyvariant.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/polyvariant.res.txt @@ -1,14 +1,11 @@ let r = #Reducer() let r = #Reducer(state, nexState, sideEffect) - let r = #Reducer( superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, ) - let r = #Reducer([state, nexState, sideEffect]) - let r = #Reducer([ superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, @@ -45,7 +42,6 @@ let c = #ConstructorWithASuuuuuuuuuuuuuuuperLoooooooooooooooooooooooooooooongIii let c = #ConstructorWithASuuuuuuuuuuuuuuuperLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer(list{}) let coordinate = #JsCoord({"x": 1, "y": 1}) - let user = #JsUser({ "name": "steve", "age": 32, diff --git a/tests/syntax_tests/data/printer/expr/expected/record.res.txt b/tests/syntax_tests/data/printer/expr/expected/record.res.txt index 83d1b5a83ee..d33ef76db57 100644 --- a/tests/syntax_tests/data/printer/expr/expected/record.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/record.res.txt @@ -1,5 +1,4 @@ let coord = {x: 3.13, y: 3.14} - let record = { firstField: superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, secondField: superLongIdentiiiiiiiifffffffiiiiieeeeeeeer, @@ -12,7 +11,6 @@ let forceBreak = { } let withSpread = {...initialState, time: nextTime} - let withSpreadAndForceBreak = { ...initialState, time: nextTime, @@ -27,7 +25,6 @@ let withSpreadAndNaturalBreak = { let x = @attr {x: 1, y: 2} let x = @attr {...initialState, superLongName: 1, superLongName: 2, superLongName: 5} - let x = @attr {...initialState, superLongName: 1, superLongName: 2, superLongName: 5, superLongName: 20} @@ -35,13 +32,11 @@ let x = let user = {name: (ceo.name: string)} // braces should be preserved on rhs let user = {name: {ceo.name}} - let user = { name: { ceo.name }, } - // braced + constrained expr let user = {name: {(ceo.name: string)}} @@ -63,24 +58,20 @@ let r = { // b b, } - let r = { a, // a b, // b } - let r = { /* a */ a, /* b */ b, } - let r = { a /* a */, b /* b */, } - let r = {a /* a */, b /* b */} let r = {x: ?None, y: ?None, z: ?(None: tt)} @@ -131,16 +122,13 @@ let optParen = {x: 3, y: ?(() => 3)} let optParen = {x: 3, y: ?-3} let x = {a: 2} - let x = { a: 2, bbbbbbbbbbbbbbbbbbbbb: 22222222222, ccccccccccccccccccccc: 22222222222222222, ddddddddddddddddddddd: 2222222222222, } - let x = {a: 2} - let x = { a: 2, } diff --git a/tests/syntax_tests/data/printer/expr/expected/refFunction.res.txt b/tests/syntax_tests/data/printer/expr/expected/refFunction.res.txt index f3cbff74c92..9f94c7ef7d4 100644 --- a/tests/syntax_tests/data/printer/expr/expected/refFunction.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/refFunction.res.txt @@ -4,7 +4,6 @@ f.contents = () => { doA() doB() } - f := () => { doA() doB() @@ -14,7 +13,6 @@ f.contents = @attr () => { doA() doB() } - f := @attr () => { doA() doB() @@ -22,14 +20,11 @@ f := @attr () => { f := () => doA() f := @first @second () => doA() - f := async () => { await doA() doB() } - f := (value: int): int => value + 1 - f := (firstArgument, secondArgument, thirdArgument, fourthArgument, fifthArgument) => { doA(firstArgument, secondArgument) doB(thirdArgument, fourthArgument, fifthArgument) @@ -41,12 +36,10 @@ f := /* function */ () => { doA() doB() } - f.contents = /* attribute */ @attr () => { doA() doB() } - f := @attr () => { doA() doB() @@ -59,7 +52,6 @@ f := { doB() } } - f := (() => doA(): unit => unit) // Other operators still need parentheses around functions. @@ -71,6 +63,5 @@ let equal = doB() } ) - let left = (() => doA()) == f.contents let nested = (f := () => doA())->ignore diff --git a/tests/syntax_tests/data/printer/expr/expected/setfield.res.txt b/tests/syntax_tests/data/printer/expr/expected/setfield.res.txt index d1cb0f161b0..06f4bf90873 100644 --- a/tests/syntax_tests/data/printer/expr/expected/setfield.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/setfield.res.txt @@ -1,5 +1,4 @@ user.name = "steve" - config.shouldSkip = !filePath.includes(allMlSuffixesCategory) && !filePath.endsWith(allScriptDirectoriesCategory) diff --git a/tests/syntax_tests/data/printer/expr/expected/ternary.res.txt b/tests/syntax_tests/data/printer/expr/expected/ternary.res.txt index 85885fff1fc..cf3ea657fb0 100644 --- a/tests/syntax_tests/data/printer/expr/expected/ternary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/ternary.res.txt @@ -26,7 +26,6 @@ let paymentMessage = : "There was an issue with the payment. Please contact support." let record = truth ? {x: 1, y: 2} : {x: 3, y: 5} - let record = truth ? { thisIsASuperLongFieldHere: loooooooooooooongIdentifier, @@ -38,7 +37,6 @@ let record = truth } let arr = truth ? [1, 2, 3, 4] : [4, 5, 6, 7] - let arr = truth ? [ thisIsASuperLongIdentifieeeeeeeer, @@ -52,7 +50,6 @@ let arr = truth ] let lst = truth ? list{1, 2, 3, 4} : list{4, 5, 6, 7} - let lst = truth ? list{ thisIsASuperLongIdentifieeeeeeeer, @@ -66,7 +63,6 @@ let lst = truth } let construct = truth ? Constructor(1, 2, 3, 4) : Constructor(4, 5, 6, 7) - let construct = truth ? Constructor( thisIsASuperLongIdentifieeeeeeeer, @@ -90,7 +86,6 @@ let x = truth let b = 2 a + b } - let x = truth ? { let a = 1 @@ -104,7 +99,6 @@ let x = truth } let x = truth ? create(a, b) : create(b, c) - let x = truth ? create( thisIsASuperLongIdentifieeeeeeeer, @@ -116,9 +110,7 @@ let x = truth thisIsASuperLongIdentifieeeeeeeer2, thisIsASuperLongIdentifieeeeeeeer3, ) - let x = truth ? create(a, b) : create(b, c) - let x = truth ? create( thisIsASuperLongIdentifieeeeeeeer, @@ -158,7 +150,6 @@ let x = exceptionLike } let tuple = truth ? (1, 2, 3, 4) : (4, 5, 6, 7) - let tuple = truth ? ( thisIsASuperLongIdentifieeeeeeeer, @@ -172,13 +163,11 @@ let tuple = truth ) let x = condition1 ? node.left : node.right - let x = condition1 ? nodeWithVeryLooooooooooooooooongNameHere.left : nodeWithVeryLooooooooooooooooongNameHere.right let x = condition ? node.left = Some(newNode) : node.right = Some(newNode) - let x = condition1 ? nodeWithVeryLooooooooooooooooongNameHere.left = Some(newNode) : nodeWithVeryLooooooooooooooooongNameHere.right = Some(newNode) @@ -194,7 +183,6 @@ let x = condition1 } else { () } - let () = condition1 ? { sideEffect() @@ -212,7 +200,6 @@ let () = condition1 : while true { doOtherThing() } - let () = condition1 ? for i in 0 to 10 { () @@ -232,11 +219,9 @@ let () = condition exception Exit throw(Exit) } - let () = condition ? foo() : assert(false) let x = condition ? module(Foo) : module(Int: Number) - let x = condition ? module(ModuleWithVeryLooooooooooooooooongNameHere) : module(ModuleWithVeryLooooooooooooooooongNameHereInt: Number) @@ -250,12 +235,10 @@ let x = condition open React render() } - let x = condition ? %eval("console.log") : %eval("console.err") let x = condition ? %eval("consoooooooooooooooooooooole.log") : %eval("consoleeeeeeeeeeeeeee.err") let jsObj = condition ? {"x": 1, "y": 2} : {"x": 20, "y": 100} - let jsObj = truth ? { "thisIsASuperLongFieldHere": loooooooooooooongIdentifier, diff --git a/tests/syntax_tests/data/printer/expr/expected/unary.res.txt b/tests/syntax_tests/data/printer/expr/expected/unary.res.txt index 63bb3d5eac9..e3c7fd69176 100644 --- a/tests/syntax_tests/data/printer/expr/expected/unary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/unary.res.txt @@ -47,7 +47,6 @@ let x = -apply(arg) let x = -Foo(a, b, c) let x = -{x: 1, y: 2} let x = -list{1, 2, 3} - let x = -( if true { 1 @@ -55,33 +54,27 @@ let x = -( 2 } ) - let x = -( for i in 0 to 10 { () } ) - let x = -( switch x { | Foo => 1 } ) - let x = -( while i < 10 { i.contents = 20 } ) - let x = -(1, 2, 3) - let x = -{ let a = 1 let b = 2 a + b } - let x = -{ sideEffect() generateNumber() diff --git a/tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt index a7768c331d0..1179ae4849c 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt @@ -1,10 +1,8 @@ module A = @attr F module B = @attr {} - module C = @attr { let x = 1 } - module D = @a @b F // on a functor application, its functor, or an argument @@ -14,15 +12,12 @@ module H = @attr F(A, B) module I = (@attr F(A))(B) module J = F(@attr X) module Q = F(@attr {}) - include @attr F({ type t = int }) - include (@attr F)({ type t = int }) - include F(@attr { type t = int }) diff --git a/tests/syntax_tests/data/printer/modExpr/expected/functor.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/functor.res.txt index c2559191aba..312c49ecd41 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/functor.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/functor.res.txt @@ -11,21 +11,17 @@ include (@functorAttr2 @functorAttr X: Map, @attr3 Y: Set) => Zzzzzzzzzzzzzzzzzz module Make = (A: X, B: Y) => { let a = A.a + B.b } - // constraint on return type module Make = (A: X, B: Y): Set => { let a = A.a + B.b } - include (@functorAttr X: Map, Y: Set, Z: SuperLongModuleTypeName, Foo: Baaaaaaaaar): Set => { let a = A.a + B.b } - // with attributes module Make = (@functorAttr A: X, B: Y): Set => { let a = A.a + B.b } - module Make = (@functorAttr A: X, @functorAttr2 B: Y): Set => { let a = A.a + B.b } @@ -50,7 +46,6 @@ module Make = ( type key = t type coll = list let empty = list{} - let add = (y: coll, e: key) => if List.exists(x => eq(x, e), y) { y @@ -62,7 +57,6 @@ module Make = ( module Make = (A: X, B: Y): ((Set, Set) => Set) => { let a = A.a + B.b } - module Make = (SuperLongNaaaaaaaame: X, SuperLongNaaaaaaaame: Y, SuperLongNaaaaaaaame: Z): ( ( Seeeeeeeeeeeeeeeeeeeeeeeeeeeeet, diff --git a/tests/syntax_tests/data/printer/modExpr/expected/include.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/include.res.txt index 3e01e2720c2..a1fec610ccf 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/include.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/include.res.txt @@ -2,11 +2,9 @@ type t include Sprite.Comp({type t = t}) include Color.Comp({type t = t}) - include Pos.Comp({ type t = superLooooooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnngggggTyyyyyyypeeeNaaaaaammeee }) - include Area.Comp({type t = t}) include Anchor.Comp({type t = t}) include Move.Comp({type t = t}) diff --git a/tests/syntax_tests/data/printer/modExpr/expected/parens.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/parens.res.txt index 477e568e8df..641f1508293 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/parens.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/parens.res.txt @@ -9,7 +9,6 @@ let e2 = (module(await (@a X)): module(S)) let e3 = (module(await (X: S1)): module(S2)) let e4 = (module(await @a (await X)): module(S)) let e5 = module(await @a X: S) - let f = () => { module M: T = (X: S) () diff --git a/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt b/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt index 31cc4493f41..14e1ecd1f67 100644 --- a/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt +++ b/tests/syntax_tests/data/printer/modExpr/expected/structure.res.txt @@ -31,7 +31,6 @@ module M7: { module N: { let x: int } - module N' = N }) @@ -63,10 +62,8 @@ module M6 = { module D = { let y = 3 } - module N = { let x = 1 } - module N' = N } diff --git a/tests/syntax_tests/data/printer/modType/expected/moduleTypeOf.res.txt b/tests/syntax_tests/data/printer/modType/expected/moduleTypeOf.res.txt index ed1236c4ca0..2c1f4c85161 100644 --- a/tests/syntax_tests/data/printer/modType/expected/moduleTypeOf.res.txt +++ b/tests/syntax_tests/data/printer/modType/expected/moduleTypeOf.res.txt @@ -1,4 +1,3 @@ module type LinkedList = module type of List - module type LinkedList = @attr module type of List diff --git a/tests/syntax_tests/data/printer/modType/expected/withConstraints.res.txt b/tests/syntax_tests/data/printer/modType/expected/withConstraints.res.txt index 42f7f950c60..45b429ef33e 100644 --- a/tests/syntax_tests/data/printer/modType/expected/withConstraints.res.txt +++ b/tests/syntax_tests/data/printer/modType/expected/withConstraints.res.txt @@ -4,7 +4,6 @@ module type A = Foo with type t<'a> = string module type A = Foo with type t<'a, 'b> = string module type A = Foo with type t = 'st constraint 'st = int module type A = Foo with type t = 'st constraint 'st = int constraint 'x = int - module type A = Foo with type t = 'st constraint 'st = int constraint 'x = int and type t = 'st constraint 'st = int constraint 'x = int @@ -14,7 +13,6 @@ module type A = Foo with type t := string module type A = Foo with type t<'a> := string module type A = Foo with type t<'a, 'b> := string module type A = Foo with type Bar.t<'a, 'b> := string - module type A = Foo with type Bar.t<'a, 'b> := string and type Bar.t<'a, 'b> := string @@ -23,7 +21,6 @@ module type A = Foo module type A = Foo with module Bar = Array module type A = Foo with module Bar = Belt.Array module type A = Foo with module X.Bar = Belt.Array - module type A = Foo with module X.Bar = Belt.Array and module X.Bar = Belt.Array @@ -31,7 +28,6 @@ module type A = Foo module type A = Foo with module Bar := Array module type A = Foo with module Bar := Belt.Array - module type A = Foo with module X.Bar := Belt.Array and module X.Bar := Belt.Array @@ -40,14 +36,12 @@ module type A = Foo module Same = (Na: N, Nb: N): ((S with type number1 = Na.number) with type number2 = Nb.number) => { type number1 = Na.number type number2 = Nb.number - let rec sim = ((n, m)) => if Na.is_zero(n) { Nb.is_zero(m) } else { sim((Na.pred(n), Nb.pred(m))) } - let similar = ((n, m)) => try sim((n, m)) catch { | Na.Too_small => false diff --git a/tests/syntax_tests/data/printer/other/expected/StaticReactTypes.res.txt b/tests/syntax_tests/data/printer/other/expected/StaticReactTypes.res.txt index d7b8a1bf936..dd479c4a0a4 100644 --- a/tests/syntax_tests/data/printer/other/expected/StaticReactTypes.res.txt +++ b/tests/syntax_tests/data/printer/other/expected/StaticReactTypes.res.txt @@ -1,5 +1,4 @@ type empty = Empty_ - /* * Also create another form for splicing in nodes into otherwise fixed length * sets. diff --git a/tests/syntax_tests/data/printer/other/expected/attributes.res.txt b/tests/syntax_tests/data/printer/other/expected/attributes.res.txt index 5f5be3c028e..b34daf6830c 100644 --- a/tests/syntax_tests/data/printer/other/expected/attributes.res.txt +++ b/tests/syntax_tests/data/printer/other/expected/attributes.res.txt @@ -8,7 +8,6 @@ let x = 1 let x = 1 %ext(: let x: int) - %ext(: let x: int let y: float diff --git a/tests/syntax_tests/data/printer/other/expected/fatSlider.res.txt b/tests/syntax_tests/data/printer/other/expected/fatSlider.res.txt index 94515d673e1..784733579ff 100644 --- a/tests/syntax_tests/data/printer/other/expected/fatSlider.res.txt +++ b/tests/syntax_tests/data/printer/other/expected/fatSlider.res.txt @@ -6,7 +6,6 @@ module Range = { /* See https://github.com/reasonml/reason-react/blob/master/docs/clone-element.md */ /* We'll need to spread both the style inside the props, and the props object itself using ReasonReact.cloneElement. */ type rec propsThatNeedSpreading = {style: ReactDOMRe.Style.t} - type rec renderTrackParams = { props: propsThatNeedSpreading, children: React.element, diff --git a/tests/syntax_tests/data/printer/pattern/expected/alias.res.txt b/tests/syntax_tests/data/printer/pattern/expected/alias.res.txt index 0d4e0f811b7..f55c7b27eac 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/alias.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/alias.res.txt @@ -13,6 +13,5 @@ let f = x => | Some(@a ()) => 5 | _ => 6 } - let g = (@a _) => 1 let h = (@a ()) => 1 diff --git a/tests/syntax_tests/data/printer/pattern/expected/firstClassModules.res.txt b/tests/syntax_tests/data/printer/pattern/expected/firstClassModules.res.txt index 060efb6a329..6712935cbc9 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/firstClassModules.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/firstClassModules.res.txt @@ -1,7 +1,6 @@ let module(Set) = z let module(Set: Set.S with type elt = s) = y let module(Set: Set.S with type elt = s and type elt2 = t) = x - let module(Set: Set.S with type elt = s and type elt2 = t diff --git a/tests/syntax_tests/data/printer/pattern/expected/list.res.txt b/tests/syntax_tests/data/printer/pattern/expected/list.res.txt index 9131949d31f..66d3131e082 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/list.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/list.res.txt @@ -5,7 +5,6 @@ let list{1, 2, 3} = 1 let list{1, 2, ...tail} = 1 let list{aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc} = 1 - let list{ aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbb, diff --git a/tests/syntax_tests/data/printer/pattern/expected/record.res.txt b/tests/syntax_tests/data/printer/pattern/expected/record.res.txt index 41b86b0bb7d..b1861d258b0 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/record.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/record.res.txt @@ -23,7 +23,6 @@ let get_age3 = ({age: "100", name: _}) => age2 let get_age3 = ({age: 1 .. 2, name: _}) => age2 let get_age3 = ({age: 'a' .. 'z', name: _}) => age2 let get_age3 = ({age: (a, b, c, d), name: _}) => age2 - let get_age3 = ({ age: ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, @@ -33,11 +32,9 @@ let get_age3 = ({ ), name: _, }) => age2 - let get_age3 = ({age: Rgb(r, g, b), name: _}) => age2 let get_age3 = ({age: Rgb({r, g, b}), name: _}) => age2 let get_age3 = ({age: Rgb({r: red, g: green, b: black}), name: _}) => age2 - let get_age3 = ({ age: Rgb( rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, @@ -46,7 +43,6 @@ let get_age3 = ({ ), name: _, }) => age2 - let get_age3 = ({ age: Rgb({ r: rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, @@ -59,7 +55,6 @@ let get_age3 = ({ let get_age3 = ({age: #red, name: _}) => age2 let get_age3 = ({age: #Blue, name: _}) => age2 let get_age3 = ({age: #Rgb(r, g, b), name: _}) => age2 - let get_age3 = ({ age: #Rgb( rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, @@ -68,7 +63,6 @@ let get_age3 = ({ ), name: _, }) => age2 - let get_age3 = ({ age: #Rgb({ r: rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr, @@ -77,9 +71,7 @@ let get_age3 = ({ }), name: _, }) => age2 - let get_age3 = ({age: {birthDay: day, birthMonth: month}, name: _}) => age2 - let get_age3 = ({ age: { birthDay: daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay, @@ -90,7 +82,6 @@ let get_age3 = ({ let get_age3 = ({age: [], name: _}) => age2 let get_age3 = ({age: [a, b, c, d], name: _}) => age2 - let get_age3 = ({ age: [ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, @@ -103,7 +94,6 @@ let get_age3 = ({ let get_age3 = ({age: list{}, name: _}) => age2 let get_age3 = ({age: list{a, b, c, d}, name: _}) => age2 - let get_age3 = ({ age: list{ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, @@ -127,12 +117,10 @@ let get_age3 = ({age: %raw("__GC"), name: _}) => age2 let get_age3 = ({age, _}) => age let get_age3 = ({_}) => "" - let get_age3 = () => switch x { | {age, _} => age } - let get_age3 = () => switch x { | {_} => "" diff --git a/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt b/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt index 3583204bb43..a2d580c8a34 100644 --- a/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt +++ b/tests/syntax_tests/data/printer/signature/expected/exception.resi.txt @@ -8,6 +8,5 @@ exception Exit = Ns.Lib.Terminate /** doc comment */ exception ExitEarly({x: int}) - /** doc comment */ exception ExitEarly({x: int, y: string}) diff --git a/tests/syntax_tests/data/printer/signature/expected/externalObjectSpread.resi.txt b/tests/syntax_tests/data/printer/signature/expected/externalObjectSpread.resi.txt index 0219e18d5b3..3e3e77034b8 100644 --- a/tests/syntax_tests/data/printer/signature/expected/externalObjectSpread.resi.txt +++ b/tests/syntax_tests/data/printer/signature/expected/externalObjectSpread.resi.txt @@ -1,4 +1,3 @@ type user = {"name": string} - @val external steve: {...user, "age": int} = "steve" diff --git a/tests/syntax_tests/data/printer/structure/expected/exception.res.txt b/tests/syntax_tests/data/printer/structure/expected/exception.res.txt index 8dd547aeb7a..03f26bf5c0e 100644 --- a/tests/syntax_tests/data/printer/structure/expected/exception.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/exception.res.txt @@ -8,12 +8,10 @@ exception ExitEarly({@attr "jsExit": int, @attr "code": int}) exception ExitEarly({"jsExit": int}) exception ExitEarly({"jsExit": int}, {"code": int}) exception ExitEarly({"jsExit": int}, int, {"code": int}) - exception ExitEarly( {@attr "jsExit": int, @attr "code": int}, {@attr "jsExit": int, @attr "code": int}, ) - exception ExitJsStyle({..}) exception ExitJsStyle({.."code": int}) exception ExitJsStyle({.."code": int}) @@ -35,10 +33,8 @@ exception GadtExit(int): exit /** doc comment */ exception ExitEarly({x: int}) - /** doc comment */ exception ExitEarly({x: int, y: string}) - /** doc comment */ exception ExitEarlyWithManyFields({ firstFieldName: int, diff --git a/tests/syntax_tests/data/printer/structure/expected/externalObjectSpread.res.txt b/tests/syntax_tests/data/printer/structure/expected/externalObjectSpread.res.txt index 0219e18d5b3..3e3e77034b8 100644 --- a/tests/syntax_tests/data/printer/structure/expected/externalObjectSpread.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/externalObjectSpread.res.txt @@ -1,4 +1,3 @@ type user = {"name": string} - @val external steve: {...user, "age": int} = "steve" diff --git a/tests/syntax_tests/data/printer/structure/expected/include.res.txt b/tests/syntax_tests/data/printer/structure/expected/include.res.txt index 12c0144fe66..3e013044097 100644 --- a/tests/syntax_tests/data/printer/structure/expected/include.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/include.res.txt @@ -8,7 +8,6 @@ include ( { @val @module("react") external createElementInternalHack: 'a = "createElement" - @send external apply: ('theFunction, 'theContext, 'arguments) => 'returnTypeOfTheFunction = "apply" diff --git a/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt b/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt index 54908550526..e2909556320 100644 --- a/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt +++ b/tests/syntax_tests/data/printer/structure/expected/typeExtension.res.txt @@ -26,49 +26,37 @@ type t += private Foo = Bar | Circle = Geo.Circle2 type t += Foo = Geo.Metry.Bar @attr type t += @attr1 Foo - @attr type t += @attr1 Foo - @attr type t += @attr1 Foo | @attr2 Bar - @attr type t += @attr1 Foo | @attr2 Bar @attr type t += private @attr1 Foo - @attr type t += private @attr1 Foo - @attr type t += private @attr1 Foo | @attr2 Bar - @attr type t += private @attr1 Foo | @attr2 Bar @attr type t += @attr1 Foo = Bar - @attr type t += @attr1 Foo = Bar - @attr type t += @attr1 Foo = Foo2 | @attr2 Bar = Bar2 - @attr type t += @attr1 Foo = Foo2 | @attr2 Bar = Bar2 @attr type t += private @attr1 Foo = Foo2 - @attr type t += private @attr1 Foo = Foo2 - @attr type t += private @attr1 Foo = Foo2 | @attr2 Bar = Bar2 - @attr type t += private @attr1 Foo = Foo2 | @attr2 Bar = Bar2 diff --git a/tests/syntax_tests/data/printer/typeDef/expected/abstract.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/abstract.res.txt index 8fa11270b40..013424b094e 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/abstract.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/abstract.res.txt @@ -10,7 +10,6 @@ type t = Module.Long.With.Very.VeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryLongName type t = private Module.Long.With.Very.VeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeryLongName.t type t<'superlongthing, 'superlongthing, 'superlongthing, 'superlongthing, 'superlongthing> = string - type t< 'superlongthing, 'superlongthing, diff --git a/tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt index 2389c3db29d..9d0bbabbe54 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/attributes.res.txt @@ -1,10 +1,8 @@ @attr type t = float - @attr type t = float @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr type t = int - @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr @attr type t = int @@ -13,7 +11,6 @@ type t = int @attrWithSuperLongIdentifeirName @attrWithSuperLongIdentifeirName type t = string - @attrWithSuperLongIdentifeirName @attrWithSuperLongIdentifeirName @attrWithSuperLongIdentifeirName diff --git a/tests/syntax_tests/data/printer/typeDef/expected/inlineRecordMultiline.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/inlineRecordMultiline.res.txt index d8344d91b05..b4418c5b800 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/inlineRecordMultiline.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/inlineRecordMultiline.res.txt @@ -39,7 +39,6 @@ type rec gadt<_> = }): gadt type ext = .. - type ext += | C({ name: string, diff --git a/tests/syntax_tests/data/printer/typeDef/expected/record.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/record.res.txt index a91778ea651..a2fea60a25a 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/record.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/record.res.txt @@ -1,13 +1,11 @@ type user = {name: string, age: int} type result<'success, 'failure> = {ok: 'success, fail: 'failure} - type result<'success1, 'failure1, 'success2, 'failure2, 'success3, 'failure3> = { ok: 'success1, fail: 'failure2, } type user = {name: string, age: int, a: string, lot: string, more: string, fields: string} - type user<'lotsOfTypeVars, 'lotsOfTypeVars2, 'lotsOfTypeVars3, 'lotsOfTypeVars4> = { name: string, age: int, @@ -32,7 +30,6 @@ type user = { } constraint 't = string type t = private {name: string, age: int} - type t = private { name: string, age: int, @@ -40,7 +37,6 @@ type t = private { type t = User.t = private {name: string, age: int} type t = @attr User.t = private {name: string, age: int} - type t = User.t = private { name: string, age: int, diff --git a/tests/syntax_tests/data/printer/typeDef/expected/variant.res.txt b/tests/syntax_tests/data/printer/typeDef/expected/variant.res.txt index 17b36d1db8f..3ca25274ad0 100644 --- a/tests/syntax_tests/data/printer/typeDef/expected/variant.res.txt +++ b/tests/syntax_tests/data/printer/typeDef/expected/variant.res.txt @@ -2,32 +2,27 @@ type color = Red | Blue type color = Red | Blue | SuperLongColooooooooooooooourName | AnotherSuuuuuuuuuuuuuuperLongName type color = private Red | Blue - type color = private | Red | Blue | Green - type color = private Red | Blue | SuperLongColooooooooooooooourName | AnotherSuuuuuuuuuuuuuperLongName type color = Colour.t = private Red | Blue - type color = Colour.t = private | Red | Blue | Green - type color = Colour.t = private Red | Blue | SuperLongColoooooooooooooourName | AnotherSuuuuuuuuuuuuuperLongName // gadt type color = Red: color | Blue: color - type color = | Red: color | Blue: color @@ -35,7 +30,6 @@ type color = | AnotherSuuuuuuuuuperLongName: color type color = Rgb(float, float, float) | Hex(int) - type color = | Rgb(superLongTypeName, superLongTypeName, superLongTypeName, superLongTypeName) | Hex(superLongTypeName, superLongTypeName, superLongTypeName, superLongTypeName) @@ -121,6 +115,5 @@ type color = module S = { type s = Five | Six } - type aa = One | Two type bb = | ...aa | Three | Four | ...S.s diff --git a/tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt index 56b47f765a8..9708f5202fd 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt @@ -185,12 +185,10 @@ external debounce: (int, unit => unit, unit => unit) => unit => unit = "debounce external debounce: (int, unit => unit, unit => unit => unit) => unit => unit = "debounce" type returnTyp = (int, int) => @magic float - type returnTyp = ( intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, ) => @magic float - type returnTyp = ( intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, diff --git a/tests/syntax_tests/data/printer/typexpr/expected/bsObject.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/bsObject.res.txt index afc1c8d8222..f854d538574 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/bsObject.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/bsObject.res.txt @@ -1,6 +1,5 @@ type user = {"age": int} type user = {"age": int, "name": string} - type user = { "age": int, "name": string, @@ -11,7 +10,6 @@ type user = { type magic = {..} type t = {.."age": int} - type magicallyLong = {.. "age": int, "name": string, @@ -55,7 +53,6 @@ type t = {.} type t = private {.} type t = constr<{.}, {.}, {.}> - type t = { hr: React.component<{.}>, } diff --git a/tests/syntax_tests/data/printer/typexpr/expected/firstClassModule.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/firstClassModule.res.txt index 3a42bc4e1e3..bf3ca0f4d23 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/firstClassModule.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/firstClassModule.res.txt @@ -1,7 +1,6 @@ type t = module(S) type t = module(Hashmap with type key = string) type t = module(Hashmap with type key = string and type value = int) - type t = module(Hashmap with type key = string and type value = int diff --git a/tests/syntax_tests/data/printer/typexpr/expected/objectTypeSpreading.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/objectTypeSpreading.res.txt index 71ae407c5ad..3531336594e 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/objectTypeSpreading.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/objectTypeSpreading.res.txt @@ -33,7 +33,6 @@ type taggedUser = | Ceo({...user, "age": int, "direction": bool}, {...salary, "taxFraud": bool}) type polyTaggedUser = [#User({...user, "age": int})] - type polyTaggedUser2 = [ | #User({...user, "age": int}) | #Ceo({...user, "age": int, "direction": bool}, {...salary, "taxFraud": bool}) @@ -42,7 +41,6 @@ type polyTaggedUser2 = [ // notice .. and ..., they should have a space type u<'a> = {.. ...hi} as 'a type u<'a> = {.. ...hi, "superLongFieldName": string, "superLongFieldName22222222222": int} as 'a - type u<'a> = {.. ...hi, "superLongFieldName": string, diff --git a/tests/syntax_tests/data/printer/typexpr/expected/typeConstr.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/typeConstr.res.txt index c3754eef9af..c4ee5cb61b5 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/typeConstr.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/typeConstr.res.txt @@ -1,6 +1,5 @@ type t = Option.t type t = Mod.Sub.t - type t = Mod.Sub.t< soooooLoooooong, soooooLoooooong, @@ -20,7 +19,6 @@ type t = Mod.Sub.t< b, c, > - type t = Mod.Sub.t< Mod.Sub.t, Nested.Module.t, @@ -47,7 +45,6 @@ let t: list< > = x type t = Option.t<(tupleTyp1, tupleTyp2, tupleTyp3)> - type t = Option.t<( tupleTyp1, tupleTyp2, @@ -60,7 +57,6 @@ type t = Option.t<( tupleTyp3, tupleTyp3, )> - let t: Option.t<( tupleTyp1, tupleTyp2, diff --git a/tests/syntax_tests/data/printer/typexpr/expected/variant.res.txt b/tests/syntax_tests/data/printer/typexpr/expected/variant.res.txt index 46298f6afb8..4837afcf085 100644 --- a/tests/syntax_tests/data/printer/typexpr/expected/variant.res.txt +++ b/tests/syntax_tests/data/printer/typexpr/expected/variant.res.txt @@ -11,7 +11,6 @@ let id = (x: [> #Red | #Green | #Blue]) => x let upper = (x: [< #Red | #Green]) => true type point = [#Point(float, float)] type \"type" = [#"Point🗿"(\"let", float)] - type shape = [ | #Rectangle(point, point) | #Circle(point, float) @@ -79,7 +78,6 @@ module type Conjunctive = { let f: [< #T([< u2]) & ([< u2]) & ([< u1])] => unit let g: [< #S & ([< u2]) & ([< u2]) & ([< u1])] => unit - let g: [< | #"Exotic-S+" & ([< #"Exotic-u2+"]) & ([< #"Exotic-u2-"]) & ([< #"Exotic-u1+++"]) ] => unit @@ -94,7 +92,6 @@ type currencyPoly = [ // should not break, user wrote it on one line type currencyPoly = [#USD | #CAD | #EUR] - // // should break, line length exceeded type currencyPoly = [ @@ -129,7 +126,6 @@ type foo = [ // doc comments on inherited polyvariant types type rgb = [#Red | #Green | #Blue] - type color = [ | /** Primary colors from RGB */ rgb /** A warm color */ From 13bd5534f2106bee3a296b37bf8c2bf237f53f80 Mon Sep 17 00:00:00 2001 From: Roland Peelen Date: Fri, 23 Oct 2026 14:46:46 +0200 Subject: [PATCH 3/5] Compare format output without carriage returns in the spacing test The formatter writes CRLF on Windows, so the new rewatch format test failed there on line endings alone; it now strips them before comparing. Signed-off-by: Roland Peelen --- .../05-format-experimental-multiline-item-spacing.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh b/rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh index 71c985638e5..ecd254259af 100755 --- a/rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh +++ b/rewatch/tests/format/05-format-experimental-multiline-item-spacing.sh @@ -18,9 +18,12 @@ expected='module A = { let y = 2 let z = 3' +# The formatter writes CRLF on Windows. $(...) drops the trailing newline, so +# compare against the input without it. without=$(printf '%s' "$input" | "$REWATCH_EXECUTABLE" format --stdin .res) -# $(...) drops the trailing newline, so compare against the input without it -if [ $? -ne 0 ] || [ "$without" != "${input%$'\n'}" ]; then +status=$? +without=$(printf '%s' "$without" | tr -d '\r') +if [ $status -ne 0 ] || [ "$without" != "${input%$'\n'}" ]; then error "Format changed spacing without the experimental feature" echo "$without" exit 1 @@ -37,6 +40,7 @@ fs.writeFileSync("rescript.json", JSON.stringify(j,null,2)); with=$(printf '%s' "$input" | "$REWATCH_EXECUTABLE" format --stdin .res) status=$? mv rescript.json.bak rescript.json +with=$(printf '%s' "$with" | tr -d '\r') if [ $status -ne 0 ] || [ "$with" != "$expected" ]; then error "Format did not space multi-line items with MultilineItemSpacing" From 2af5880803c5939f31eaf3004d01a64608953b5c Mon Sep 17 00:00:00 2001 From: Roland Peelen Date: Fri, 23 Oct 2026 15:22:05 +0200 Subject: [PATCH 4/5] Cover multi-line item spacing with unit tests Codecov reported 15 changed lines without coverage: branches of the separator's measurement that the fixtures never reach first, the trailing comments it moves, the new cases of will_break, is_nil and debug, and Experimental_features.to_string. tests/syntax_tests/res_test.ml now prints documents built for each case and checks the output, and formats a module with the feature off and on through the printer API. The fixture adds a multi-line template literal and a trailing comment on a multi-line item. print_list matched an accumulator that cannot be empty after the first item; it now matches the one case that adds a separator and treats every other one as the first item. Signed-off-by: Roland Peelen --- compiler/syntax/src/res_printer.ml | 2 +- .../expected/multilineSpacing.res.txt | 13 ++ .../MultilineItemSpacing/multilineSpacing.res | 11 ++ tests/syntax_tests/res_test.ml | 160 ++++++++++++++++++ 4 files changed, 185 insertions(+), 1 deletion(-) diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 52891025f13..01b63b7d303 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -404,7 +404,6 @@ let print_list ~get_loc ~nodes ~print ?(force_break = false) let doc = print_comments raw_doc t loc in let acc = match (prev_loc_opt, acc) with - | None, _ | _, [] -> [doc] | Some prev_loc, prev_doc :: _ -> let sep = if start_pos.pos_lnum - prev_loc.Location.loc_end.pos_lnum > 1 @@ -414,6 +413,7 @@ let print_list ~get_loc ~nodes ~print ?(force_break = false) else Doc.hard_line in doc :: sep :: acc + | _ -> [doc] in let first_loc_opt = match first_loc_opt with diff --git a/tests/syntax_tests/data/experimental/MultilineItemSpacing/expected/multilineSpacing.res.txt b/tests/syntax_tests/data/experimental/MultilineItemSpacing/expected/multilineSpacing.res.txt index 85d07733e06..083f6ae7239 100644 --- a/tests/syntax_tests/data/experimental/MultilineItemSpacing/expected/multilineSpacing.res.txt +++ b/tests/syntax_tests/data/experimental/MultilineItemSpacing/expected/multilineSpacing.res.txt @@ -56,3 +56,16 @@ let h = () => { } x + y } + +// a template literal with a line break is multi-line +let s = `multi +line` + +let t = 5 + +// a trailing comment stays on the last line of a multi-line item +let g = { + 1 +} // trailing + +let h = 6 diff --git a/tests/syntax_tests/data/experimental/MultilineItemSpacing/multilineSpacing.res b/tests/syntax_tests/data/experimental/MultilineItemSpacing/multilineSpacing.res index da593d06159..7eb0267f80d 100644 --- a/tests/syntax_tests/data/experimental/MultilineItemSpacing/multilineSpacing.res +++ b/tests/syntax_tests/data/experimental/MultilineItemSpacing/multilineSpacing.res @@ -44,3 +44,14 @@ let h = () => { } x + y } + +// a template literal with a line break is multi-line +let s = `multi +line` +let t = 5 + +// a trailing comment stays on the last line of a multi-line item +let g = { + 1 +} // trailing +let h = 6 diff --git a/tests/syntax_tests/res_test.ml b/tests/syntax_tests/res_test.ml index 461ff2866c4..fa554f4e642 100644 --- a/tests/syntax_tests/res_test.ml +++ b/tests/syntax_tests/res_test.ml @@ -525,6 +525,166 @@ module Parser_api_test = struct windows_crlf () end +(* Res_doc.item_separator puts a blank line next to an item that prints on + several lines, measuring the documents on each side as to_string lays them + out. Res_doc.comment hides comments from the measurement. *) +module Multiline_item_spacing_test = struct + module Doc = Res_doc + + let check name ~expected actual = + if actual <> expected then + failwith + (Printf.sprintf "%s:\nexpected:\n%S\nactual:\n%S" name expected actual) + + (* Module items are printed inside a broken group, like print_structure. *) + let print ?(width = 80) doc = + Doc.to_string ~width (Doc.breakable_group ~force_break:true doc) + let items prev next = Doc.concat [prev; Doc.item_separator ~prev ~next; next] + let a = Doc.text "let a = 1" + let b = Doc.text "let b = 2" + + (* A function call that fits on one line at width 80 but not at width 10. *) + let call = + Doc.group + (Doc.concat + [ + Doc.text "f("; + Doc.indent + (Doc.concat + [ + Doc.soft_line; + Doc.text "x,"; + Doc.line; + Doc.text "y"; + Doc.trailing_comma; + ]); + Doc.soft_line; + Doc.text ")"; + ]) + + let measuring () = + check "one-line items stay together" ~expected:"let a = 1\nlet b = 2" + (print (items a b)); + check "a hard line spans lines" ~expected:"x\ny\n\nlet b = 2" + (print (items (Doc.concat [Doc.text "x"; Doc.hard_line; Doc.text "y"]) b)); + check "a literal line spans lines" ~expected:"`x\ny`\n\nlet b = 2" + (print + (items (Doc.concat [Doc.text "`x"; Doc.literal_line; Doc.text "y`"]) b)); + check "a newline inside text spans lines" ~expected:"`x\ny`\n\nlet b = 2" + (print (items (Doc.text "`x\ny`") b)); + check "an item list spans lines" + ~expected:"let a = 1\nlet b = 2\n\nlet c = 3" + (print (items (items a b) (Doc.text "let c = 3"))); + check "a group that fits is one line" ~expected:"f(x, y)\nlet b = 2" + (print (items call b)); + check "a group that breaks spans lines" + ~expected:"f(\n x,\n y,\n)\n\nlet b = 2" + (print ~width:5 (items call b)); + check "a chosen custom layout is measured" ~expected:"let a = 1\nlet b = 2" + (print (items (Doc.custom_layout [a]) b)); + check "break parents and line suffixes do not span lines" + ~expected:"let a = 1 // c\nlet b = 2" + (print + (items + (Doc.concat + [a; Doc.break_parent; Doc.line_suffix (Doc.text " // c")]) + b)); + check "a comment above an item does not count" + ~expected:"let a = 1\n// c\nlet b = 2" + (print + (items a + (Doc.concat + [Doc.comment (Doc.concat [Doc.text "// c"; Doc.hard_line]); b]))); + let forced_if_breaks = + Doc.if_breaks (Doc.text "a") (Doc.concat [Doc.text "b"; Doc.hard_line]) + in + check "an if-breaks broken by its flat branch takes the break branch" + ~expected:"xa\nlet b = 2" + (print (items (Doc.concat [Doc.text "x"; forced_if_breaks]) b)); + check "an if-breaks in a broken group takes the break branch" + ~expected:"{\n}\n\nlet b = 2" + (print + (items + (Doc.breakable_group ~force_break:true + (Doc.concat + [ + Doc.if_breaks (Doc.text "{") (Doc.text "("); + Doc.line; + Doc.text "}"; + ])) + b)) + + let trailing_comments () = + let block = + Doc.concat [Doc.text "let a = {"; Doc.hard_line; Doc.text "}"] + in + let after_block suffix = + items (Doc.concat [block; Doc.line_suffix suffix]) b + in + check "a same-line trailing comment stays on its line" + ~expected:"let a = {\n} // c\n\nlet b = 2" + (print (after_block (Doc.text " // c"))); + check "an own-line trailing comment moves below the blank line" + ~expected:"let a = {\n}\n\n// c\nlet b = 2" + (print (after_block (Doc.concat [Doc.hard_line; Doc.text "// c"]))); + check "an empty own-line trailing comment prints an empty line" + ~expected:"let a = {\n}\n\n\nlet b = 2" + (print (after_block Doc.hard_line)) + + let predicates () = + let separator = Doc.item_separator ~prev:a ~next:b in + assert (Doc.will_break separator); + assert (Doc.will_break Doc.break_parent); + assert (Doc.will_break (Doc.comment Doc.hard_line)); + assert (not (Doc.will_break (Doc.comment a))); + assert (not (Doc.is_nil separator)); + assert (not (Doc.is_nil (Doc.comment a))); + check "an empty custom layout prints nothing" ~expected:"" + (print (Doc.custom_layout [])) + + (* debug prints to stdout; send it to the null device. *) + let debug () = + flush stdout; + let saved = Unix.dup Unix.stdout in + let null = Unix.openfile Filename.null [Unix.O_WRONLY] 0 in + Unix.dup2 null Unix.stdout; + Fun.protect + ~finally:(fun () -> + flush stdout; + Unix.dup2 saved Unix.stdout; + Unix.close saved; + Unix.close null) + (fun () -> Doc.debug (Doc.concat [items a b; Doc.comment a])) + + let printer () = + let source = "module A = {\n let x = 1\n}\nlet y = 2\n" in + let format () = + let result = + Res_driver.parse_implementation_from_source ~display_filename:"A.res" + ~source + in + Res_printer.print_implementation ~width:80 result.parsetree + ~comments:result.comments + in + check "the printer keeps items together by default" ~expected:source + (format ()); + Experimental_features.enable_from_string + (Experimental_features.to_string + Experimental_features.MultilineItemSpacing); + Fun.protect ~finally:Experimental_features.reset (fun () -> + check "the printer spaces items with MultilineItemSpacing" + ~expected:"module A = {\n let x = 1\n}\n\nlet y = 2\n" (format ())) + + let run () = + measuring (); + trailing_comments (); + predicates (); + debug (); + printer (); + print_endline "✅ multi-line item spacing" +end + let () = Outcome_printer_tests.run () let () = Parser_api_test.run () let () = Res_utf8_test.run () +let () = Multiline_item_spacing_test.run () From f209b66548b15b63f370361c0f8aff541ac30195 Mon Sep 17 00:00:00 2001 From: Roland Peelen Date: Fri, 23 Oct 2026 15:42:47 +0200 Subject: [PATCH 5/5] Check is_nil on every document constructor Codecov still reported the last line of the is_nil match: its Group, CustomLayout and BreakParent alternatives share the line with the new ones, and no test passed them. The test now checks every constructor. Signed-off-by: Roland Peelen --- tests/syntax_tests/res_test.ml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/syntax_tests/res_test.ml b/tests/syntax_tests/res_test.ml index fa554f4e642..56f40f837c4 100644 --- a/tests/syntax_tests/res_test.ml +++ b/tests/syntax_tests/res_test.ml @@ -637,8 +637,21 @@ module Multiline_item_spacing_test = struct assert (Doc.will_break Doc.break_parent); assert (Doc.will_break (Doc.comment Doc.hard_line)); assert (not (Doc.will_break (Doc.comment a))); - assert (not (Doc.is_nil separator)); - assert (not (Doc.is_nil (Doc.comment a))); + assert (Doc.is_nil Doc.nil); + [ + a; + Doc.line_suffix a; + Doc.concat [a; b]; + Doc.indent a; + Doc.trailing_comma; + Doc.line; + Doc.group a; + Doc.custom_layout [a]; + Doc.break_parent; + separator; + Doc.comment a; + ] + |> List.iter (fun doc -> assert (not (Doc.is_nil doc))); check "an empty custom layout prints nothing" ~expected:"" (print (Doc.custom_layout []))