From 3877a2b26e6c549b1ebc7846fdd59331df820d8a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 8 Feb 2023 15:12:55 +0100 Subject: [PATCH] GenType: fix issue with V3 compatibility mode Fixes https://github.com/rescript-lang/rescript-compiler/issues/5990 --- CHANGELOG.md | 1 + jscomp/gentype/TranslateTypeExprFromTypes.ml | 23 ++- .../package-lock.json | 131 +++++------------- .../typescript-react-example/package.json | 6 +- .../src/V3Compatibility.bs.js | 2 + .../src/V3Compatibility.gen.tsx | 6 + .../src/V3Compatibility.res | 4 + 7 files changed, 71 insertions(+), 102 deletions(-) create mode 100644 jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.bs.js create mode 100644 jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.gen.tsx create mode 100644 jscomp/gentype_tests/typescript-react-example/src/V3Compatibility.res diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f7f931304..b51a972112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ These are only breaking changes for unformatted code. - Fix support for recursive components in JSX V4 https://github.com/rescript-lang/rescript-compiler/pull/5986 - Fix issue with overlapping labelled argument with default value https://github.com/rescript-lang/rescript-compiler/pull/5989 - Fix issue with using alias and default value together https://github.com/rescript-lang/rescript-compiler/pull/5989 +- 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 #### :nail_care: Polish diff --git a/jscomp/gentype/TranslateTypeExprFromTypes.ml b/jscomp/gentype/TranslateTypeExprFromTypes.ml index 063d16ee09..573c5ed996 100644 --- a/jscomp/gentype/TranslateTypeExprFromTypes.ml +++ b/jscomp/gentype/TranslateTypeExprFromTypes.ml @@ -127,7 +127,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = paramTranslation1.dependencies @ paramTranslation2.dependencies; type_ = variant; } - | ["React"; "callback"], [fromTranslation; toTranslation] -> + | ( (["React"; "callback"] | ["ReactV3"; "React"; "callback"]), + [fromTranslation; toTranslation] ) -> { dependencies = fromTranslation.dependencies @ toTranslation.dependencies; type_ = @@ -140,7 +141,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = uncurried = false; }; } - | ["React"; "componentLike"], [propsTranslation; retTranslation] -> + | ( (["React"; "componentLike"] | ["ReactV3"; "React"; "componentLike"]), + [propsTranslation; retTranslation] ) -> { dependencies = propsTranslation.dependencies @ retTranslation.dependencies; type_ = @@ -153,7 +155,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = uncurried = false; }; } - | ["React"; "component"], [propsTranslation] -> + | ( (["React"; "component"] | ["ReactV3"; "React"; "component"]), + [propsTranslation] ) -> { dependencies = propsTranslation.dependencies; type_ = @@ -166,12 +169,17 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = uncurried = false; }; } - | ["React"; "Context"; "t"], [paramTranslation] -> + | ( (["React"; "Context"; "t"] | ["ReactV3"; "React"; "Context"; "t"]), + [paramTranslation] ) -> { dependencies = paramTranslation.dependencies; type_ = EmitType.typeReactContext ~type_:paramTranslation.type_; } - | (["React"; "Ref"; "t"] | ["React"; "ref"]), [paramTranslation] -> + | ( ( ["React"; "Ref"; "t"] + | ["React"; "ref"] + | ["ReactV3"; "React"; "Ref"; "t"] + | ["ReactV3"; "React"; "ref"] ), + [paramTranslation] ) -> { dependencies = paramTranslation.dependencies; type_ = EmitType.typeReactRef ~type_:paramTranslation.type_; @@ -186,7 +194,10 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = {dependencies = []; type_ = EmitType.typeAny} | ["ReactEvent"; "Mouse"; "t"], [] -> {dependencies = []; type_ = EmitType.typeReactEventMouseT} - | (["React"; "element"] | ["ReasonReact"; "reactElement"]), [] -> + | ( ( ["React"; "element"] + | ["ReactV3"; "React"; "element"] + | ["ReasonReact"; "reactElement"] ), + [] ) -> {dependencies = []; type_ = EmitType.typeReactElement} | (["FB"; "option"] | ["option"]), [paramTranslation] -> {paramTranslation with type_ = Option paramTranslation.type_} diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index 32e24bbf6e..e0b4f81ee2 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:../../..", @@ -31,20 +31,19 @@ "rescript": "rescript" }, "devDependencies": { - "mocha": "^7.2.0", + "mocha": "^10.1.0", "nyc": "^15.0.0", "prettier": "^2.7.1", "rollup": "^0.49.2" } }, "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,63 +219,38 @@ "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": { - "mocha": "^7.2.0", + "mocha": "^10.1.0", "nyc": "^15.0.0", "prettier": "^2.7.1", "rollup": "^0.49.2" } }, "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..a494cc27a5 100644 --- a/jscomp/gentype_tests/typescript-react-example/package.json +++ b/jscomp/gentype_tests/typescript-react-example/package.json @@ -3,8 +3,9 @@ "version": "0.1.0", "private": true, "dependencies": { - "react": "^16.13.1", - "react-dom": "^16.13.1" + "@rescript/react": "^0.11.0", + "react": "^18.2.0", + "react-dom": "^18.2.0" }, "scripts": { "start": "rescript build -w", @@ -13,7 +14,6 @@ "tsc": "tsc -p tsconfig.json" }, "devDependencies": { - "@rescript/react": "^0.10.3", "@types/node": "^13.13.4", "@types/react-dom": "^16.9.7", "rescript": "file:../../..", 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