Skip to content

GenType: fix issue with V3 compatibility mode #5992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Fix issue with printing async functions with locally abstract types https://github.com/rescript-lang/syntax/pull/732
- Fix issue with async context and locally abstract types https://github.com/rescript-lang/rescript-compiler/pull/5985
- Fix support for recursive components in JSX V4 https://github.com/rescript-lang/syntax/pull/733
- 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

# 10.1.2

Expand Down
7 changes: 5 additions & 2 deletions jscomp/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
type_ = Ident { builtin = false; name = dep |> depToString; typeArgs };
}
in
match (path |> pathToList |> List.rev, paramsTranslation) with
let patchReactV3 path =
match path with "ReactV3" :: rest -> rest | _ -> path
in
match (path |> pathToList |> List.rev |> patchReactV3, paramsTranslation) with
| ([ "FB"; "bool" ] | [ "bool" ]), [] ->
{ dependencies = []; type_ = booleanT }
| ([ "FB"; "int" ] | [ "int" ]), [] -> { dependencies = []; type_ = numberT }
Expand Down Expand Up @@ -203,7 +206,7 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
| [ "Js"; "null_undefined" ] ),
[ paramTranslation ] ) ->
{ paramTranslation with type_ = Nullable paramTranslation.type_ }
| ([ "Js"; "Promise"; "t" ] | ["promise"]), [ paramTranslation ] ->
| ([ "Js"; "Promise"; "t" ] | [ "promise" ]), [ paramTranslation ] ->
{ paramTranslation with type_ = Promise paramTranslation.type_ }
| ( [ "Js"; "Internal"; "fn" ],
[ { dependencies = argsDependencies; type_ = Tuple ts }; ret ] ) ->
Expand Down
129 changes: 37 additions & 92 deletions jscomp/gentype_tests/typescript-react-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions jscomp/gentype_tests/typescript-react-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
"name": "typescript-react-example",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"scripts": {
"start": "rescript build -w",
"build": "rescript",
"clean": "rescript clean -with-deps",
"tsc": "tsc -p tsconfig.json"
},
"devDependencies": {
"@rescript/react": "^0.10.3",
"@types/node": "^13.13.4",
"@types/react-dom": "^16.9.7",
"rescript": "file:../../..",
"typescript": "3.9.2"
},
"dependencies": {
"@rescript/react": "^0.11.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* TypeScript file generated from V3Compatibility.res by genType. */
/* eslint-disable import/first */


// tslint:disable-next-line:interface-over-type-literal
export type cb = (_1:number) => string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
open ReactV3

@genType
type cb = React.callback<int, string>
7 changes: 5 additions & 2 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -242402,7 +242402,10 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
type_ = Ident { builtin = false; name = dep |> depToString; typeArgs };
}
in
match (path |> pathToList |> List.rev, paramsTranslation) with
let patchReactV3 path =
match path with "ReactV3" :: rest -> rest | _ -> path
in
match (path |> pathToList |> List.rev |> patchReactV3, paramsTranslation) with
| ([ "FB"; "bool" ] | [ "bool" ]), [] ->
{ dependencies = []; type_ = booleanT }
| ([ "FB"; "int" ] | [ "int" ]), [] -> { dependencies = []; type_ = numberT }
Expand Down Expand Up @@ -242538,7 +242541,7 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
| [ "Js"; "null_undefined" ] ),
[ paramTranslation ] ) ->
{ paramTranslation with type_ = Nullable paramTranslation.type_ }
| ([ "Js"; "Promise"; "t" ] | ["promise"]), [ paramTranslation ] ->
| ([ "Js"; "Promise"; "t" ] | [ "promise" ]), [ paramTranslation ] ->
{ paramTranslation with type_ = Promise paramTranslation.type_ }
| ( [ "Js"; "Internal"; "fn" ],
[ { dependencies = argsDependencies; type_ = Tuple ts }; ret ] ) ->
Expand Down