diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aa338c251..343a2affd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,11 @@ - Add experimental command to `rescript-tools` for extracting all ReScript code blocks from markdown, either a md-file directly, or inside of docstrings in ReScript code. https://github.com/rescript-lang/rescript/pull/7623 +#### :bug: Bug fix + +- Fix `typeof` parens on functions. https://github.com/rescript-lang/rescript/pull/7643 + + # 12.0.0-beta.1 #### :rocket: New Feature diff --git a/compiler/core/js_dump.ml b/compiler/core/js_dump.ml index 1684aa056c..44820298f6 100644 --- a/compiler/core/js_dump.ml +++ b/compiler/core/js_dump.ml @@ -798,9 +798,14 @@ and expression_desc cxt ~(level : int) f x : cxt = P.string f " in "; expression ~level:0 cxt f obj) | Typeof e -> + let is_fun = + match e.expression_desc with + | Fun _ -> true + | _ -> false + in P.string f "typeof"; P.space f; - expression ~level:13 cxt f e + P.cond_paren_group f is_fun (fun _ -> expression ~level:13 cxt f e) | Bin ( Minus, { diff --git a/tests/tests/src/core/Test.mjs b/tests/tests/src/core/Test.mjs index 936183ec24..d5af26fce7 100644 --- a/tests/tests/src/core/Test.mjs +++ b/tests/tests/src/core/Test.mjs @@ -45,9 +45,14 @@ function run(loc, left, comparator, right) { console.log(obj.stack.replace(/\n /g, "\n ").replace(/^Error\n/, "").replace(/^.+\n/, "").replace(/\n at .+\(node:internal.+\n?/g, "")); } +console.log(typeof (prim => require(prim))); + +let TypeofParensOnFun = {}; + export { dirname, print, run, + TypeofParensOnFun, } /* dirname Not a pure module */ diff --git a/tests/tests/src/core/Test.res b/tests/tests/src/core/Test.res index d62638c910..cd94b2c6cd 100644 --- a/tests/tests/src/core/Test.res +++ b/tests/tests/src/core/Test.res @@ -48,3 +48,9 @@ ${codeFrame} ->Console.log } } + +module TypeofParensOnFun = { + @val external require: string => {..} = "require" + + Console.log(Type.typeof(require)) +}