Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#### :nail_care: Polish

- Omit redundant braces around multi-statement switch case bodies when formatting. https://github.com/rescript-lang/rescript/pull/8677
Comment thread
cknitt marked this conversation as resolved.
- Avoid running `rescript-schema-ppx` and `sury-ppx` on source files without an `@schema` annotation. https://github.com/rescript-lang/rescript/pull/8662

#### :house: Internal
Expand Down
1 change: 0 additions & 1 deletion compiler/syntax/Formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ that all source line breaks must be retained.

When changing the formatter:

- test both narrow and wide print widths;
- cover comments and the parentheses needed to preserve parsing;
- run `make test-syntax` and `make test-syntax-roundtrip`;
- inspect snapshot changes for unrelated reformatting;
Expand Down
27 changes: 13 additions & 14 deletions compiler/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5272,18 +5272,15 @@ and print_cases ~state (cases : Parsetree.case list) cmt_tbl =
])

and print_case ~state (case : Parsetree.case) cmt_tbl =
let is_block_rhs = Parsetree_viewer.is_block_expr case.pc_rhs in
let rhs =
match case.pc_rhs.pexp_desc with
| Pexp_let _ | Pexp_letmodule _ | Pexp_letexception _ | Pexp_open _
| Pexp_sequence _ ->
print_expression_block ~state
~braces:(Parsetree_viewer.is_braced_expr case.pc_rhs)
case.pc_rhs cmt_tbl
| _ -> (
if is_block_rhs then
print_expression_block ~state ~braces:false case.pc_rhs cmt_tbl
else
let doc = print_expression_with_comments ~state case.pc_rhs cmt_tbl in
match Parens.expr case.pc_rhs with
| Parenthesized -> add_parens doc
| _ -> doc)
| _ -> doc
in

let guard =
Expand All @@ -5299,12 +5296,14 @@ and print_case ~state (case : Parsetree.case) cmt_tbl =
])
in
let should_inline_rhs =
match case.pc_rhs.pexp_desc with
| Pexp_construct ({txt = Longident.Lident ("()" | "true" | "false")}, _)
| Pexp_constant _ | Pexp_ident _ ->
true
| _ when Parsetree_viewer.is_huggable_rhs case.pc_rhs -> true
| _ -> false
if is_block_rhs then false
else
match case.pc_rhs.pexp_desc with
| Pexp_construct ({txt = Longident.Lident ("()" | "true" | "false")}, _)
| Pexp_constant _ | Pexp_ident _ ->
true
| _ when Parsetree_viewer.is_huggable_rhs case.pc_rhs -> true
| _ -> false
in
let should_indent_pattern =
match case.pc_lhs.ppat_desc with
Expand Down
16 changes: 7 additions & 9 deletions packages/@rescript/runtime/Primitive_exceptions.res
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@ let idMap = Dict.empty()

let create = (str: string): string => {
switch idMap->Dict.dangerouslyGetNonOption(str) {
| Some(v) => {
let id = v + 1
idMap->Dict.set(str, id)
str ++ ("/" ++ (Obj.magic((id: int)): string))
}
| None => {
idMap->Dict.set(str, 1)
str
}
| Some(v) =>
let id = v + 1
idMap->Dict.set(str, id)
str ++ ("/" ++ (Obj.magic((id: int)): string))
| None =>
idMap->Dict.set(str, 1)
str
}
}
Loading