Skip to content

Commit 785bc59

Browse files
committed
make jsx component abstract
1 parent 6a9fe4a commit 785bc59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+202
-141
lines changed

jscomp/build_tests/react_ppx/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
var cp = require("child_process");
33
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
44

5-
cp.execSync(rescript_exe, { cwd: __dirname });
5+
// cp.execSync(rescript_exe, { cwd: __dirname });

jscomp/others/jsxC.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ external string: string => element = "%identity"
3636
external array: array<element> => element = "%identity"
3737

3838
type componentLike<'props, 'return> = 'props => 'return
39-
type component<'props> = componentLike<'props, element>
39+
type component<'props>
4040

4141
/* this function exists to prepare for making `component` abstract */
4242
external component: componentLike<'props, element> => component<'props> = "%identity"

jscomp/others/jsxU.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ external string: string => element = "%identity"
1414
external array: array<element> => element = "%identity"
1515

1616
type componentLike<'props, 'return> = 'props => 'return
17-
type component<'props> = componentLike<'props, element>
17+
type component<'props>
1818

1919
/* this function exists to prepare for making `component` abstract */
2020
external component: componentLike<'props, element> => component<'props> = "%identity"

jscomp/syntax/src/reactjs_jsx_v4.ml

+12-6
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,12 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
958958
|> Ast_uncurried.uncurriedFun ~loc:fullExpression.pexp_loc ~arity:1
959959
else fullExpression
960960
in
961+
(* making component abstract *)
962+
let fullExpression =
963+
Exp.apply
964+
(Exp.ident (Location.mknoloc @@ Ldot (Lident "React", "component")))
965+
[(Nolabel, fullExpression)]
966+
in
961967
let fullExpression =
962968
match fullModuleName with
963969
| "" -> fullExpression
@@ -1122,7 +1128,7 @@ let transformStructureItem ~config item =
11221128
(name, ptyp_attributes, returnValue.ptyp_loc, type_) :: types )
11231129
| _ -> (fullType, types)
11241130
in
1125-
let innerType, propTypes = getPropTypes [] pval_type in
1131+
let _, propTypes = getPropTypes [] pval_type in
11261132
let namedTypeList = List.fold_left argToConcreteType [] propTypes in
11271133
let retPropsType =
11281134
Typ.constr ~loc:pstr_loc
@@ -1142,8 +1148,8 @@ let transformStructureItem ~config item =
11421148
(* can't be an arrow because it will defensively uncurry *)
11431149
let newExternalType =
11441150
Ptyp_constr
1145-
( {loc = pstr_loc; txt = Ldot (Lident "React", "componentLike")},
1146-
[retPropsType; innerType] )
1151+
( {loc = pstr_loc; txt = Ldot (Lident "React", "component")},
1152+
[retPropsType] )
11471153
in
11481154
let newStructure =
11491155
{
@@ -1233,7 +1239,7 @@ let transformSignatureItem ~config item =
12331239
(returnValue, (name, attrs, returnValue.ptyp_loc, type_) :: types)
12341240
| _ -> (fullType, types)
12351241
in
1236-
let innerType, propTypes = getPropTypes [] pval_type in
1242+
let _, propTypes = getPropTypes [] pval_type in
12371243
let namedTypeList = List.fold_left argToConcreteType [] propTypes in
12381244
let retPropsType =
12391245
Typ.constr
@@ -1257,8 +1263,8 @@ let transformSignatureItem ~config item =
12571263
(* can't be an arrow because it will defensively uncurry *)
12581264
let newExternalType =
12591265
Ptyp_constr
1260-
( {loc = psig_loc; txt = Ldot (Lident "React", "componentLike")},
1261-
[retPropsType; innerType] )
1266+
( {loc = psig_loc; txt = Ldot (Lident "React", "component")},
1267+
[retPropsType] )
12621268
in
12631269
let newStructure =
12641270
{
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module SomeComp2 = {
2+
type props = {x: int}
3+
@module("SomeModule")
4+
external make: props => React.element = "SomeComp2"
5+
}
6+
7+
let _ = <SomeComp2 x=42 />
8+
9+
@@jsxConfig({version: 3})
10+
11+
@react.component
12+
let rec make = (~foo, ()) => React.createElement(make, makeProps(~foo, ()))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module SomeComp2 = {
2+
type props = {x: int}
3+
@module("SomeModule")
4+
external make: props => React.element = "SomeComp2"
5+
}
6+
7+
let _ = React.jsx(SomeComp2.make, {x: 42})
8+
9+
@@jsxConfig({version: 3})
10+
@obj external makeProps: (~foo: 'foo, ~key: string=?, unit) => {"foo": 'foo} = ""
11+
12+
let rec make = {
13+
@merlin.focus
14+
let rec \"make$Internal" =
15+
@warning("-16") (~foo, ()) => React.createElement(make, makeProps(~foo, ()))
16+
and make = {
17+
let \"Abstract" = (\"Props": {"foo": 'foo}) => \"make$Internal"(~foo=\"Props"["foo"], ())
18+
\"Abstract"
19+
}
20+
make
21+
}

jscomp/syntax/tests/ppx/react/expected/aliasProps.res.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module C0 = {
1212
React.string(text)
1313
}
1414
let make = {
15-
let \"AliasProps$C0" = (props: props<_>) => make(props)
15+
let \"AliasProps$C0" = React.component((props: props<_>) => make(props))
1616

1717
\"AliasProps$C0"
1818
}
@@ -30,7 +30,7 @@ module C1 = {
3030
React.string(p ++ text)
3131
}
3232
let make = {
33-
let \"AliasProps$C1" = (props: props<_>) => make(props)
33+
let \"AliasProps$C1" = React.component((props: props<_>) => make(props))
3434

3535
\"AliasProps$C1"
3636
}
@@ -48,7 +48,7 @@ module C2 = {
4848
React.string(bar)
4949
}
5050
let make = {
51-
let \"AliasProps$C2" = (props: props<_>) => make(props)
51+
let \"AliasProps$C2" = React.component((props: props<_>) => make(props))
5252

5353
\"AliasProps$C2"
5454
}
@@ -72,7 +72,7 @@ module C3 = {
7272
}
7373
}
7474
let make = {
75-
let \"AliasProps$C3" = (props: props<_>) => make(props)
75+
let \"AliasProps$C3" = React.component((props: props<_>) => make(props))
7676

7777
\"AliasProps$C3"
7878
}
@@ -90,7 +90,7 @@ module C4 = {
9090
ReactDOM.jsx("div", {children: ?ReactDOM.someElement(b)})
9191
}
9292
let make = {
93-
let \"AliasProps$C4" = (props: props<_>) => make(props)
93+
let \"AliasProps$C4" = React.component((props: props<_>) => make(props))
9494

9595
\"AliasProps$C4"
9696
}
@@ -108,7 +108,7 @@ module C5 = {
108108
x + y + z
109109
}
110110
let make = {
111-
let \"AliasProps$C5" = (props: props<_>) => make(props)
111+
let \"AliasProps$C5" = React.component((props: props<_>) => make(props))
112112

113113
\"AliasProps$C5"
114114
}
@@ -118,13 +118,13 @@ module C6 = {
118118
module type Comp = {
119119
type props = {}
120120

121-
let make: React.componentLike<props, React.element>
121+
let make: React.component<props>
122122
}
123123
type props<'comp, 'x> = {comp: 'comp, x: 'x}
124124

125125
let make = ({comp: module(Comp: Comp), x: (a, b), _}: props<_, _>) => React.jsx(Comp.make, {})
126126
let make = {
127-
let \"AliasProps$C6" = (props: props<_>) => make(props)
127+
let \"AliasProps$C6" = React.component((props: props<_>) => make(props))
128128

129129
\"AliasProps$C6"
130130
}

jscomp/syntax/tests/ppx/react/expected/commentAtTop.res.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let make = ({msg, _}: props<_>) => {
44
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})})
55
}
66
let make = {
7-
let \"CommentAtTop" = (props: props<_>) => make(props)
7+
let \"CommentAtTop" = React.component((props: props<_>) => make(props))
88

99
\"CommentAtTop"
1010
}

jscomp/syntax/tests/ppx/react/expected/defaultValueProp.res.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module C0 = {
1313
React.int(a + b)
1414
}
1515
let make = {
16-
let \"DefaultValueProp$C0" = (props: props<_>) => make(props)
16+
let \"DefaultValueProp$C0" = React.component((props: props<_>) => make(props))
1717
\"DefaultValueProp$C0"
1818
}
1919
}
@@ -30,7 +30,7 @@ module C1 = {
3030
React.int(a + b)
3131
}
3232
let make = {
33-
let \"DefaultValueProp$C1" = (props: props<_>) => make(props)
33+
let \"DefaultValueProp$C1" = React.component((props: props<_>) => make(props))
3434

3535
\"DefaultValueProp$C1"
3636
}

jscomp/syntax/tests/ppx/react/expected/externalWithCustomName.res.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Foo = {
1616
type props<'a, 'b> = {a: 'a, b: 'b}
1717

1818
@module("Foo")
19-
external component: React.componentLike<props<int, string>, React.element> = "component"
19+
external component: React.component<props<int, string>> = "component"
2020
}
2121

2222
let t = React.createElement(Foo.component, {a: 1, b: "1"})
@@ -27,7 +27,7 @@ module Foo = {
2727
type props<'a, 'b> = {a: 'a, b: 'b}
2828

2929
@module("Foo")
30-
external component: React.componentLike<props<int, string>, React.element> = "component"
30+
external component: React.component<props<int, string>> = "component"
3131
}
3232

3333
let t = React.jsx(Foo.component, {a: 1, b: "1"})

jscomp/syntax/tests/ppx/react/expected/externalWithRef.res.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ module V4C = {
2424
}
2525

2626
@module("componentForwardRef")
27-
external make: React.componentLike<props<string, ReactDOM.Ref.currentDomRef>, React.element> =
28-
"component"
27+
external make: React.component<props<string, ReactDOM.Ref.currentDomRef>> = "component"
2928
}
3029

