Skip to content

Commit d87fb77

Browse files
committed
GenType: fix issue with V3 compatibility mode
This is a porting of #5991 to compiler v10.1
1 parent 709ead4 commit d87fb77

File tree

8 files changed

+65
-101
lines changed

8 files changed

+65
-101
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Fix issue with printing async functions with locally abstract types https://github.com/rescript-lang/syntax/pull/732
2424
- Fix issue with async context and locally abstract types https://github.com/rescript-lang/rescript-compiler/pull/5985
2525
- Fix support for recursive components in JSX V4 https://github.com/rescript-lang/syntax/pull/733
26+
- 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/5992
2627

2728
# 10.1.2
2829

jscomp/gentype/TranslateTypeExprFromTypes.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
6767
type_ = Ident { builtin = false; name = dep |> depToString; typeArgs };
6868
}
6969
in
70-
match (path |> pathToList |> List.rev, paramsTranslation) with
70+
let patchReactV3 path =
71+
match path with "ReactV3" :: rest -> rest | _ -> path
72+
in
73+
match (path |> pathToList |> List.rev |> patchReactV3, paramsTranslation) with
7174
| ([ "FB"; "bool" ] | [ "bool" ]), [] ->
7275
{ dependencies = []; type_ = booleanT }
7376
| ([ "FB"; "int" ] | [ "int" ]), [] -> { dependencies = []; type_ = numberT }
@@ -203,7 +206,7 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
203206
| [ "Js"; "null_undefined" ] ),
204207
[ paramTranslation ] ) ->
205208
{ paramTranslation with type_ = Nullable paramTranslation.type_ }
206-
| ([ "Js"; "Promise"; "t" ] | ["promise"]), [ paramTranslation ] ->
209+
| ([ "Js"; "Promise"; "t" ] | [ "promise" ]), [ paramTranslation ] ->
207210
{ paramTranslation with type_ = Promise paramTranslation.type_ }
208211
| ( [ "Js"; "Internal"; "fn" ],
209212
[ { dependencies = argsDependencies; type_ = Tuple ts }; ret ] ) ->

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

+37-92
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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
"name": "typescript-react-example",
33
"version": "0.1.0",
44
"private": true,
5-
"dependencies": {
6-
"react": "^16.13.1",
7-
"react-dom": "^16.13.1"
8-
},
95
"scripts": {
106
"start": "rescript build -w",
117
"build": "rescript",
128
"clean": "rescript clean -with-deps",
139
"tsc": "tsc -p tsconfig.json"
1410
},
1511
"devDependencies": {
16-
"@rescript/react": "^0.10.3",
1712
"@types/node": "^13.13.4",
1813
"@types/react-dom": "^16.9.7",
1914
"rescript": "file:../../..",
2015
"typescript": "3.9.2"
16+
},
17+
"dependencies": {
18+
"@rescript/react": "^0.11.0",
19+
"react": "^18.2.0",
20+
"react-dom": "^18.2.0"
2121
}
2222
}

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>

lib/4.06.1/whole_compiler.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -242402,7 +242402,10 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
242402242402
type_ = Ident { builtin = false; name = dep |> depToString; typeArgs };
242403242403
}
242404242404
in
242405-
match (path |> pathToList |> List.rev, paramsTranslation) with
242405+
let patchReactV3 path =
242406+
match path with "ReactV3" :: rest -> rest | _ -> path
242407+
in
242408+
match (path |> pathToList |> List.rev |> patchReactV3, paramsTranslation) with
242406242409
| ([ "FB"; "bool" ] | [ "bool" ]), [] ->
242407242410
{ dependencies = []; type_ = booleanT }
242408242411
| ([ "FB"; "int" ] | [ "int" ]), [] -> { dependencies = []; type_ = numberT }
@@ -242538,7 +242541,7 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
242538242541
| [ "Js"; "null_undefined" ] ),
242539242542
[ paramTranslation ] ) ->
242540242543
{ paramTranslation with type_ = Nullable paramTranslation.type_ }
242541-
| ([ "Js"; "Promise"; "t" ] | ["promise"]), [ paramTranslation ] ->
242544+
| ([ "Js"; "Promise"; "t" ] | [ "promise" ]), [ paramTranslation ] ->
242542242545
{ paramTranslation with type_ = Promise paramTranslation.type_ }
242543242546
| ( [ "Js"; "Internal"; "fn" ],
242544242547
[ { dependencies = argsDependencies; type_ = Tuple ts }; ret ] ) ->

0 commit comments

Comments
 (0)