From 4ca7a550308f7aec127142cd3585279b663c6ad2 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Wed, 30 Aug 2023 16:36:11 +0400 Subject: [PATCH 1/5] Add test for broken uncurried printer --- .../uncurried_printer/bsconfig.json | 6 ++++++ jscomp/build_tests/uncurried_printer/input.js | 19 +++++++++++++++++++ .../build_tests/uncurried_printer/src/a.res | 1 + 3 files changed, 26 insertions(+) create mode 100644 jscomp/build_tests/uncurried_printer/bsconfig.json create mode 100755 jscomp/build_tests/uncurried_printer/input.js create mode 100644 jscomp/build_tests/uncurried_printer/src/a.res diff --git a/jscomp/build_tests/uncurried_printer/bsconfig.json b/jscomp/build_tests/uncurried_printer/bsconfig.json new file mode 100644 index 0000000000..ded06e80cd --- /dev/null +++ b/jscomp/build_tests/uncurried_printer/bsconfig.json @@ -0,0 +1,6 @@ +{ + "name": "uncurried_printer", + "version": "0.1.0", + "sources": ["src"], + "uncurried": false +} diff --git a/jscomp/build_tests/uncurried_printer/input.js b/jscomp/build_tests/uncurried_printer/input.js new file mode 100755 index 0000000000..da437221e5 --- /dev/null +++ b/jscomp/build_tests/uncurried_printer/input.js @@ -0,0 +1,19 @@ +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 incorrectContent = `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, incorrectContent); + +// Rollback the incorrect content until it's fixed +fs.writeFileSync(filePath, expectedContent, "utf-8"); diff --git a/jscomp/build_tests/uncurried_printer/src/a.res b/jscomp/build_tests/uncurried_printer/src/a.res new file mode 100644 index 0000000000..568bcab521 --- /dev/null +++ b/jscomp/build_tests/uncurried_printer/src/a.res @@ -0,0 +1 @@ +let a = (. b) => b From 29bd42ec8c5acfa6d8b3f7179edfdc095005b9bf Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Wed, 30 Aug 2023 19:28:51 +0400 Subject: [PATCH 2/5] Fix getUncurriedFromBsconfig --- jscomp/build_tests/uncurried_printer/input.js | 6 +--- jscomp/syntax/src/res_multi_printer.ml | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/jscomp/build_tests/uncurried_printer/input.js b/jscomp/build_tests/uncurried_printer/input.js index da437221e5..e5b78de60a 100755 --- a/jscomp/build_tests/uncurried_printer/input.js +++ b/jscomp/build_tests/uncurried_printer/input.js @@ -4,7 +4,6 @@ const fs = require("fs"); const path = require("path"); const expectedContent = `let a = (. b) => b\n`; -const incorrectContent = `let a = b => b\n`; const filePath = path.join(__dirname, "src", "a.res"); fs.writeFileSync(filePath, expectedContent, "utf-8"); @@ -13,7 +12,4 @@ child_process.execSync(`../../../rescript format -all`, { cwd: __dirname }); const content = fs.readFileSync(filePath, "utf-8"); -assert.equal(content, incorrectContent); - -// Rollback the incorrect content until it's fixed -fs.writeFileSync(filePath, expectedContent, "utf-8"); +assert.equal(content, expectedContent); diff --git a/jscomp/syntax/src/res_multi_printer.ml b/jscomp/syntax/src/res_multi_printer.ml index d419db1c8b..34b2c93987 100644 --- a/jscomp/syntax/src/res_multi_printer.ml +++ b/jscomp/syntax/src/res_multi_printer.ml @@ -41,20 +41,21 @@ let getUncurriedFromBsconfig ~filename = let uncurried = lines |> List.exists (fun line -> - let uncurried = ref false in - let false_ = ref false in - let words = line |> String.split_on_char ' ' in - words - |> List.iter (fun word -> - match word with - | "\"uncurried\"" | "\"uncurried\":" -> uncurried := true - | "\"uncurried\":false" | "\"uncurried\":false," -> - uncurried := true; - false_ := true - | "false" | ":false" | "false," | ":false," -> - false_ := true - | _ -> ()); - not (!uncurried && !false_)) + let uncurried = ref false in + let false_ = ref false in + let words = line |> String.split_on_char ' ' in + words + |> List.iter (fun word -> + match word with + | "\"uncurried\"" | "\"uncurried\":" -> uncurried := true + | "\"uncurried\":false" | "\"uncurried\":false," -> + uncurried := true; + false_ := true + | "false" | ":false" | "false," | ":false," -> + false_ := true + | _ -> ()); + !uncurried && not !false_ + ) in if uncurried then Config.uncurried := Uncurried From 9f728c4c73ac87dd56121725634bbe5d455a4d1b Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Wed, 30 Aug 2023 19:32:08 +0400 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b13ac9c13..60a86d3dc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From bc09a87ac4a09c5ff2d92504584e62f466304c49 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Wed, 30 Aug 2023 19:54:25 +0400 Subject: [PATCH 4/5] Fix getUncurriedFromBsconfig --- jscomp/syntax/src/res_multi_printer.ml | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/jscomp/syntax/src/res_multi_printer.ml b/jscomp/syntax/src/res_multi_printer.ml index 34b2c93987..b0d17d4a46 100644 --- a/jscomp/syntax/src/res_multi_printer.ml +++ b/jscomp/syntax/src/res_multi_printer.ml @@ -38,26 +38,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 words = line |> String.split_on_char ' ' in - words - |> List.iter (fun word -> - match word with - | "\"uncurried\"" | "\"uncurried\":" -> uncurried := true - | "\"uncurried\":false" | "\"uncurried\":false," -> - uncurried := true; - false_ := true - | "false" | ":false" | "false," | ":false," -> - false_ := true - | _ -> ()); - !uncurried && not !false_ - ) + 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\":" -> + is_uncurried_option := true + | "\"uncurried\":false" | "\"uncurried\":false," -> + is_uncurried_option := true; + is_option_falsy := true + | "false" | ":false" | "false," | ":false," -> + is_option_falsy := true + | _ -> ()); + !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 = From b9a6ca8239a51be19a65ea57a5c5c8480e995756 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Wed, 30 Aug 2023 20:56:58 +0400 Subject: [PATCH 5/5] Update doc comment --- jscomp/syntax/src/res_multi_printer.ml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jscomp/syntax/src/res_multi_printer.ml b/jscomp/syntax/src/res_multi_printer.ml index b0d17d4a46..354311ce08 100644 --- a/jscomp/syntax/src/res_multi_printer.ml +++ b/jscomp/syntax/src/res_multi_printer.ml @@ -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