3130
@@jsxConfig({version: 4, mode: "automatic"})
@@ -37,6 +36,5 @@ module V4C = {
3736
}
3837

3938
@module("componentForwardRef")
40-
external make: React.componentLike<props<string, ReactDOM.Ref.currentDomRef>, React.element> =
41-
"component"
39+
external make: React.component<props<string, ReactDOM.Ref.currentDomRef>> = "component"
4240
}

jscomp/syntax/tests/ppx/react/expected/externalWithTypeVariables.res.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module V4C = {
2222
}
2323

2424
@module("c")
25-
external make: React.componentLike<props<t<'a>, React.element>, React.element> = "component"
25+
external make: React.component<props<t<'a>, React.element>> = "component"
2626
}
2727

2828
@@jsxConfig({version: 4, mode: "automatic"})
@@ -34,5 +34,5 @@ module V4C = {
3434
}
3535

3636
@module("c")
37-
external make: React.componentLike<props<t<'a>, React.element>, React.element> = "component"
37+
external make: React.component<props<t<'a>, React.element>> = "component"
3838
}

jscomp/syntax/tests/ppx/react/expected/fileLevelConfig.res.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module V4C = {
2424
ReactDOM.createDOMElementVariadic("div", [{msg->React.string}])
2525
}
2626
let make = {
27-
let \"FileLevelConfig$V4C" = (props: props<_>) => make(props)
27+
let \"FileLevelConfig$V4C" = React.component((props: props<_>) => make(props))
2828

2929
\"FileLevelConfig$V4C"
3030
}
@@ -39,7 +39,7 @@ module V4A = {
3939
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({msg->React.string})})
4040
}
4141
let make = {
42-
let \"FileLevelConfig$V4A" = (props: props<_>) => make(props)
42+
let \"FileLevelConfig$V4A" = React.component((props: props<_>) => make(props))
4343

4444
\"FileLevelConfig$V4A"
4545
}

