diff --git a/CHANGELOG.md b/CHANGELOG.md index 99f044fbf6..8cb5b292ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/gentype/TranslateTypeExprFromTypes.ml b/jscomp/gentype/TranslateTypeExprFromTypes.ml index 58db8cfc07..e4edca71e0 100644 --- a/jscomp/gentype/TranslateTypeExprFromTypes.ml +++ b/jscomp/gentype/TranslateTypeExprFromTypes.ml @@ -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 } @@ -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 ] ) -> diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index 262d65d69b..860ebedd7f 100644 --- a/jscomp/gentype_tests/typescript-react-example/package-lock.json +++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json @@ -8,11 +8,11 @@ "name": "typescript-react-example", "version": "0.1.0", "dependencies": { - "react": "^16.13.1", - "react-dom": "^16.13.1" + "@rescript/react": "^0.11.0", + "react": "^18.2.0", + "react-dom": "^18.2.0" }, "devDependencies": { - "@rescript/react": "^0.10.3", "@types/node": "^13.13.4", "@types/react-dom": "^16.9.7", "rescript": "file:../../..", @@ -21,7 +21,7 @@ }, "../../..": { "name": "rescript", - "version": "10.1.1", + "version": "10.1.3", "dev": true, "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", @@ -38,13 +38,12 @@ } }, "node_modules/@rescript/react": { - "version": "0.10.3", - "resolved": "https://registry.npmjs.org/@rescript/react/-/react-0.10.3.tgz", - "integrity": "sha512-Lf9rzrR3bQPKJjOK3PBRa/B3xrJ7CqQ1HYr9VHPVxJidarIJJFZBhj0Dg1uZURX+Wg/xiP0PHFxXmdj2bK8Vxw==", - "dev": true, + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@rescript/react/-/react-0.11.0.tgz", + "integrity": "sha512-RzoAO+3cJwXE2D7yodMo4tBO2EkeDYCN/I/Sj/yRweI3S1CY1ZBOF/GMcVtjeIurJJt7KMveqQXTaRrqoGZBBg==", "peerDependencies": { - "react": ">=16.8.1", - "react-dom": ">=16.8.1" + "react": ">=18.0.0", + "react-dom": ">=18.0.0" } }, "node_modules/@types/node": { @@ -107,67 +106,39 @@ "loose-envify": "cli.js" } }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/prop-types": { - "version": "15.8.1", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", - "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", - "dependencies": { - "loose-envify": "^1.4.0", - "object-assign": "^4.1.1", - "react-is": "^16.13.1" - } - }, "node_modules/react": { - "version": "16.14.0", - "resolved": "https://registry.npmjs.org/react/-/react-16.14.0.tgz", - "integrity": "sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==", + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", "dependencies": { - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2" + "loose-envify": "^1.1.0" }, "engines": { "node": ">=0.10.0" } }, "node_modules/react-dom": { - "version": "16.14.0", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.14.0.tgz", - "integrity": "sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==", + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", "dependencies": { "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2", - "scheduler": "^0.19.1" + "scheduler": "^0.23.0" }, "peerDependencies": { - "react": "^16.14.0" + "react": "^18.2.0" } }, - "node_modules/react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" - }, "node_modules/rescript": { "resolved": "../../..", "link": true }, "node_modules/scheduler": { - "version": "0.19.1", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", - "integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", "dependencies": { - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1" + "loose-envify": "^1.1.0" } }, "node_modules/typescript": { @@ -186,10 +157,9 @@ }, "dependencies": { "@rescript/react": { - "version": "0.10.3", - "resolved": "https://registry.npmjs.org/@rescript/react/-/react-0.10.3.tgz", - "integrity": "sha512-Lf9rzrR3bQPKJjOK3PBRa/B3xrJ7CqQ1HYr9VHPVxJidarIJJFZBhj0Dg1uZURX+Wg/xiP0PHFxXmdj2bK8Vxw==", - "dev": true, + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@rescript/react/-/react-0.11.0.tgz", + "integrity": "sha512-RzoAO+3cJwXE2D7yodMo4tBO2EkeDYCN/I/Sj/yRweI3S1CY1ZBOF/GMcVtjeIurJJt7KMveqQXTaRrqoGZBBg==", "requires": {} }, "@types/node": { @@ -249,47 +219,23 @@ "js-tokens": "^3.0.0 || ^4.0.0" } }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==" - }, - "prop-types": { - "version": "15.8.1", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", - "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", - "requires": { - "loose-envify": "^1.4.0", - "object-assign": "^4.1.1", - "react-is": "^16.13.1" - } - }, "react": { - "version": "16.14.0", - "resolved": "https://registry.npmjs.org/react/-/react-16.14.0.tgz", - "integrity": "sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==", + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", "requires": { - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2" + "loose-envify": "^1.1.0" } }, "react-dom": { - "version": "16.14.0", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.14.0.tgz", - "integrity": "sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==", + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", "requires": { "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2", - "scheduler": "^0.19.1" + "scheduler": "^0.23.0" } }, - "react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" - }, "rescript": { "version": "file:../../..", "requires": { @@ -299,12 +245,11 @@ } }, "scheduler": { - "version": "0.19.1", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", - "integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", "requires": { - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1" + "loose-envify": "^1.1.0" } }, "typescript": { diff --git a/jscomp/gentype_tests/typescript-react-example/package.json b/jscomp/gentype_tests/typescript-react-example/package.json index 95f63a0fdb..66eda0fc26 100644 --- a/jscomp/gentype_tests/typescript-react-example/package.json +++ b/jscomp/gentype_tests/typescript-react-example/package.json @@ -2,10 +2,6 @@ "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", @@ -13,10 +9,14 @@ "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" } } diff --git a/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.bs.js b/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.bs.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.bs.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.gen.tsx new file mode 100644 index 0000000000..9fdfc8bebd --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.gen.tsx @@ -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; diff --git a/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.res b/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.res new file mode 100644 index 0000000000..74ebf6164a --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.res @@ -0,0 +1,4 @@ +open ReactV3 + +@genType +type cb = React.callback diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index e61cf67911..1fb2875c3d 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -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 } @@ -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 ] ) ->