Skip to content

Commit

Permalink
Fix printer in uncurried false mode (#6378)
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Aug 30, 2023
1 parent c43223f commit 2defd97
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### :bug: Bug Fix

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

# 11.0.0-rc.2

Expand Down
6 changes: 6 additions & 0 deletions jscomp/build_tests/uncurried_printer/bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "uncurried_printer",
"version": "0.1.0",
"sources": ["src"],
"uncurried": false
}
15 changes: 15 additions & 0 deletions jscomp/build_tests/uncurried_printer/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const assert = require("assert");
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");

const expectedContent = `let a = (. b) => b\n`;
const filePath = path.join(__dirname, "src", "a.res");

fs.writeFileSync(filePath, expectedContent, "utf-8");

child_process.execSync(`../../../rescript format -all`, { cwd: __dirname });

const content = fs.readFileSync(filePath, "utf-8");

assert.equal(content, expectedContent);
1 change: 1 addition & 0 deletions jscomp/build_tests/uncurried_printer/src/a.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let a = (. b) => b
22 changes: 11 additions & 11 deletions jscomp/syntax/src/res_multi_printer.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
let defaultPrintWidth = 100

(* Determine if the file is in uncurried mode by looking for
the fist ancestor .bsconfig and see if it contains "uncurried": false *)
(* Look at bsconfig.json to set Uncurried or Legacy mode if it contains "uncurried": false *)
let getUncurriedFromBsconfig ~filename =
let rec findBsconfig ~dir =
let bsconfig = Filename.concat dir "bsconfig.json" in
Expand Down Expand Up @@ -38,25 +37,26 @@ let getUncurriedFromBsconfig ~filename =
| None -> ()
| Some bsconfig ->
let lines = bsconfig |> String.split_on_char '\n' in
let uncurried =
let is_legacy_uncurried =
lines
|> List.exists (fun line ->
let uncurried = ref false in
let false_ = ref false in
let is_uncurried_option = ref false in
let is_option_falsy = ref false in
let words = line |> String.split_on_char ' ' in
words
|> List.iter (fun word ->
match word with
| "\"uncurried\"" | "\"uncurried\":" -> uncurried := true
| "\"uncurried\"" | "\"uncurried\":" ->
is_uncurried_option := true
| "\"uncurried\":false" | "\"uncurried\":false," ->
uncurried := true;
false_ := true
is_uncurried_option := true;
is_option_falsy := true
| "false" | ":false" | "false," | ":false," ->
false_ := true
is_option_falsy := true
| _ -> ());
not (!uncurried && !false_))
!is_uncurried_option && !is_option_falsy)
in
if uncurried then Config.uncurried := Uncurried
if not is_legacy_uncurried then Config.uncurried := Uncurried

(* print res files to res syntax *)
let printRes ~ignoreParseErrors ~isInterface ~filename =
Expand Down

0 comments on commit 2defd97

Please sign in to comment.