Skip to content

Commit a0f2fff

Browse files
committed
GenType: fix issue with V3 compatibility mode
Fixes #5990
1 parent beebcff commit a0f2fff

File tree

7 files changed

+71
-102
lines changed

7 files changed

+71
-102
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ These are only breaking changes for unformatted code.
5858
- Fix issue with nested async functions, where the inner function would be emitted without `async` https://github.com/rescript-lang/rescript-compiler/pull/5983
5959
- Fix issue with async context check, and printer, for async functions with locally abstract type https://github.com/rescript-lang/rescript-compiler/pull/5982
6060
- Fix support for recursive components in JSX V4 https://github.com/rescript-lang/rescript-compiler/pull/5986
61+
- GenType: fix issue with V3 compatibility mode (see https://github.com/rescript-lang/rescript-compiler/issues/5990) https://github.com/rescript-lang/rescript-compiler/pull/5991
6162

6263
#### :nail_care: Polish
6364

jscomp/gentype/TranslateTypeExprFromTypes.ml

+17-6
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
127127
paramTranslation1.dependencies @ paramTranslation2.dependencies;
128128
type_ = variant;
129129
}
130-
| ["React"; "callback"], [fromTranslation; toTranslation] ->
130+
| ( (["React"; "callback"] | ["ReactV3"; "React"; "callback"]),
131+
[fromTranslation; toTranslation] ) ->
131132
{
132133
dependencies = fromTranslation.dependencies @ toTranslation.dependencies;
133134
type_ =
@@ -140,7 +141,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
140141
uncurried = false;
141142
};
142143
}
143-
| ["React"; "componentLike"], [propsTranslation; retTranslation] ->
144+
| ( (["React"; "componentLike"] | ["ReactV3"; "React"; "componentLike"]),
145+
[propsTranslation; retTranslation] ) ->
144146
{
145147
dependencies = propsTranslation.dependencies @ retTranslation.dependencies;
146148
type_ =
@@ -153,7 +155,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
153155
uncurried = false;
154156
};
155157
}
156-
| ["React"; "component"], [propsTranslation] ->
158+
| ( (["React"; "component"] | ["ReactV3"; "React"; "component"]),
159+
[propsTranslation] ) ->
157160
{
158161
dependencies = propsTranslation.dependencies;
159162
type_ =
@@ -166,12 +169,17 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
166169
uncurried = false;
167170
};
168171
}
169-
| ["React"; "Context"; "t"], [paramTranslation] ->
172+
| ( (["React"; "Context"; "t"] | ["ReactV3"; "React"; "Context"; "t"]),
173+
[paramTranslation] ) ->
170174
{
171175
dependencies = paramTranslation.dependencies;
172176
type_ = EmitType.typeReactContext ~type_:paramTranslation.type_;
173177
}
174-
| (["React"; "Ref"; "t"] | ["React"; "ref"]), [paramTranslation] ->
178+
| ( ( ["React"; "Ref"; "t"]
179+
| ["React"; "ref"]
180+
| ["ReactV3"; "React"; "Ref"; "t"]
181+
| ["ReactV3"; "React"; "ref"] ),
182+
[paramTranslation] ) ->
175183
{
176184
dependencies = paramTranslation.dependencies;
177185
type_ = EmitType.typeReactRef ~type_:paramTranslation.type_;
@@ -186,7 +194,10 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
186194
{dependencies = []; type_ = EmitType.typeAny}
187195
| ["ReactEvent"; "Mouse"; "t"], [] ->
188196
{dependencies = []; type_ = EmitType.typeReactEventMouseT}
189-
| (["React"; "element"] | ["ReasonReact"; "reactElement"]), [] ->
197+
| ( ( ["React"; "element"]
198+
| ["ReactV3"; "React"; "element"]
199+
| ["ReasonReact"; "reactElement"] ),
200+
[] ) ->
190201
{dependencies = []; type_ = EmitType.typeReactElement}
191202
| (["FB"; "option"] | ["option"]), [paramTranslation] ->
192203
{paramTranslation with type_ = Option paramTranslation.type_}

jscomp/gentype_tests/typescript-react-example/package-lock.json

+38-93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"react": "^16.13.1",
7-
"react-dom": "^16.13.1"
6+
"@rescript/react": "^0.11.0",
7+
"react": "^18.2.0",
8+
"react-dom": "^18.2.0"
89
},
910
"scripts": {
1011
"start": "rescript build -w",
@@ -13,7 +14,6 @@
1314
"tsc": "tsc -p tsconfig.json"
1415
},
1516
"devDependencies": {
16-
"@rescript/react": "^0.10.3",
1717
"@types/node": "^13.13.4",
1818
"@types/react-dom": "^16.9.7",
1919
"rescript": "file:../../..",

jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.bs.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* TypeScript file generated from V3Compatibility.res by genType. */
2+
/* eslint-disable import/first */
3+
4+
5+
// tslint:disable-next-line:interface-over-type-literal
6+
export type cb = (_1:number) => string;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
open ReactV3
2+
3+
@genType
4+
type cb = React.callback<int, string>

0 commit comments

Comments
 (0)