Skip to content

Commit c8b2585

Browse files
committed
Make components actually uncurried functions in uncurried mode.
This change does not seem strictly necessary, and it's a bit invasive. E.g. the editor integration needs to be adapted. But eventually, we'll want this in, as otherwise e.g. hover on the `make` would show a curried function.
1 parent 5802387 commit c8b2585

File tree

6 files changed

+66
-11
lines changed

6 files changed

+66
-11
lines changed

jscomp/stdlib-406/pervasivesU.res

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@
1515

1616
@@uncurried
1717

18+
module Jsx = {
19+
type element
20+
type ref
21+
22+
@val external null: element = "null"
23+
24+
external float: float => element = "%identity"
25+
external int: int => element = "%identity"
26+
external string: string => element = "%identity"
27+
28+
external array: array<element> => element = "%identity"
29+
30+
type componentLike<'props, 'return> = 'props => 'return
31+
type component<'props> = componentLike<'props, element>
32+
33+
/* this function exists to prepare for making `component` abstract */
34+
external component: componentLike<'props, element> => component<'props> = "%identity"
35+
}
36+
1837
/* Internal */
1938
external __unsafe_cast: 'a => 'b = "%identity"
2039

@@ -301,12 +320,10 @@ let exit_function = ref(ignore)
301320
let at_exit = f => {
302321
let g = exit_function.contents
303322
exit_function :=
304-
(
305-
() => {
306-
f()
307-
g()
308-
}
309-
)
323+
() => {
324+
f()
325+
g()
326+
}
310327
}
311328

312329
let do_at_exit = () => exit_function.contents()

jscomp/stdlib-406/pervasivesU.resi

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@@ocaml.text(/* ************************************************************************ */
1+
/* ************************************************************************ */
22
/* */
33
/* OCaml */
44
/* */
@@ -13,9 +13,7 @@
1313
/* */
1414
/* ************************************************************************ */
1515

16-
@@uncurried
17-
18-
" The initially opened module.
16+
/*** The initially opened module.
1917

2018
This module provides the basic operations over the built-in types
2119
(numbers, booleans, byte sequences, strings, exceptions, references,
@@ -24,7 +22,28 @@
2422
This module is automatically opened at the beginning of each compilation.
2523
All components of this module can therefore be referred by their short
2624
name, without prefixing them by [Pervasives].
27-
")
25+
*/
26+
27+
@@uncurried
28+
29+
module Jsx: {
30+
type element
31+
type ref
32+
33+
@val external null: element = "null"
34+
35+
external float: float => element = "%identity"
36+
external int: int => element = "%identity"
37+
external string: string => element = "%identity"
38+
39+
external array: array<element> => element = "%identity"
40+
41+
type componentLike<'props, 'return> = 'props => 'return
42+
type component<'props> = componentLike<'props, element>
43+
44+
/* this function exists to prepare for making `component` abstract */
45+
external component: componentLike<'props, element> => component<'props> = "%identity"
46+
}
2847

2948
/* Internal */
3049
external __unsafe_cast: 'a => 'b = "%identity"

lib/es6/pervasivesU.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as Caml_string from "./caml_string.js";
66
import * as Caml_exceptions from "./caml_exceptions.js";
77
import * as Caml_js_exceptions from "./caml_js_exceptions.js";
88

9+
var Jsx = {};
10+
911
function failwith(s) {
1012
throw {
1113
RE_EXN_ID: "Failure",
@@ -216,6 +218,7 @@ var min_float = 2.22507385850720138e-308;
216218
var epsilon_float = 2.22044604925031308e-16;
217219

218220
export {
221+
Jsx ,
219222
invalid_arg ,
220223
failwith ,
221224
Exit ,

lib/js/pervasivesU.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var Caml_string = require("./caml_string.js");
66
var Caml_exceptions = require("./caml_exceptions.js");
77
var Caml_js_exceptions = require("./caml_js_exceptions.js");
88

9+
var Jsx = {};
10+
911
function failwith(s) {
1012
throw {
1113
RE_EXN_ID: "Failure",
@@ -215,6 +217,7 @@ var min_float = 2.22507385850720138e-308;
215217

216218
var epsilon_float = 2.22044604925031308e-16;
217219

220+
exports.Jsx = Jsx;
218221
exports.invalid_arg = invalid_arg;
219222
exports.failwith = failwith;
220223
exports.Exit = Exit;

res_syntax/src/reactjs_jsx_v3.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,13 @@ let jsxMapper ~config =
959959
}
960960
innerExpressionWithRef
961961
in
962+
let fullExpression =
963+
if !Config.uncurried = Uncurried then
964+
fullExpression
965+
|> Ast_uncurried.uncurriedFun ~loc:fullExpression.pexp_loc
966+
~arity:1
967+
else fullExpression
968+
in
962969
let fullExpression =
963970
match fullModuleName with
964971
| "" -> fullExpression

res_syntax/src/reactjs_jsx_v4.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,12 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
952952
innerExpression
953953
else innerExpression)
954954
in
955+
let fullExpression =
956+
if !Config.uncurried = Uncurried then
957+
fullExpression
958+
|> Ast_uncurried.uncurriedFun ~loc:fullExpression.pexp_loc ~arity:1
959+
else fullExpression
960+
in
955961
let fullExpression =
956962
match fullModuleName with
957963
| "" -> fullExpression

0 commit comments

Comments
 (0)