jscomp/syntax/tests/ppx/react/expected/firstClassModules.res.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module Select = {
7777
ReactDOM.createDOMElementVariadic("div", [])
7878
}
7979
let make = {
80-
let \"FirstClassModules$Select" = (props: props<_>) => make(props)
80+
let \"FirstClassModules$Select" = React.component((props: props<_>) => make(props))
8181

8282
\"FirstClassModules$Select"
8383
}
@@ -96,13 +96,12 @@ module External = {
9696
}
9797

9898
@module("c")
99-
external make: React.componentLike<
99+
external make: React.component<
100100
props<
101101
module(T with type t = 'a and type key = 'key),
102102
option<'key>,
103103
(option<'key> => unit),
104104
array<'a>,
105105
>,
106-
React.element,
107106
> = "default"
108107
}

jscomp/syntax/tests/ppx/react/expected/firstClassModules.resi.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ module Select: {
4545
items: 'items,
4646
}
4747

48-
let make: React.componentLike<
48+
let make: React.component<
4949
props<
5050
module(T with type t = 'a and type key = 'key),
5151
option<'key>,
5252
(option<'key> => unit),
5353
array<'a>,
5454
>,
55-
React.element,
5655
>
5756
}

jscomp/syntax/tests/ppx/react/expected/forwardRef.res.txt

