diff --git a/CHANGELOG.md b/CHANGELOG.md index eda17db2e0..b41344d319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ - Introduce experimental uncurried by default mode. Can be turned on mid-file by adding standalone annotation `@@uncurried`. For experimentation only. https://github.com/rescript-lang/rescript-compiler/pull/5796 +- Adding `@@toUncurried` to the file and reformat will convert to uncurried syntax https://github.com/rescript-lang/rescript-compiler/pull/5800 + #### :boom: Breaking Change - Remove support for the legacy Reason syntax. Existing Reason code can be converted to ReScript syntax using ReScript 9 as follows: diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index f8bcd0345a..2098cb1ccb 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -58330,7 +58330,16 @@ and printAttribute ?(standalone = false) ~state ], Doc.hardLine ) | _ -> - if id.txt = "uncurried" then state.uncurried_by_default <- true; + let id = + match id.txt with + | "uncurried" -> + state.uncurried_by_default <- true; + id + | "toUncurried" -> + state.uncurried_by_default <- true; + {id with txt = "uncurried"} + | _ -> id + in ( Doc.group (Doc.concat [ diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 81bbc0bb22..152d7727cd 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -58330,7 +58330,16 @@ and printAttribute ?(standalone = false) ~state ], Doc.hardLine ) | _ -> - if id.txt = "uncurried" then state.uncurried_by_default <- true; + let id = + match id.txt with + | "uncurried" -> + state.uncurried_by_default <- true; + id + | "toUncurried" -> + state.uncurried_by_default <- true; + {id with txt = "uncurried"} + | _ -> id + in ( Doc.group (Doc.concat [ diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 9cb3b3dbdd..17496469c3 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -113325,7 +113325,16 @@ and printAttribute ?(standalone = false) ~state ], Doc.hardLine ) | _ -> - if id.txt = "uncurried" then state.uncurried_by_default <- true; + let id = + match id.txt with + | "uncurried" -> + state.uncurried_by_default <- true; + id + | "toUncurried" -> + state.uncurried_by_default <- true; + {id with txt = "uncurried"} + | _ -> id + in ( Doc.group (Doc.concat [ diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index ea9532e84c..4720101cb4 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -6404,7 +6404,14 @@ and parseStandaloneAttribute p = let startPos = p.startPos in Parser.expect AtAt p; let attrId = parseAttributeId ~startPos p in - if attrId.txt = "uncurried" then p.uncurried_by_default <- true; + let attrId = + match attrId.txt with + | "uncurried" -> + p.uncurried_by_default <- true; + attrId + | "toUncurried" -> {attrId with txt = "uncurried"} + | _ -> attrId + in let payload = parsePayload p in (attrId, payload) diff --git a/res_syntax/src/res_printer.ml b/res_syntax/src/res_printer.ml index 12d3606206..d13d7b9d73 100644 --- a/res_syntax/src/res_printer.ml +++ b/res_syntax/src/res_printer.ml @@ -5264,7 +5264,16 @@ and printAttribute ?(standalone = false) ~state ], Doc.hardLine ) | _ -> - if id.txt = "uncurried" then state.uncurried_by_default <- true; + let id = + match id.txt with + | "uncurried" -> + state.uncurried_by_default <- true; + id + | "toUncurried" -> + state.uncurried_by_default <- true; + {id with txt = "uncurried"} + | _ -> id + in ( Doc.group (Doc.concat [ diff --git a/res_syntax/tests/printer/expr/ToUncurried.res b/res_syntax/tests/printer/expr/ToUncurried.res new file mode 100644 index 0000000000..0b704a150e --- /dev/null +++ b/res_syntax/tests/printer/expr/ToUncurried.res @@ -0,0 +1,35 @@ +let cApp = foo(3) +let uApp = foo(. 3) + +let cFun = x => 3 +let uFun = (.x) => 3 +let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4 +let bracesFun = (. x) => y => x+y +let cFun2 = (x, y) => 3 +let uFun2 = (. x, y) => 3 + +type cTyp = string => int +type uTyp = (. string) => int +type mixTyp = (string, .string, string) => (string, string, string) => (string, .string) => int +type bTyp = (. string) => string => int +type cTyp2 = (string, string) => int +type uTyp2 = (.string, string) => int + +@@toUncurried + +let cApp = foo(3) +let uApp = foo(. 3) + +let cFun = x => 3 +let uFun = (.x) => 3 +let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4 +let bracesFun = (. x) => y => x+y +let cFun2 = (x, y) => 3 +let uFun2 = (. x, y) => 3 + +type cTyp = string => int +type uTyp = (. string) => int +type mixTyp = (string, .string, string) => (string, string, string) => (string, .string) => int +type bTyp = (. string) => string => int +type cTyp2 = (string, string) => int +type uTyp2 = (.string, string) => int diff --git a/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt b/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt new file mode 100644 index 0000000000..b11293a008 --- /dev/null +++ b/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt @@ -0,0 +1,35 @@ +let cApp = foo(3) +let uApp = foo(. 3) + +let cFun = x => 3 +let uFun = (. x) => 3 +let mixFun = a => (. b, c) => {(d, e, f, g) => (. h) => 4} +let bracesFun = (. x) => {y => x + y} +let cFun2 = (x, y) => 3 +let uFun2 = (. x, y) => 3 + +type cTyp = string => int +type uTyp = (. string) => int +type mixTyp = string => (. string, string) => (string, string, string, string) => (. string) => int +type bTyp = (. string) => string => int +type cTyp2 = (string, string) => int +type uTyp2 = (. string, string) => int + +@@uncurried + +let cApp = foo(. 3) +let uApp = foo(3) + +let cFun = (. x) => 3 +let uFun = x => 3 +let mixFun = (. a) => (b, c) => {(. d, e, f, g) => h => 4} +let bracesFun = x => {(. y) => x + y} +let cFun2 = (. x, y) => 3 +let uFun2 = (x, y) => 3 + +type cTyp = (. string) => int +type uTyp = string => int +type mixTyp = (. string) => (string, string) => (. string, string, string, string) => string => int +type bTyp = string => (. string) => int +type cTyp2 = (. string, string) => int +type uTyp2 = (string, string) => int