Skip to content

Commit 2defd97

Browse files
authored
Fix printer in uncurried false mode (#6378)
1 parent c43223f commit 2defd97

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :bug: Bug Fix
1616

1717
- Fix issue with JSX V4 when component props have the default value with same name. https://github.com/rescript-lang/rescript-compiler/pull/6377
18+
- Fixed printer with `"uncurried": false` in bsconfig. https://github.com/rescript-lang/rescript-compiler/pull/6378
1819

1920
# 11.0.0-rc.2
2021

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "uncurried_printer",
3+
"version": "0.1.0",
4+
"sources": ["src"],
5+
"uncurried": false
6+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const assert = require("assert");
2+
const child_process = require("child_process");
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
const expectedContent = `let a = (. b) => b\n`;
7+
const filePath = path.join(__dirname, "src", "a.res");
8+
9+
fs.writeFileSync(filePath, expectedContent, "utf-8");
10+
11+
child_process.execSync(`../../../rescript format -all`, { cwd: __dirname });
12+
13+
const content = fs.readFileSync(filePath, "utf-8");
14+
15+
assert.equal(content, expectedContent);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a = (. b) => b

jscomp/syntax/src/res_multi_printer.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
let defaultPrintWidth = 100
22

3-
(* Determine if the file is in uncurried mode by looking for
4-
the fist ancestor .bsconfig and see if it contains "uncurried": false *)
3+
(* Look at bsconfig.json to set Uncurried or Legacy mode if it contains "uncurried": false *)
54
let getUncurriedFromBsconfig ~filename =
65
let rec findBsconfig ~dir =
76
let bsconfig = Filename.concat dir "bsconfig.json" in
@@ -38,25 +37,26 @@ let getUncurriedFromBsconfig ~filename =
3837
| None -> ()
3938
| Some bsconfig ->
4039
let lines = bsconfig |> String.split_on_char '\n' in
41-
let uncurried =
40+
let is_legacy_uncurried =
4241
lines
4342
|> List.exists (fun line ->
44-
let uncurried = ref false in
45-
let false_ = ref false in
43+
let is_uncurried_option = ref false in
44+
let is_option_falsy = ref false in
4645
let words = line |> String.split_on_char ' ' in
4746
words
4847
|> List.iter (fun word ->
4948
match word with
50-
| "\"uncurried\"" | "\"uncurried\":" -> uncurried := true
49+
| "\"uncurried\"" | "\"uncurried\":" ->
50+
is_uncurried_option := true
5151
| "\"uncurried\":false" | "\"uncurried\":false," ->
52-
uncurried := true;
53-
false_ := true
52+
is_uncurried_option := true;
53+
is_option_falsy := true
5454
| "false" | ":false" | "false," | ":false," ->
55-
false_ := true
55+
is_option_falsy := true
5656
| _ -> ());
57-
not (!uncurried && !false_))
57+
!is_uncurried_option && !is_option_falsy)
5858
in
59-
if uncurried then Config.uncurried := Uncurried
59+
if not is_legacy_uncurried then Config.uncurried := Uncurried
6060

6161
(* print res files to res syntax *)
6262
let printRes ~ignoreParseErrors ~isInterface ~filename =

0 commit comments

Comments
 (0)