+12-8
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module V4C = {
9595
],
9696
)
9797
let make = React.forwardRef({
98-
let \"ForwardRef$V4C$FancyInput" = (props: props<_>, ref) => make(props, ref)
98+
let \"ForwardRef$V4C$FancyInput" = React.component((props: props<_>, ref) => make(props, ref))
9999

100100
\"ForwardRef$V4C$FancyInput"
101101
})
@@ -116,7 +116,7 @@ module V4C = {
116116
)
117117
}
118118
let make = {
119-
let \"ForwardRef$V4C" = props => make(props)
119+
let \"ForwardRef$V4C" = React.component(props => make(props))
120120

121121
\"ForwardRef$V4C"
122122
}
@@ -150,7 +150,9 @@ module V4CUncurried = {
150150
],
151151
)
152152
let make = React.forwardRef({
153-
let \"ForwardRef$V4CUncurried$FancyInput" = (props: props<_>, ref) => make(props, ref)
153+
let \"ForwardRef$V4CUncurried$FancyInput" = React.component((props: props<_>, ref) =>
154+
make(props, ref)
155+
)
154156

155157
\"ForwardRef$V4CUncurried$FancyInput"
156158
})
@@ -171,7 +173,7 @@ module V4CUncurried = {
171173
)
172174
}
173175
let make = {
174-
let \"ForwardRef$V4CUncurried" = props => make(props)
176+
let \"ForwardRef$V4CUncurried" = React.component(props => make(props))
175177

176178
\"ForwardRef$V4CUncurried"
177179
}
@@ -205,7 +207,7 @@ module V4A = {
205207
},
206208
)
207209
let make = React.forwardRef({
208-
let \"ForwardRef$V4A$FancyInput" = (props: props<_>, ref) => make(props, ref)
210+
let \"ForwardRef$V4A$FancyInput" = React.component((props: props<_>, ref) => make(props, ref))
209211

210212
\"ForwardRef$V4A$FancyInput"
211213
})
@@ -225,7 +227,7 @@ module V4A = {
225227
)
226228
}
227229
let make = {
228-
let \"ForwardRef$V4A" = props => make(props)
230+
let \"ForwardRef$V4A" = React.component(props => make(props))
229231

230232
\"ForwardRef$V4A"
231233
}
@@ -257,7 +259,9 @@ module V4AUncurried = {
257259
},
258260
)
259261
let make = React.forwardRef({
260-
let \"ForwardRef$V4AUncurried$FancyInput" = (props: props<_>, ref) => make(props, ref)
262+
let \"ForwardRef$V4AUncurried$FancyInput" = React.component((props: props<_>, ref) =>
263+
make(props, ref)
264+
)
261265

262266
\"ForwardRef$V4AUncurried$FancyInput"
263267
})
@@ -277,7 +281,7 @@ module V4AUncurried = {
277281
)
278282
}
279283
let make = {
280-
let \"ForwardRef$V4AUncurried" = props => make(props)
284+
let \"ForwardRef$V4AUncurried" = React.component(props => make(props))
281285

282286
\"ForwardRef$V4AUncurried"
283287
}

0 commit comments

Comments
 (0)