From 9ed21d9d5bfc79aca61b1979fe3d4bdbd0b93d8e Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 27 May 2022 07:08:56 +0200 Subject: [PATCH] Update flow examples to RescriptReact. --- examples/flow-react-example/bsconfig.json | 7 +- examples/flow-react-example/package-lock.json | 18 +++ examples/flow-react-example/package.json | 1 + .../flow-react-example/src/AutoAnnotate.bs.js | 28 +---- .../src/AutoAnnotate.gen.js | 24 ---- .../flow-react-example/src/AutoAnnotate.res | 9 -- .../flow-react-example/src/Component2.res | 4 +- examples/flow-react-example/src/Hooks.gen.js | 2 + examples/flow-react-example/src/Hooks.res | 10 +- examples/flow-react-example/src/Index.bs.js | 4 +- examples/flow-react-example/src/Index.res | 3 +- .../src/components/Navigator.bs.js | 35 ++---- .../src/components/Navigator.gen.js | 20 +-- .../src/components/Navigator.res | 16 +-- .../src/components/RenameProps.bs.js | 32 ++--- .../src/components/RenameProps.gen.js | 29 ++--- .../src/components/RenameProps.res | 10 +- .../src/shims/ReactShim.shim.js | 31 ----- .../typescript-react-example/bsconfig.json | 1 - .../src/shims/ReactShim.shim.ts | 28 ----- src/EmitType.ml | 2 +- src/EmitType.mli | 114 ------------------ src/TranslateTypeExprFromTypes.ml | 6 +- 23 files changed, 77 insertions(+), 357 deletions(-) delete mode 100644 examples/flow-react-example/src/shims/ReactShim.shim.js delete mode 100644 examples/typescript-react-example/src/shims/ReactShim.shim.ts delete mode 100644 src/EmitType.mli diff --git a/examples/flow-react-example/bsconfig.json b/examples/flow-react-example/bsconfig.json index 86093c015..9d0737509 100644 --- a/examples/flow-react-example/bsconfig.json +++ b/examples/flow-react-example/bsconfig.json @@ -3,14 +3,11 @@ "language": "flow", "module": "es6", "importPath": "relative", - "reasonReactPath": "reason-react/src/ReasonReact.js", "shims": { "Js": "Js", "Obj": "Obj", - "React": "ReactShim", "ReactEvent": "ReactEvent", - "RescriptPervasives": "RescriptPervasives", - "ReasonReact": "ReactShim" + "RescriptPervasives": "RescriptPervasives" }, "debug": { "all": false @@ -21,7 +18,7 @@ "name": "flow-react-example", "bsc-flags": ["-bs-super-errors"], "reason": { "react-jsx": 3 }, - "bs-dependencies": ["reason-react"], + "bs-dependencies": ["@rescript/react"], "sources": [ { "dir": "src", diff --git a/examples/flow-react-example/package-lock.json b/examples/flow-react-example/package-lock.json index fc35e6734..a2b29ba7e 100644 --- a/examples/flow-react-example/package-lock.json +++ b/examples/flow-react-example/package-lock.json @@ -19,6 +19,7 @@ "@babel/preset-env": "^7.11.5", "@babel/preset-flow": "^7.10.4", "@babel/preset-react": "^7.10.4", + "@rescript/react": "^0.10.3", "babel-loader": "^8.1.0", "concurrently": "^3.5.0", "rescript": "9.1.1", @@ -1415,6 +1416,16 @@ "node": ">=10.0.0" } }, + "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, + "peerDependencies": { + "react": ">=16.8.1", + "react-dom": ">=16.8.1" + } + }, "node_modules/@types/eslint": { "version": "7.28.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.28.2.tgz", @@ -5086,6 +5097,13 @@ "integrity": "sha512-6nFkfkmSeV/rqSaS4oWHgmpnYw194f6hmWF5is6b0J1naJZoiD0NTc9AiUwPHvWsowkjuHErCZT1wa0jg+BLIA==", "dev": true }, + "@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, + "requires": {} + }, "@types/eslint": { "version": "7.28.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.28.2.tgz", diff --git a/examples/flow-react-example/package.json b/examples/flow-react-example/package.json index d27d3f1a4..305e3f2fd 100644 --- a/examples/flow-react-example/package.json +++ b/examples/flow-react-example/package.json @@ -27,6 +27,7 @@ "@babel/preset-env": "^7.11.5", "@babel/preset-flow": "^7.10.4", "@babel/preset-react": "^7.10.4", + "@rescript/react": "^0.10.3", "babel-loader": "^8.1.0", "concurrently": "^3.5.0", "rescript": "9.1.1", diff --git a/examples/flow-react-example/src/AutoAnnotate.bs.js b/examples/flow-react-example/src/AutoAnnotate.bs.js index 8f778a23a..11f7d4db8 100644 --- a/examples/flow-react-example/src/AutoAnnotate.bs.js +++ b/examples/flow-react-example/src/AutoAnnotate.bs.js @@ -1,38 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as ReasonReact from "reason-react/src/legacy/ReasonReact.bs.js"; function useR5(x) { return x; } -var component = ReasonReact.statelessComponent("AutoAnnotate"); - -function make(param, _children) { - return { - debugName: component.debugName, - reactClassInternal: component.reactClassInternal, - handedOffState: component.handedOffState, - willReceiveProps: component.willReceiveProps, - didMount: component.didMount, - didUpdate: component.didUpdate, - willUnmount: component.willUnmount, - willUpdate: component.willUpdate, - shouldUpdate: component.shouldUpdate, - render: (function (param) { - return null; - }), - initialState: component.initialState, - retainedProps: component.retainedProps, - reducer: component.reducer, - jsElementWrapped: component.jsElementWrapped - }; -} - export { useR5 , - component , - make , } -/* component Not a pure module */ +/* No side effect */ diff --git a/examples/flow-react-example/src/AutoAnnotate.gen.js b/examples/flow-react-example/src/AutoAnnotate.gen.js index 85e37fe96..c1b30d733 100644 --- a/examples/flow-react-example/src/AutoAnnotate.gen.js +++ b/examples/flow-react-example/src/AutoAnnotate.gen.js @@ -4,27 +4,10 @@ * @nolint */ /* eslint-disable */ -// $FlowExpectedError[unclear-type]: Reason checked type sufficiently -type $any = any; - -// $FlowExpectedError[untyped-import]: Reason checked type sufficiently -import * as Curry from 'rescript/lib/es6/curry.js'; // $FlowExpectedError[untyped-import]: Reason checked type sufficiently import * as AutoAnnotateBS from './AutoAnnotate.bs'; -// flowlint-next-line nonstrict-import:off -import type {actionless as ReasonReact_actionless} from '../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {componentSpec as ReasonReact_componentSpec} from '../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {noRetainedProps as ReasonReact_noRetainedProps} from '../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {stateless as ReasonReact_stateless} from '../src/shims/ReactShim.shim'; - export type variant = {| tag: "R", value: number |}; export type record = {| +variant: variant |}; @@ -41,11 +24,4 @@ export type annotatedVariant = export type r5 = {| +r5: number |}; -export type r6 = {| +r6: number |}; - export const useR5: (r5) => r5 = AutoAnnotateBS.useR5; - -export const make: ({| +r6: r6 |}, T1) => ReasonReact_componentSpec = function (Arg1: $any, Arg2: $any) { - const result = Curry._2(AutoAnnotateBS.make, Arg1.r6, Arg2); - return result -}; diff --git a/examples/flow-react-example/src/AutoAnnotate.res b/examples/flow-react-example/src/AutoAnnotate.res index eb17e4533..2977b51cf 100644 --- a/examples/flow-react-example/src/AutoAnnotate.res +++ b/examples/flow-react-example/src/AutoAnnotate.res @@ -20,12 +20,3 @@ type r5 = {r5: int} let useR5 = (x: r5) => x type r6 = {r6: int} - -let component = ReasonReact.statelessComponent(__MODULE__) - -@genType -let make = (~r6 as _: r6, _children) => { - ...component, - render: _ => ReasonReact.null, -} - diff --git a/examples/flow-react-example/src/Component2.res b/examples/flow-react-example/src/Component2.res index 212ecf64d..e7057edc6 100644 --- a/examples/flow-react-example/src/Component2.res +++ b/examples/flow-react-example/src/Component2.res @@ -14,8 +14,8 @@ type action = let make = (~greeting) => { let message = "You've clicked this " ++ ("xx" ++ " times(s)")
- - + + {React.string(greeting)}
} diff --git a/examples/flow-react-example/src/Hooks.gen.js b/examples/flow-react-example/src/Hooks.gen.js index 0199a3bc0..3d17cb4b8 100644 --- a/examples/flow-react-example/src/Hooks.gen.js +++ b/examples/flow-react-example/src/Hooks.gen.js @@ -30,6 +30,8 @@ export type testReactRef = { current: (null | number), ... }; export type testDomRef = React$Ref; +export type testDOMReft = React$Ref; + export type notAFunctionComponent = ({ current: (null | number), ... }) => React$Node; export type Props = {| +vehicle: vehicle |}; diff --git a/examples/flow-react-example/src/Hooks.res b/examples/flow-react-example/src/Hooks.res index 5c46d7792..d4905857a 100644 --- a/examples/flow-react-example/src/Hooks.res +++ b/examples/flow-react-example/src/Hooks.res @@ -49,7 +49,7 @@ module Inner = { module NoProps = { @genType @react.component - let make = () =>
ReasonReact.null
+ let make = () =>
React.null
} type cb = (~_to: vehicle) => unit @@ -71,7 +71,7 @@ let makeWithRef = (~vehicle) => { let _ = 42 ref => switch ref->Js.Nullable.toOption { - | Some(ref) => + | Some(ref) => | None => React.null } } @@ -94,7 +94,10 @@ type testReactContext = React.Context.t type testReactRef = React.ref @genType -type testDomRef = ReactDOMRe.domRef +type testDomRef = ReactDOM.domRef + +@genType +type testDOMReft = ReactDOM.Ref.t @genType @react.component let polymorphicComponent = (~p as (x, _)) => React.string(x.name) @@ -116,4 +119,3 @@ let aComponentWithChildren = (~vehicle, ~children) => @genType type notAFunctionComponent = React.ref => React.element - diff --git a/examples/flow-react-example/src/Index.bs.js b/examples/flow-react-example/src/Index.bs.js index a5f86ab38..ebced250f 100644 --- a/examples/flow-react-example/src/Index.bs.js +++ b/examples/flow-react-example/src/Index.bs.js @@ -1,10 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as React from "react"; +import * as ReactDom from "react-dom"; import * as Component2 from "./Component2.bs.js"; -import * as ReactDOMRe from "reason-react/src/legacy/ReactDOMRe.bs.js"; -ReactDOMRe.renderToElementWithId(React.createElement(Component2.make, { +ReactDom.render(React.createElement(Component2.make, { greeting: "Hello!" }), "index2"); diff --git a/examples/flow-react-example/src/Index.res b/examples/flow-react-example/src/Index.res index 8b96fb3d2..babb31d8e 100644 --- a/examples/flow-react-example/src/Index.res +++ b/examples/flow-react-example/src/Index.res @@ -1,2 +1 @@ -ReactDOMRe.renderToElementWithId(, "index2") - +ReactDOM.render(, "index2"->Obj.magic) diff --git a/examples/flow-react-example/src/components/Navigator.bs.js b/examples/flow-react-example/src/components/Navigator.bs.js index 5aea3aa73..2d805139f 100644 --- a/examples/flow-react-example/src/components/Navigator.bs.js +++ b/examples/flow-react-example/src/components/Navigator.bs.js @@ -1,36 +1,19 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as React from "react"; -import * as ReasonReact from "reason-react/src/legacy/ReasonReact.bs.js"; -var component = ReasonReact.statelessComponent("Navigator"); - -function make(history, match_, _children) { - return { - debugName: component.debugName, - reactClassInternal: component.reactClassInternal, - handedOffState: component.handedOffState, - willReceiveProps: component.willReceiveProps, - didMount: component.didMount, - didUpdate: component.didUpdate, - willUnmount: component.willUnmount, - willUpdate: component.willUpdate, - shouldUpdate: component.shouldUpdate, - render: (function (_self) { - console.log("history", history); - console.log("match", match_); - return React.createElement("div", undefined); - }), - initialState: component.initialState, - retainedProps: component.retainedProps, - reducer: component.reducer, - jsElementWrapped: component.jsElementWrapped - }; +function $$Navigator(Props) { + var history = Props.history; + var match_ = Props.match; + console.log("history", history); + console.log("match", match_); + return React.createElement("div", undefined); } +var make = $$Navigator; + export { - component , make , } -/* component Not a pure module */ +/* react Not a pure module */ diff --git a/examples/flow-react-example/src/components/Navigator.gen.js b/examples/flow-react-example/src/components/Navigator.gen.js index 73eb03d5f..ac4240a85 100644 --- a/examples/flow-react-example/src/components/Navigator.gen.js +++ b/examples/flow-react-example/src/components/Navigator.gen.js @@ -7,25 +7,9 @@ // $FlowExpectedError[unclear-type]: Reason checked type sufficiently type $any = any; -// $FlowExpectedError[untyped-import]: Reason checked type sufficiently -import * as Curry from 'rescript/lib/es6/curry.js'; - // $FlowExpectedError[untyped-import]: Reason checked type sufficiently import * as NavigatorBS from './Navigator.bs'; -// flowlint-next-line nonstrict-import:off -import type {actionless as ReasonReact_actionless} from '../../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {componentSpec as ReasonReact_componentSpec} from '../../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {noRetainedProps as ReasonReact_noRetainedProps} from '../../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {stateless as ReasonReact_stateless} from '../../src/shims/ReactShim.shim'; +export type Props = {| +history: history, +match: match |}; -export const make: ({| +history: T1, +match: T2 |}, T3) => ReasonReact_componentSpec = function (Arg1: $any, Arg2: $any) { - const result = Curry._3(NavigatorBS.make, Arg1.history, Arg1.match, Arg2); - return result -}; +export const make: React$ComponentType<{| +history: $any, +match: $any |}> = NavigatorBS.make; diff --git a/examples/flow-react-example/src/components/Navigator.res b/examples/flow-react-example/src/components/Navigator.res index cde0e7104..1f1bf1ffb 100644 --- a/examples/flow-react-example/src/components/Navigator.res +++ b/examples/flow-react-example/src/components/Navigator.res @@ -1,16 +1,10 @@ -let component = ReasonReact.statelessComponent("Navigator") - type action = | Navigate(string) | Logout -@genType -let make = (~history, ~match as match_, _children) => { - ...component, - render: _self => { - Js.log2("history", history) - Js.log2("match", match_) -
- }, +@genType @react.component +let make = (~history, ~match as match_) => { + Js.log2("history", history) + Js.log2("match", match_) +
} - diff --git a/examples/flow-react-example/src/components/RenameProps.bs.js b/examples/flow-react-example/src/components/RenameProps.bs.js index 1b0875090..55be6dca8 100644 --- a/examples/flow-react-example/src/components/RenameProps.bs.js +++ b/examples/flow-react-example/src/components/RenameProps.bs.js @@ -1,32 +1,15 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as ReasonReact from "reason-react/src/legacy/ReasonReact.bs.js"; - -var component = ReasonReact.statelessComponent("RenameProps"); function functionWithGenTypeAs(firstNameArgumentCantBeRenamed, type_, number) { return firstNameArgumentCantBeRenamed + (type_ + String(number)); } -function make(firstNameArgumentCantBeRenamed, type_, number, _children) { - return { - debugName: component.debugName, - reactClassInternal: component.reactClassInternal, - handedOffState: component.handedOffState, - willReceiveProps: component.willReceiveProps, - didMount: component.didMount, - didUpdate: component.didUpdate, - willUnmount: component.willUnmount, - willUpdate: component.willUpdate, - shouldUpdate: component.shouldUpdate, - render: (function (_self) { - return firstNameArgumentCantBeRenamed + (type_ + String(number)); - }), - initialState: component.initialState, - retainedProps: component.retainedProps, - reducer: component.reducer, - jsElementWrapped: component.jsElementWrapped - }; +function RenameProps(Props) { + var firstNameArgumentCantBeRenamed = Props.firstNameArgumentCantBeRenamed; + var type_ = Props.type_; + var number = Props.number; + return firstNameArgumentCantBeRenamed + (type_ + String(number)); } function firstIsIgnored(x) { @@ -57,8 +40,9 @@ function renameABunch3(pad, x, y, z) { return ((pad + x | 0) + y | 0) + z | 0; } +var make = RenameProps; + export { - component , functionWithGenTypeAs , make , firstIsIgnored , @@ -70,4 +54,4 @@ export { renameABunch3 , } -/* component Not a pure module */ +/* No side effect */ diff --git a/examples/flow-react-example/src/components/RenameProps.gen.js b/examples/flow-react-example/src/components/RenameProps.gen.js index 332534b8b..1f46df7cb 100644 --- a/examples/flow-react-example/src/components/RenameProps.gen.js +++ b/examples/flow-react-example/src/components/RenameProps.gen.js @@ -13,18 +13,6 @@ import * as Curry from 'rescript/lib/es6/curry.js'; // $FlowExpectedError[untyped-import]: Reason checked type sufficiently import * as RenamePropsBS from './RenameProps.bs'; -// flowlint-next-line nonstrict-import:off -import type {actionless as ReasonReact_actionless} from '../../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {componentSpec as ReasonReact_componentSpec} from '../../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {noRetainedProps as ReasonReact_noRetainedProps} from '../../src/shims/ReactShim.shim'; - -// flowlint-next-line nonstrict-import:off -import type {stateless as ReasonReact_stateless} from '../../src/shims/ReactShim.shim'; - export type functionTypeWithGenTypeAs = ({| +type: string, +"$number": number |}) => number; export const functionWithGenTypeAs: ({| @@ -36,14 +24,17 @@ export const functionWithGenTypeAs: ({| return result }; -export const make: ({| +export type Props = {| +firstNameArgumentCantBeRenamed: string, - +type: string, - +"$$number": number -|}, T1) => ReasonReact_componentSpec = function (Arg1: $any, Arg2: $any) { - const result = Curry._4(RenamePropsBS.make, Arg1.firstNameArgumentCantBeRenamed, Arg1.type, Arg1.$$number, Arg2); - return result -}; + +number: number, + +type_: string +|}; + +export const make: React$ComponentType<{| + +firstNameArgumentCantBeRenamed: string, + +number: number, + +type_: string +|}> = RenamePropsBS.make; export const firstIsIgnored: ({| +Ignored: number |}) => number = function (Arg1: $any) { const result = RenamePropsBS.firstIsIgnored(Arg1.Ignored); diff --git a/examples/flow-react-example/src/components/RenameProps.res b/examples/flow-react-example/src/components/RenameProps.res index cd9b430c5..c3460d804 100644 --- a/examples/flow-react-example/src/components/RenameProps.res +++ b/examples/flow-react-example/src/components/RenameProps.res @@ -1,5 +1,3 @@ -let component = ReasonReact.statelessComponent("RenameProps") - /* All these genType.as annotation are picked up in the AST. */ @genType type functionTypeWithGenTypeAs = ( @@ -15,16 +13,13 @@ let functionWithGenTypeAs = ( ) => firstNameArgumentCantBeRenamed ++ (type_ ++ string_of_int(number)) /* These genType.as annotation are currently not picked up in the AST */ -@genType +@genType @react.component let make = ( ~firstNameArgumentCantBeRenamed, @genType.as("type") ~type_, @genType.as("$$number") ~number, - _children, ) => { - ...component, - render: _self => - (firstNameArgumentCantBeRenamed ++ (type_ ++ string_of_int(number)))->ReasonReact.string, + (firstNameArgumentCantBeRenamed ++ (type_ ++ string_of_int(number)))->React.string } @genType @@ -55,4 +50,3 @@ let renameABunch2 = (pad, @genType.as("xRenamed") ~x, ~y, @genType.as("zRenamed" @genType let renameABunch3 = (pad, @genType.as("xRenamed") ~x, y, @genType.as("zRenamed") ~z) => pad + x + y + z - diff --git a/examples/flow-react-example/src/shims/ReactShim.shim.js b/examples/flow-react-example/src/shims/ReactShim.shim.js deleted file mode 100644 index 4d5a7b068..000000000 --- a/examples/flow-react-example/src/shims/ReactShim.shim.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2004-present Facebook. All Rights Reserved. - * - * @flow strict - * @nolint - */ - -import * as React from 'react'; - -export type reactElement = React.Node; -export type element = React.Node; - -export type component = React.ComponentType; - -// $FlowExpectedError[unclear-type]: Reason checked type sufficiently. -export opaque type componentSpec = any; - -// $FlowExpectedError[unclear-type]: Reason checked type sufficiently. -export opaque type noRetainedProps = any; - -// $FlowExpectedError[unclear-type]: Reason checked type sufficiently. -export opaque type actionless = any; - -// $FlowExpectedError[unclear-type]: Reason checked type sufficiently. -export opaque type stateless = any; - -// $FlowExpectedError[unclear-type]: Reason checked type sufficiently. -export opaque type reactRef = any; - -// $FlowExpectedError[unclear-type]: Reason checked type sufficiently. -export opaque type ref = any; diff --git a/examples/typescript-react-example/bsconfig.json b/examples/typescript-react-example/bsconfig.json index 033e621b1..0d1dd3200 100644 --- a/examples/typescript-react-example/bsconfig.json +++ b/examples/typescript-react-example/bsconfig.json @@ -5,7 +5,6 @@ "importPath": "relative", "shims": { "Js": "Js", - "React": "ReactShim", "ReactEvent": "ReactEvent", "RescriptPervasives": "RescriptPervasives", "ReasonReact": "ReactShim" diff --git a/examples/typescript-react-example/src/shims/ReactShim.shim.ts b/examples/typescript-react-example/src/shims/ReactShim.shim.ts deleted file mode 100644 index 25dcc9c7a..000000000 --- a/examples/typescript-react-example/src/shims/ReactShim.shim.ts +++ /dev/null @@ -1,28 +0,0 @@ - -export type reactElement = JSX.Element; -export type element = reactElement; - -// tslint:disable-next-line:max-classes-per-file -export abstract class component { - protected opaque: unknown; -} -// tslint:disable-next-line:max-classes-per-file -export abstract class componentSpec { - protected opaque: unknown; -} -// tslint:disable-next-line:max-classes-per-file -export abstract class noRetainedProps { - protected opaque: unknown; -} -// tslint:disable-next-line:max-classes-per-file -export abstract class actionless { - protected opaque: unknown; -} -// tslint:disable-next-line:max-classes-per-file -export abstract class stateless { - protected opaque: unknown; -} -// tslint:disable-next-line:max-classes-per-file -export abstract class reactRef { - protected opaque: unknown; -} diff --git a/src/EmitType.ml b/src/EmitType.ml index faafdc15f..8cb41144e 100644 --- a/src/EmitType.ml +++ b/src/EmitType.ml @@ -105,7 +105,7 @@ let typeReactChild ~config = let isTypeReactElement ~config type_ = type_ == typeReactElement ~config -let typeReactDOMReDomRef ~config = +let typeReactDOMRef ~config = (match config.language = Flow with | true -> "React$Ref" | false -> "React.Ref") diff --git a/src/EmitType.mli b/src/EmitType.mli deleted file mode 100644 index 0e2ad5f16..000000000 --- a/src/EmitType.mli +++ /dev/null @@ -1,114 +0,0 @@ -open GenTypeCommon - -val emitExportConst : - ?comment:string -> - config:config -> - ?docString:string -> - emitters:Emitters.t -> - name:string -> - type_:type_ -> - typeNameIsInterface:(string -> bool) -> - string -> - Emitters.t - -val emitExportConstEarly : - ?comment:string -> - config:config -> - ?docString:string -> - emitters:Emitters.t -> - name:string -> - type_:type_ -> - typeNameIsInterface:(string -> bool) -> - string -> - Emitters.t - -val emitExportDefault : - emitters:Emitters.t -> config:config -> string -> Emitters.t - -val emitExportType : - ?early:bool -> - config:config -> - emitters:Emitters.t -> - nameAs:string option -> - opaque:bool -> - type_:type_ -> - typeNameIsInterface:(string -> bool) -> - typeVars:string list -> - string -> - Emitters.t - -val emitImportReact : emitters:Emitters.t -> config:config -> Emitters.t - -val emitImportTypeAs : - emitters:Emitters.t -> - config:config -> - typeName:string -> - asTypeName:string option -> - typeNameIsInterface:(string -> bool) -> - importPath:ImportPath.t -> - Emitters.t - -val emitImportValueAsEarly : - config:config -> - emitters:Emitters.t -> - name:string -> - nameAs:string option -> - ImportPath.t -> - Emitters.t - -val emitPropTypes : - config:config -> - emitters:Emitters.t -> - indent:Indent.t -> - name:string -> - field list -> - Emitters.t - -val emitRequire : - importedValueOrComponent:bool -> - early:bool -> - emitters:Emitters.t -> - config:config -> - moduleName:ModuleName.t -> - strict:bool -> - ImportPath.t -> - Emitters.t - -val emitTypeCast : - config:config -> - type_:type_ -> - typeNameIsInterface:(string -> bool) -> - string -> - string - -val fileHeader : config:config -> sourceFile:string -> string - -val generatedModuleExtension : config:config -> string - -val isTypeFunctionComponent : config:config -> fields:fields -> type_ -> bool - -val isTypeReactElement : config:config -> type_ -> bool - -val ofTypeAny : config:config -> string -> string -(** Help type-checking by making the argument of type any *) - -val outputFileSuffix : config:config -> string - -val shimExtension : config:config -> string - -val typeReactChild : config:config -> type_ - -val typeReactContext : config:config -> type_:type_ -> type_ - -val typeReactDOMReDomRef : config:config -> type_ - -val typeReactElement : config:config -> type_ - -val typeReactEventMouseT : config:config -> type_ - -val typeReactRef : type_:type_ -> type_ - -val typeAny : config:config -> type_ - -val typeToString : - config:config -> typeNameIsInterface:(string -> bool) -> type_ -> string diff --git a/src/TranslateTypeExprFromTypes.ml b/src/TranslateTypeExprFromTypes.ml index 9302721ba..db781ec86 100644 --- a/src/TranslateTypeExprFromTypes.ml +++ b/src/TranslateTypeExprFromTypes.ml @@ -174,8 +174,12 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = dependencies = paramTranslation.dependencies; type_ = EmitType.typeReactRef ~type_:paramTranslation.type_; } + | (["ReactDOM"; "domRef"] | ["ReactDOM"; "Ref"; "t"]), [] -> + {dependencies = []; type_ = EmitType.typeReactDOMRef ~config} + | ["ReactDOM"; "Ref"; "currentDomRef"], [] -> + {dependencies = []; type_ = EmitType.typeAny ~config} | ["ReactDOMRe"; "domRef"], [] -> - {dependencies = []; type_ = EmitType.typeReactDOMReDomRef ~config} + {dependencies = []; type_ = EmitType.typeReactDOMRef ~config} | ["ReactDOMRe"; "Ref"; "currentDomRef"], [] -> {dependencies = []; type_ = EmitType.typeAny ~config} | ["ReactEvent"; "Mouse"; "t"], [] ->