From 799c60a1b81ad82f99a03c3148a26e1d462d9419 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 6 Jul 2022 06:05:51 +0200 Subject: [PATCH] rebase on master --- examples/typescript-react-example/src/Records.gen.tsx | 2 +- .../typescript-react-example/src/nested/Types.gen.tsx | 2 +- src/EmitJs.ml | 11 ++++------- src/EmitType.ml | 2 +- src/GenTypeMain.ml | 2 +- src/ModuleName.ml | 2 +- src/ModuleName.mli | 2 +- src/TranslateCoreType.ml | 3 +-- src/TranslateTypeExprFromTypes.ml | 4 ++-- 9 files changed, 13 insertions(+), 17 deletions(-) diff --git a/examples/typescript-react-example/src/Records.gen.tsx b/examples/typescript-react-example/src/Records.gen.tsx index fd0f19ffb..8201ca600 100644 --- a/examples/typescript-react-example/src/Records.gen.tsx +++ b/examples/typescript-react-example/src/Records.gen.tsx @@ -10,7 +10,7 @@ const Curry: any = Curry__Es6Import; import * as RecordsBS__Es6Import from './Records.bs'; const RecordsBS: any = RecordsBS__Es6Import; -import type {list} from '../src/shims/RescriptPervasives.shim'; +import type {list} from './ReasonPervasives.gen'; // tslint:disable-next-line:interface-over-type-literal export type coord = { diff --git a/examples/typescript-react-example/src/nested/Types.gen.tsx b/examples/typescript-react-example/src/nested/Types.gen.tsx index 1c7fff069..16e727949 100644 --- a/examples/typescript-react-example/src/nested/Types.gen.tsx +++ b/examples/typescript-react-example/src/nested/Types.gen.tsx @@ -16,7 +16,7 @@ import type {Json_t as Js_Json_t} from '../../src/shims/Js.shim'; import type {M_t__ as TypeNameSanitize_M_t__} from '../../src/TypeNameSanitize.gen'; -import type {list} from '../../src/shims/RescriptPervasives.shim'; +import type {list} from './ReasonPervasives.gen'; import type {t_ as TypeNameSanitize_t_} from '../../src/TypeNameSanitize.gen'; diff --git a/src/EmitJs.ml b/src/EmitJs.ml index 191b205b5..5c057ead8 100644 --- a/src/EmitJs.ml +++ b/src/EmitJs.ml @@ -156,7 +156,7 @@ let rec emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName let type_ = match type_ with | Function - ({argTypes = [{aType = Object (_, fields)}]; retType} as function_) + ({argTypes = [{aType = Object (closedFlag, fields); aName}]; retType} as function_) when retType |> EmitType.isTypeFunctionComponent ~fields -> let componentName = match importFile with "." | ".." -> None | _ -> Some importFile @@ -166,16 +166,13 @@ let rec emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName |> List.map (fun (field : field) -> match field.nameJS = "children" - && field.type_ |> EmitType.isTypeReactElement ~config + && field.type_ |> EmitType.isTypeReactElement with - | true -> {field with type_ = EmitType.typeReactChild ~config} + | true -> {field with type_ = EmitType.typeReactChild} | false -> field) in let function_ = - { - function_ with - argTypes = [{argType with aType = Object (closedFlag, fields)}]; - } + {function_ with argTypes = [{aType = Object (closedFlag, fields); aName}]} in Function {function_ with componentName} | _ -> type_ diff --git a/src/EmitType.ml b/src/EmitType.ml index 5ab5e3cfa..3a5333ff9 100644 --- a/src/EmitType.ml +++ b/src/EmitType.ml @@ -1,6 +1,6 @@ open GenTypeCommon -let fileHeader ~config ~sourceFile = +let fileHeader ~sourceFile = let makeHeader ~lines = match lines with | [line] -> "/* " ^ line ^ " */\n" diff --git a/src/GenTypeMain.ml b/src/GenTypeMain.ml index c6d81198b..b5e85db6f 100644 --- a/src/GenTypeMain.ml +++ b/src/GenTypeMain.ml @@ -78,7 +78,7 @@ let emitTranslation ~config ~fileName ~outputFile ~outputFileRelative ~resolver in let fileContents = signFile - (EmitType.fileHeader ~config ~sourceFile:(Filename.basename sourceFile) + (EmitType.fileHeader ~sourceFile:(Filename.basename sourceFile) ^ "\n" ^ codeText ^ "\n") in GeneratedFiles.writeFileIfRequired ~outputFile ~fileContents diff --git a/src/ModuleName.ml b/src/ModuleName.ml index da1122249..b3f183f2a 100644 --- a/src/ModuleName.ml +++ b/src/ModuleName.ml @@ -4,7 +4,7 @@ let curry = "Curry" let propTypes = "PropTypes" -let reasonPervasives = "ReasonPervasives" +let rescriptPervasives = "ReasonPervasives" let dotRegex = "." |> Str.quote |> Str.regexp diff --git a/src/ModuleName.mli b/src/ModuleName.mli index cd7c01193..a87375d08 100644 --- a/src/ModuleName.mli +++ b/src/ModuleName.mli @@ -13,7 +13,7 @@ val fromStringUnsafe : string -> t val propTypes : t -val reasonPervasives : t +val rescriptPervasives : t val toString : t -> string diff --git a/src/TranslateCoreType.ml b/src/TranslateCoreType.ml index b2f7170e1..2d7452765 100644 --- a/src/TranslateCoreType.ml +++ b/src/TranslateCoreType.ml @@ -248,8 +248,7 @@ and translateCoreType_ ~config ~typeVarsGen |> List.map (fun (_, _, {dependencies}) -> dependencies) |> List.concat) in - {dependencies; type_} - | _ -> {dependencies = []; type_ = unknown}) + {dependencies; type_}) | Ttyp_package {pack_path; pack_fields} -> ( match typeEnv |> TypeEnv.lookupModuleTypeSignature ~path:pack_path with | Some (signature, typeEnv) -> diff --git a/src/TranslateTypeExprFromTypes.ml b/src/TranslateTypeExprFromTypes.ml index 3b5df7238..74fcf5ba4 100644 --- a/src/TranslateTypeExprFromTypes.ml +++ b/src/TranslateTypeExprFromTypes.ml @@ -175,9 +175,9 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = type_ = EmitType.typeReactRef ~type_:paramTranslation.type_; } | (["ReactDOM"; "domRef"] | ["ReactDOM"; "Ref"; "t"]), [] -> - {dependencies = []; type_ = EmitType.typeReactRef} + {dependencies = []; type_ = EmitType.typeReactDOMReDomRef} | ["ReactDOM"; "Ref"; "currentDomRef"], [] -> - {dependencies = []; type_ = EmitType.typeAny ~config} + {dependencies = []; type_ = EmitType.typeAny} | ["ReactDOMRe"; "domRef"], [] -> {dependencies = []; type_ = EmitType.typeReactDOMReDomRef} | ["ReactDOMRe"; "Ref"; "currentDomRef"], [] ->