diff --git a/CHANGELOG.md b/CHANGELOG.md index 7657569522..346df05115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ These are only breaking changes for unformatted code. - Remove deprecated module `Printexc` - `@deriving(jsConverter)` not supported anymore for variant types https://github.com/rescript-lang/rescript-compiler/pull/6088 - New representation for variants, where the tag is a string instead of a number. https://github.com/rescript-lang/rescript-compiler/pull/6088 +- GenType: removed support for `@genType.as` for records and variants which has become unnecessary. Use the language's `@as` instead to channge the runtime representation without requiring any runtime conversion during FFI. #### :bug: Bug Fix @@ -84,6 +85,7 @@ These are only breaking changes for unformatted code. - Change the compilation of pattern matching for variants so it does not depends on variats being integers https://github.com/rescript-lang/rescript-compiler/pull/6085 - Improve code generated for string templates https://github.com/rescript-lang/rescript-compiler/pull/6090 - Move Jsx and JsxDOM and JsxEvent and JsxPPXReactSupport inside Pervasives and build them separately for curried and uncurried mode https://github.com/rescript-lang/rescript-compiler/pull/6091 +- Gentype: allow recursive data types https://github.com/rescript-association/genType/issues/585 # 10.1.4 diff --git a/Makefile b/Makefile index ddb6c97c7f..047c9a9dff 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ bench: $(DUNE_BIN_DIR)/syntax_benchmarks dce: - reanalyze.exe -- -dce-cmt _build + reanalyze.exe -dce-cmt _build/default/jscomp ninja/ninja: ./scripts/buildNinjaBinary.js @@ -43,6 +43,7 @@ test-all: test test-gentype reanalyze: reanalyze.exe -set-exit-code -all-cmt _build/default/res_syntax -suppress res_syntax/testrunner + reanalyze.exe -set-exit-code -all-cmt _build/default/jscomp -suppress res_syntax/testrunner -exclude-paths jscomp/super_errors,jscomp/outcome_printer,jscomp/ounit_tests,jscomp/ml,jscomp/js_parser,jscomp/frontend,jscomp/ext,jscomp/depends,jscomp/core,jscomp/common,jscomp/cmij,jscomp/bsb_helper,jscomp/bsb lib: build node_modules/.bin/semver node scripts/ninja.js config diff --git a/jscomp/frontend/ast_attributes.mli b/jscomp/frontend/ast_attributes.mli index c495fff9a9..7ab5bdcc05 100644 --- a/jscomp/frontend/ast_attributes.mli +++ b/jscomp/frontend/ast_attributes.mli @@ -94,4 +94,4 @@ val process_send_pipe : t -> (Parsetree.core_type * t) option val process_as_value : t -> Lambda.as_value option -val process_tag_name : t -> string option \ No newline at end of file +val process_tag_name : t -> string option diff --git a/jscomp/gentype/Annotation.ml b/jscomp/gentype/Annotation.ml index 6d0c89f715..632d406851 100644 --- a/jscomp/gentype/Annotation.ml +++ b/jscomp/gentype/Annotation.ml @@ -64,46 +64,68 @@ let rec getAttributePayload checkText (attributes : Typedtree.attributes) = in match attributes with | [] -> None - | ({Asttypes.txt}, payload) :: _tl when checkText txt -> ( + | ({txt; loc}, payload) :: _tl when checkText txt -> ( + let payload = + match payload with + | PStr [] -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_eval (expr, _)} :: _) -> expr |> fromExpr + | PStr ({pstr_desc = Pstr_extension _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_value _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_primitive _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_type _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_typext _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_exception _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_module _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_recmodule _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_modtype _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_open _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_class _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_class_type _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_include _} :: _) -> Some UnrecognizedPayload + | PStr ({pstr_desc = Pstr_attribute _} :: _) -> Some UnrecognizedPayload + | PPat _ -> Some UnrecognizedPayload + | PSig _ -> Some UnrecognizedPayload + | PTyp _ -> Some UnrecognizedPayload + in match payload with - | PStr [] -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_eval (expr, _)} :: _) -> expr |> fromExpr - | PStr ({pstr_desc = Pstr_extension _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_value _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_primitive _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_type _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_typext _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_exception _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_module _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_recmodule _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_modtype _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_open _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_class _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_class_type _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_include _} :: _) -> Some UnrecognizedPayload - | PStr ({pstr_desc = Pstr_attribute _} :: _) -> Some UnrecognizedPayload - | PPat _ -> Some UnrecognizedPayload - | PSig _ -> Some UnrecognizedPayload - | PTyp _ -> Some UnrecognizedPayload) + | None -> None + | Some payload -> Some (loc, payload)) | _hd :: tl -> getAttributePayload checkText tl let getGenTypeAsRenaming attributes = match attributes |> getAttributePayload tagIsGenTypeAs with - | Some (StringPayload s) -> Some s + | Some (_, StringPayload s) -> Some s | None -> ( match attributes |> getAttributePayload tagIsGenType with - | Some (StringPayload s) -> Some s + | Some (_, StringPayload s) -> Some s | _ -> None) | _ -> None +(* This is not supported anymore: only use to give a warning *) +let checkUnsupportedGenTypeAsRenaming attributes = + let error ~loc = + Log_.Color.setup (); + Log_.info ~loc ~name:"Warning genType" (fun ppf () -> + Format.fprintf ppf + "@\n\ + @genType.as is not supported anymore in type definitions. Use @as \ + from the language.") + in + match attributes |> getAttributePayload tagIsGenTypeAs with + | Some (loc, _) -> error ~loc + | None -> ( + match attributes |> getAttributePayload tagIsGenType with + | Some (loc, _) -> error ~loc + | None -> ()) + let getBsAsRenaming attributes = match attributes |> getAttributePayload tagIsBsAs with - | Some (StringPayload s) -> Some s + | Some (_, StringPayload s) -> Some s | _ -> None let getBsAsInt attributes = match attributes |> getAttributePayload tagIsBsAs with - | Some (IntPayload s) -> ( + | Some (_, IntPayload s) -> ( try Some (int_of_string s) with Failure _ -> None) | _ -> None @@ -111,10 +133,12 @@ let getAttributeImportRenaming attributes = let attributeImport = attributes |> getAttributePayload tagIsGenTypeImport in let genTypeAsRenaming = attributes |> getGenTypeAsRenaming in match (attributeImport, genTypeAsRenaming) with - | Some (StringPayload importString), _ -> + | Some (_, StringPayload importString), _ -> (Some importString, genTypeAsRenaming) | ( Some - (TuplePayload [StringPayload importString; StringPayload renameString]), + ( _, + TuplePayload [StringPayload importString; StringPayload renameString] + ), _ ) -> (Some importString, Some renameString) | _ -> (None, genTypeAsRenaming) @@ -122,7 +146,7 @@ let getAttributeImportRenaming attributes = let getDocString attributes = let docPayload = attributes |> getAttributePayload tagIsOcamlDoc in match docPayload with - | Some (StringPayload docString) -> "/** " ^ docString ^ " */\n" + | Some (_, StringPayload docString) -> "/** " ^ docString ^ " */\n" | _ -> "" let hasAttribute checkText (attributes : Typedtree.attributes) = @@ -133,7 +157,7 @@ let fromAttributes ~loc (attributes : Typedtree.attributes) = else if hasAttribute (fun s -> tagIsGenType s || tagIsGenTypeAs s) attributes then ( (match attributes |> getAttributePayload tagIsGenType with - | Some UnrecognizedPayload -> () + | Some (_, UnrecognizedPayload) -> () | Some _ -> Log_.Color.setup (); Log_.info ~loc ~name:"Warning genType" (fun ppf () -> diff --git a/jscomp/gentype/Converter.ml b/jscomp/gentype/Converter.ml index 9a7d1c42a2..f31f0b602a 100644 --- a/jscomp/gentype/Converter.ml +++ b/jscomp/gentype/Converter.ml @@ -1,166 +1,32 @@ open GenTypeCommon -type t = - | ArrayC of t - | CircularC of string * t - | FunctionC of functionC - | IdentC - | ObjectC of fieldsC - | OptionC of t - | PromiseC of t - | TupleC of t list - | VariantC of variantC - -and groupedArgConverter = - | ArgConverter of t - | GroupConverter of (string * optional * t) list - -and fieldC = {lblJS: string; lblRE: string; c: t} -and fieldsC = fieldC list - -and functionC = { - funArgConverters: groupedArgConverter list; - componentName: string option; - isHook: bool; - retConverter: t; - typeVars: string list; - uncurried: bool; -} - -and variantC = { - hash: int; - noPayloads: case list; - withPayloads: withPayload list; - polymorphic: bool; - unboxed: bool; - useVariantTables: bool; -} - -and withPayload = {case: case; inlineRecord: bool; argConverters: t list} - -let rec toString converter = - match converter with - | ArrayC c -> "array(" ^ toString c ^ ")" - | CircularC (s, c) -> "circular(" ^ s ^ " " ^ toString c ^ ")" - | FunctionC {funArgConverters; retConverter; uncurried} -> - "fn" - ^ (match uncurried with - | true -> "Uncurried" - | false -> "") - ^ "(" - ^ (funArgConverters - |> List.map (fun groupedArgConverter -> - match groupedArgConverter with - | ArgConverter conv -> "(" ^ "_" ^ ":" ^ toString conv ^ ")" - | GroupConverter groupConverters -> - "{|" - ^ (groupConverters - |> List.map (fun (s, optional, argConverter) -> - s - ^ (match optional = Optional with - | true -> "?" - | false -> "") - ^ ":" ^ toString argConverter) - |> String.concat ", ") - ^ "|}") - |> String.concat ", ") - ^ " -> " ^ toString retConverter ^ ")" - | IdentC -> "id" - | ObjectC fieldsC -> - let dot = - match converter with - | ObjectC _ -> ". " - | _ -> "" - in - "{" ^ dot - ^ (fieldsC - |> List.map (fun {lblJS; lblRE; c} -> - (match lblJS = lblRE with - | true -> lblJS - | false -> "(" ^ lblJS ^ "/" ^ lblRE ^ ")") - ^ ":" ^ (c |> toString)) - |> String.concat ", ") - ^ "}" - | OptionC c -> "option(" ^ toString c ^ ")" - | PromiseC c -> "promise(" ^ toString c ^ ")" - | TupleC innerTypesC -> - "[" ^ (innerTypesC |> List.map toString |> String.concat ", ") ^ "]" - | VariantC {noPayloads; withPayloads} -> - "variant(" - ^ ((noPayloads |> List.map labelJSToString) - @ (withPayloads - |> List.map (fun {case; inlineRecord; argConverters} -> - (case |> labelJSToString) - ^ (match inlineRecord with - | true -> " inlineRecord " - | false -> "") - ^ ":" ^ "{" - ^ (argConverters |> List.map toString |> String.concat ", ") - ^ "}")) - |> String.concat ", ") - ^ ")" - -let typeGetConverterNormalized ~config ~inline ~lookupId ~typeNameIsInterface - type0 = +let typeGetInlined ~config ~lookupId ~typeNameIsInterface type0 = let circular = ref "" in - let expandOneLevel type_ = - match type_ with - | Ident {builtin = false; name} -> ( - match name |> lookupId with - | (t : CodeItem.exportTypeItem) -> t.type_ - | exception Not_found -> type_) - | _ -> type_ - in let rec visit ~(visited : StringSet.t) type_ = let normalized_ = type_ in match type_ with | Array (t, mutable_) -> - let tConverter, tNormalized = t |> visit ~visited in - (ArrayC tConverter, Array (tNormalized, mutable_)) - | Dict _ -> (IdentC, normalized_) - | Function - ({argTypes; componentName; retType; typeVars; uncurried} as function_) - -> - let argConverted = - argTypes |> List.map (argTypeToGroupedArgConverter ~visited) - in - let funArgConverters = argConverted |> List.map fst in - let retConverter, retNormalized = retType |> visit ~visited in - let isHook = - match argTypes with - | [{aType = Object (_, fields)}] -> - retType |> EmitType.isTypeFunctionComponent ~fields - | _ -> false - in - ( FunctionC - { - funArgConverters; - componentName; - isHook; - retConverter; - typeVars; - uncurried; - }, - Function - { - function_ with - argTypes = argConverted |> List.map snd; - retType = retNormalized; - } ) + let tNormalized = t |> visit ~visited in + Array (tNormalized, mutable_) + | Dict _ -> normalized_ + | Function ({argTypes; retType} as function_) -> + let argConverted = argTypes |> List.map (argTypeToGroupedArg ~visited) in + let retNormalized = retType |> visit ~visited in + Function {function_ with argTypes = argConverted; retType = retNormalized} | GroupOfLabeledArgs _ -> (* This case should only fire from withing a function *) - (IdentC, normalized_) - | Ident {builtin = true} -> (IdentC, normalized_) + normalized_ + | Ident {builtin = true} -> normalized_ | Ident {builtin = false; name; typeArgs} -> ( if visited |> StringSet.mem name then ( circular := name; - (IdentC, normalized_)) + normalized_) else let visited = visited |> StringSet.add name in match name |> lookupId with - | {annotation = GenTypeOpaque} -> (IdentC, normalized_) - | {annotation = NoGenType} -> (IdentC, normalized_) - | {typeVars; type_} -> ( + | {CodeItem.annotation = GenTypeOpaque} -> normalized_ + | {annotation = NoGenType} -> normalized_ + | {typeVars; type_} -> let pairs = try List.combine typeVars typeArgs with Invalid_argument _ -> [] in @@ -171,132 +37,46 @@ let typeGetConverterNormalized ~config ~inline ~lookupId ~typeNameIsInterface | _, typeArgument -> Some typeArgument | exception Not_found -> None in - let converter, inlined = - type_ |> TypeVars.substitute ~f |> visit ~visited - in - ( converter, - match inline with - | true -> inlined - | false -> normalized_ )) + let inlined = type_ |> TypeVars.substitute ~f |> visit ~visited in + inlined | exception Not_found -> - if inline then - let typeArgs = - typeArgs |> List.map (fun t -> t |> visit ~visited |> snd) - in - (IdentC, Ident {builtin = false; name; typeArgs}) - else (IdentC, normalized_)) + let typeArgs = typeArgs |> List.map (fun t -> t |> visit ~visited) in + Ident {builtin = false; name; typeArgs}) | Null t -> - let tConverter, tNormalized = t |> visit ~visited in - (OptionC tConverter, Null tNormalized) + let tNormalized = t |> visit ~visited in + Null tNormalized | Nullable t -> - let tConverter, tNormalized = t |> visit ~visited in - (OptionC tConverter, Nullable tNormalized) - | Object (closedFlag, fields) -> - let fieldsConverted = - fields - |> List.map (fun ({type_} as field) -> (field, type_ |> visit ~visited)) - in - ( ObjectC - (fieldsConverted - |> List.map (fun ({nameJS; nameRE; optional}, (converter, _)) -> - { - lblJS = nameJS; - lblRE = nameRE; - c = - (match optional = Mandatory with - | true -> converter - | false -> OptionC converter); - })), - Object - ( closedFlag, - fieldsConverted - |> List.map (fun (field, (_, tNormalized)) -> - {field with type_ = tNormalized}) ) ) + let tNormalized = t |> visit ~visited in + Nullable tNormalized + | Object _ -> normalized_ | Option t -> - let tConverter, tNormalized = t |> visit ~visited in - (OptionC tConverter, Option tNormalized) + let tNormalized = t |> visit ~visited in + Option tNormalized | Promise t -> - let tConverter, tNormalized = t |> visit ~visited in - (PromiseC tConverter, Promise tNormalized) + let tNormalized = t |> visit ~visited in + Promise tNormalized | Tuple innerTypes -> - let innerConversions, normalizedList = - innerTypes |> List.map (visit ~visited) |> List.split - in - (TupleC innerConversions, Tuple normalizedList) - | TypeVar _ -> (IdentC, normalized_) + let normalizedList = innerTypes |> List.map (visit ~visited) in + Tuple normalizedList + | TypeVar _ -> normalized_ | Variant variant -> - let allowUnboxed = not variant.polymorphic in - let withPayloads, normalized, unboxed = - match - variant.payloads - |> List.map (fun {case; inlineRecord; numArgs; t} -> - (case, inlineRecord, numArgs, t |> visit ~visited)) - with - | [] when allowUnboxed -> ([], normalized_, variant.unboxed) - | [(case, inlineRecord, numArgs, (converter, tNormalized))] - when allowUnboxed -> - let unboxed = tNormalized |> expandOneLevel |> typeIsObject in - let normalized = - Variant - { - variant with - payloads = [{case; inlineRecord; numArgs; t = tNormalized}]; - unboxed = - (match unboxed with - | true -> true - | false -> variant.unboxed); - } - in - let argConverters = - match converter with - | TupleC converters when numArgs > 1 -> converters - | _ -> [converter] - in - ([{argConverters; case; inlineRecord}], normalized, unboxed) + let ordinaryVariant = not variant.polymorphic in + let withPayloadConverted = + variant.payloads + |> List.map (fun (payload : payload) -> + {payload with t = payload.t |> visit ~visited}) + in + let normalized = + match withPayloadConverted with + | [] when ordinaryVariant -> normalized_ + | [payload] when ordinaryVariant -> + let normalized = Variant {variant with payloads = [payload]} in + normalized | withPayloadConverted -> - let withPayloadNormalized = - withPayloadConverted - |> List.map (fun (case, inlineRecord, numArgs, (_, tNormalized)) -> - {case; inlineRecord; numArgs; t = tNormalized}) - in - let normalized = - Variant {variant with payloads = withPayloadNormalized} - in - ( withPayloadConverted - |> List.map (fun (case, inlineRecord, numArgs, (converter, _)) -> - let argConverters = - match converter with - | TupleC converters when numArgs > 1 -> converters - | _ -> [converter] - in - {argConverters; case; inlineRecord}), - normalized, - variant.unboxed ) - in - let noPayloads = variant.noPayloads in - let useVariantTables = - if variant.bsStringOrInt then false - else if variant.polymorphic then - noPayloads - |> List.exists (fun {label; labelJS} -> labelJS <> StringLabel label) - || withPayloads - |> List.exists (fun {case = {label; labelJS}} -> - labelJS <> StringLabel label) - else true - in - let converter = - VariantC - { - hash = variant.hash; - noPayloads; - withPayloads; - polymorphic = variant.polymorphic; - unboxed; - useVariantTables; - } + Variant {variant with payloads = withPayloadConverted} in - (converter, normalized) - and argTypeToGroupedArgConverter ~visited {aName; aType} = + normalized + and argTypeToGroupedArg ~visited {aName; aType} = match aType with | GroupOfLabeledArgs fields -> let fieldsConverted = @@ -306,361 +86,15 @@ let typeGetConverterNormalized ~config ~inline ~lookupId ~typeNameIsInterface let tNormalized = GroupOfLabeledArgs (fieldsConverted - |> List.map (fun (field, (_, t)) -> {field with type_ = t})) - in - let converter = - GroupConverter - (fieldsConverted - |> List.map (fun ({nameJS; optional}, (converter, _)) -> - (nameJS, optional, converter))) + |> List.map (fun (field, t) -> {field with type_ = t})) in - (converter, {aName; aType = tNormalized}) + {aName; aType = tNormalized} | _ -> - let converter, tNormalized = aType |> visit ~visited in - let converter = ArgConverter converter in - (converter, {aName; aType = tNormalized}) - in - let converter, normalized = type0 |> visit ~visited:StringSet.empty in - let finalConverter = - match !circular <> "" with - | true -> CircularC (!circular, converter) - | false -> converter + let tNormalized = aType |> visit ~visited in + {aName; aType = tNormalized} in + let normalized = type0 |> visit ~visited:StringSet.empty in if !Debug.converter then - Log_.item "Converter type0:%s converter:%s\n" - (type0 |> EmitType.typeToString ~config ~typeNameIsInterface) - (finalConverter |> toString); - (finalConverter, normalized) - -let typeGetConverter ~config ~lookupId ~typeNameIsInterface type_ = - type_ - |> typeGetConverterNormalized ~config ~inline:false ~lookupId - ~typeNameIsInterface - |> fst - -let typeGetNormalized ~config ~inline ~lookupId ~typeNameIsInterface type_ = - type_ - |> typeGetConverterNormalized ~config ~inline ~lookupId ~typeNameIsInterface - |> snd - -let rec converterIsIdentity ~config ~toJS converter = - match converter with - | ArrayC c -> c |> converterIsIdentity ~config ~toJS - | CircularC (_, c) -> c |> converterIsIdentity ~config ~toJS - | FunctionC {funArgConverters; retConverter; uncurried} -> - retConverter |> converterIsIdentity ~config ~toJS - && ((not toJS) || uncurried || funArgConverters |> List.length <= 1) - && funArgConverters - |> List.for_all (fun groupedArgConverter -> - match groupedArgConverter with - | ArgConverter argConverter -> - argConverter |> converterIsIdentity ~config ~toJS:(not toJS) - | GroupConverter _ -> false) - | IdentC -> true - | ObjectC fieldsC -> - fieldsC - |> List.for_all (fun {lblJS; lblRE; c} -> - lblJS = lblRE - && - match c with - | OptionC c1 -> c1 |> converterIsIdentity ~config ~toJS - | _ -> c |> converterIsIdentity ~config ~toJS) - | OptionC c -> c |> converterIsIdentity ~config ~toJS - | PromiseC c -> c |> converterIsIdentity ~config ~toJS - | TupleC innerTypesC -> - innerTypesC |> List.for_all (converterIsIdentity ~config ~toJS) - | VariantC {withPayloads; useVariantTables} -> - if not useVariantTables then - withPayloads - |> List.for_all (fun {argConverters} -> - argConverters - |> List.for_all (fun c -> c |> converterIsIdentity ~config ~toJS)) - else false - -let rec apply ~config ~converter ~indent ~nameGen ~toJS ~variantTables value = - match converter with - | _ when converter |> converterIsIdentity ~config ~toJS -> value - | ArrayC c -> - let x = "ArrayItem" |> EmitText.name ~nameGen in - value ^ ".map(function _element(" - ^ (x |> EmitType.ofTypeAny ~config) - ^ ") { return " - ^ (x |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables) - ^ "})" - | CircularC (s, c) -> - value - |> EmitText.addComment - ~comment: - ("WARNING: circular type " ^ s ^ ". Only shallow converter applied.") - |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables - | FunctionC - { - funArgConverters; - componentName; - isHook; - retConverter; - typeVars; - uncurried; - } -> - let resultName = EmitText.resultName ~nameGen in - let indent1 = indent |> Indent.more in - let indent2 = indent1 |> Indent.more in - let mkReturn x = - "const " ^ resultName ^ " = " ^ x ^ ";" - ^ Indent.break ~indent:indent1 - ^ "return " - ^ (resultName - |> apply ~config ~converter:retConverter ~indent:indent2 ~nameGen ~toJS - ~variantTables) - in - let convertArg i groupedArgConverter = - match groupedArgConverter with - | ArgConverter argConverter -> - let varName = i + 1 |> EmitText.argi ~nameGen in - let notToJS = not toJS in - ( [varName], - [ - varName - |> apply ~config ~converter:argConverter ~indent:indent2 ~nameGen - ~toJS:notToJS ~variantTables; - ] ) - | GroupConverter groupConverters -> - let notToJS = not toJS in - if toJS then - let varName = i + 1 |> EmitText.argi ~nameGen in - ( [varName], - groupConverters - |> List.map (fun (label, optional, argConverter) -> - varName - |> EmitText.fieldAccess ~label - |> apply ~config - ~converter: - (match - optional = Optional - && not - (argConverter - |> converterIsIdentity ~config ~toJS:notToJS) - with - | true -> OptionC argConverter - | false -> argConverter) - ~indent:indent2 ~nameGen ~toJS:notToJS ~variantTables) - ) - else - let varNames = - groupConverters - |> List.map (fun (s, _optional, _argConverter) -> - s |> EmitText.arg ~nameGen) - in - let varNamesArr = varNames |> Array.of_list in - let fieldValues = - groupConverters - |> List.mapi (fun i (s, _optional, argConverter) -> - s ^ ":" - ^ (varNamesArr.(i) - |> apply ~config ~converter:argConverter ~indent:indent2 - ~nameGen ~toJS:notToJS ~variantTables)) - |> String.concat ", " - in - (varNames, ["{" ^ fieldValues ^ "}"]) - in - let mkBody bodyArgs = - let useCurry = (not uncurried) && toJS && List.length bodyArgs > 1 in - config.emitImportCurry <- config.emitImportCurry || useCurry; - let functionName = - match isHook with - | true -> "React.createElement" - | false -> value - in - if isHook then config.emitImportReact <- true; - let declareProps, args = - match bodyArgs with - | [props] when isHook -> - let propsName = "$props" |> EmitText.name ~nameGen in - ( Indent.break ~indent:indent1 - ^ "const " ^ propsName ^ " = " ^ props ^ ";", - [value; propsName] ) - | _ -> ("", bodyArgs) - in - declareProps - ^ Indent.break ~indent:indent1 - ^ (functionName |> EmitText.funCall ~args ~useCurry |> mkReturn) - in - let convertedArgs = funArgConverters |> List.mapi convertArg in - let args = convertedArgs |> List.map fst |> List.concat in - let funParams = - args |> List.map (fun v -> v |> EmitType.ofTypeAny ~config) - in - let bodyArgs = convertedArgs |> List.map snd |> List.concat in - EmitText.funDef ~bodyArgs ~functionName:componentName ~funParams ~indent - ~mkBody ~typeVars - | IdentC -> value - | ObjectC fieldsC -> - let simplifyFieldConverted fieldConverter = - match fieldConverter with - | OptionC converter1 when converter1 |> converterIsIdentity ~config ~toJS - -> - IdentC - | _ -> fieldConverter - in - let fieldValues = - fieldsC - |> List.map (fun {lblJS; lblRE; c = fieldConverter} -> - (match toJS with - | true -> lblJS - | false -> lblRE) - ^ ":" - ^ (value - |> EmitText.fieldAccess - ~label: - (match toJS with - | true -> lblRE - | false -> lblJS) - |> apply ~config - ~converter:(fieldConverter |> simplifyFieldConverted) - ~indent ~nameGen ~toJS ~variantTables)) - |> String.concat ", " - in - "{" ^ fieldValues ^ "}" - | OptionC c -> - EmitText.parens - [ - value ^ " == null ? " ^ value ^ " : " - ^ (value - |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables); - ] - | PromiseC c -> - let x = "$promise" |> EmitText.name ~nameGen in - value ^ ".then(function _element(" - ^ (x |> EmitType.ofTypeAny ~config) - ^ ") { return " - ^ (x |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables) - ^ "})" - | TupleC innerTypesC -> - "[" - ^ (innerTypesC - |> List.mapi (fun index c -> - value - |> EmitText.arrayAccess ~index - |> apply ~config ~converter:c ~indent ~nameGen ~toJS ~variantTables) - |> String.concat ", ") - ^ "]" - | VariantC {noPayloads = [case]; withPayloads = []; polymorphic} -> ( - match toJS with - | true -> case |> labelJSToString - | false -> case.label |> Runtime.emitVariantLabel ~polymorphic) - | VariantC variantC -> ( - if variantC.noPayloads <> [] && variantC.useVariantTables then - Hashtbl.replace variantTables (variantC.hash, toJS) variantC; - let convertToString = - match - (not toJS) - && variantC.noPayloads - |> List.exists (fun {labelJS} -> - labelJS = BoolLabel true || labelJS = BoolLabel false) - with - | true -> ".toString()" - | false -> "" - in - let table = variantC.hash |> variantTable ~toJS in - let accessTable v = - match not variantC.useVariantTables with - | true -> v - | false -> table ^ EmitText.array [v ^ convertToString] - in - let convertVariantPayloadToJS ~indent ~argConverters x = - match argConverters with - | [converter] -> - x |> apply ~config ~converter ~indent ~nameGen ~toJS ~variantTables - | _ -> - argConverters - |> List.mapi (fun i converter -> - x - |> Runtime.accessVariant ~index:i - |> apply ~config ~converter ~indent ~nameGen ~toJS ~variantTables) - |> EmitText.array - in - let convertVariantPayloadToRE ~indent ~argConverters x = - match argConverters with - | [converter] -> - [x |> apply ~config ~converter ~indent ~nameGen ~toJS ~variantTables] - | _ -> - argConverters - |> List.mapi (fun i converter -> - x - |> EmitText.arrayAccess ~index:i - |> apply ~config ~converter ~indent ~nameGen ~toJS ~variantTables) - in - match variantC.withPayloads with - | [] -> value |> accessTable - | [{case; inlineRecord; argConverters}] when variantC.unboxed -> ( - let casesWithPayload ~indent = - if toJS then - value - |> Runtime.emitVariantGetPayload ~inlineRecord - ~numArgs:(argConverters |> List.length) - ~polymorphic:variantC.polymorphic - |> convertVariantPayloadToJS ~argConverters ~indent - else - value - |> convertVariantPayloadToRE ~argConverters ~indent - |> Runtime.emitVariantWithPayload ~inlineRecord ~label:case.label - ~polymorphic:variantC.polymorphic - in - match variantC.noPayloads = [] with - | true -> casesWithPayload ~indent - | false -> - EmitText.ifThenElse ~indent - (fun ~indent:_ -> value |> EmitText.typeOfObject) - casesWithPayload - (fun ~indent:_ -> value |> accessTable)) - | _ :: _ -> ( - let convertCaseWithPayload ~indent ~inlineRecord ~argConverters case = - if toJS then - value - |> Runtime.emitVariantGetPayload ~inlineRecord - ~numArgs:(argConverters |> List.length) - ~polymorphic:variantC.polymorphic - |> convertVariantPayloadToJS ~argConverters ~indent - |> Runtime.emitJSVariantWithPayload ~label:(case |> labelJSToString) - ~polymorphic:variantC.polymorphic - else - value - |> Runtime.emitJSVariantGetPayload ~polymorphic:variantC.polymorphic - |> convertVariantPayloadToRE ~argConverters ~indent - |> Runtime.emitVariantWithPayload ~inlineRecord ~label:case.label - ~polymorphic:variantC.polymorphic - in - let switchCases ~indent = - variantC.withPayloads - |> List.map (fun {case; inlineRecord; argConverters} -> - ( (match toJS with - | true -> - case.label - |> Runtime.emitVariantLabel ~polymorphic:variantC.polymorphic - | false -> case |> labelJSToString), - case - |> convertCaseWithPayload ~indent ~inlineRecord ~argConverters - )) - in - let casesWithPayload ~indent = - value - |> (let open Runtime in - (match toJS with - | true -> emitVariantGetLabel - | false -> emitJSVariantGetLabel) - ~polymorphic:variantC.polymorphic) - |> EmitText.switch ~indent ~cases:(switchCases ~indent) - in - match variantC.noPayloads = [] with - | true -> casesWithPayload ~indent - | false -> - EmitText.ifThenElse ~indent - (fun ~indent:_ -> value |> EmitText.typeOfObject) - casesWithPayload - (fun ~indent:_ -> value |> accessTable))) - -let toJS ~config ~converter ~indent ~nameGen ~variantTables value = - value |> apply ~config ~converter ~indent ~nameGen ~variantTables ~toJS:true - -let toReason ~config ~converter ~indent ~nameGen ~variantTables value = - value |> apply ~config ~converter ~indent ~nameGen ~toJS:false ~variantTables + Log_.item "type0:%s \n" + (type0 |> EmitType.typeToString ~config ~typeNameIsInterface); + normalized diff --git a/jscomp/gentype/EmitJs.ml b/jscomp/gentype/EmitJs.ml index 85e273a6c2..57843bbc55 100644 --- a/jscomp/gentype/EmitJs.ml +++ b/jscomp/gentype/EmitJs.ml @@ -68,7 +68,7 @@ let codeItemToString ~config ~typeNameIsInterface (codeItem : CodeItem.t) = | ImportValue {importAnnotation} -> "ImportValue " ^ (importAnnotation.importPath |> ImportPath.dump) -let emitExportType ~emitters ~config ~typeGetNormalized ~typeNameIsInterface +let emitExportType ~emitters ~config ~typeNameIsInterface {CodeItem.loc; nameAs; opaque; type_; typeVars; resolvedTypeName} = let freeTypeVars = TypeVars.free type_ in let isGADT = @@ -86,12 +86,10 @@ let emitExportType ~emitters ~config ~typeGetNormalized ~typeNameIsInterface Some true | _ -> opaque in - let opaque, type_ = + let opaque = match opaque with - | Some opaque -> (opaque, type_) - | None -> - let normalized = type_ |> typeGetNormalized in - (false, normalized) + | Some opaque -> opaque + | None -> false in resolvedTypeName |> ResolvedName.toString |> EmitType.emitExportType ~config ~emitters ~nameAs ~opaque ~type_ @@ -111,33 +109,29 @@ let typeNameIsInterface ~(exportTypeMap : CodeItem.exportTypeMap) | {type_} -> type_ |> typeIsInterface | exception Not_found -> false) -let emitExportFromTypeDeclaration ~config ~emitters ~typeGetNormalized ~env - ~typeNameIsInterface +let emitExportFromTypeDeclaration ~config ~emitters ~env ~typeNameIsInterface (exportFromTypeDeclaration : CodeItem.exportFromTypeDeclaration) = ( env, exportFromTypeDeclaration.exportType - |> emitExportType ~emitters ~config ~typeGetNormalized ~typeNameIsInterface - ) + |> emitExportType ~emitters ~config ~typeNameIsInterface ) -let emitExportFromTypeDeclarations ~config ~emitters ~env ~typeGetNormalized - ~typeNameIsInterface exportFromTypeDeclarations = +let emitExportFromTypeDeclarations ~config ~emitters ~env ~typeNameIsInterface + exportFromTypeDeclarations = exportFromTypeDeclarations |> List.fold_left (fun (env, emitters) -> - emitExportFromTypeDeclaration ~config ~emitters ~env ~typeGetNormalized + emitExportFromTypeDeclaration ~config ~emitters ~env ~typeNameIsInterface) (env, emitters) let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName - ~outputFileRelative ~resolver ~typeGetConverter ~inlineOneLevel - ~typeGetNormalized ~typeNameIsInterface ~variantTables codeItem = + ~outputFileRelative ~resolver ~inlineOneLevel ~typeNameIsInterface codeItem + = if !Debug.codeItems then Log_.item "Code Item: %s\n" (codeItem |> codeItemToString ~config ~typeNameIsInterface); - let indent = Some "" in match codeItem with | ImportValue {asPath; importAnnotation; type_; valueName} -> - let nameGen = EmitText.newNameGen () in let importPath = importAnnotation.importPath in let importFile = importAnnotation.name in let firstNameInPath, restOfPath = @@ -220,7 +214,6 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName | _ -> type_) | _ -> type_ in - let converter = type_ |> typeGetConverter in let valueNameTypeChecked = valueName ^ "TypeChecked" in let emitters = (importedAsName ^ restOfPath) ^ ";" @@ -242,7 +235,6 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName in let emitters = (valueNameTypeChecked - |> Converter.toReason ~config ~converter ~indent ~nameGen ~variantTables |> EmitType.emitTypeCast ~config ~type_ ~typeNameIsInterface) ^ ";" |> EmitType.emitExportConst @@ -261,7 +253,6 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName | ExportValue {docString; moduleAccessPath; originalName; resolvedName; type_} -> let resolvedNameStr = ResolvedName.toString resolvedName in - let nameGen = EmitText.newNameGen () in let importPath = fileName |> ModuleResolver.resolveModule ~config ~importExtension:config.suffix @@ -375,9 +366,7 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName | _ -> (type_, None) in - let converter = type_ |> typeGetConverter in - resolvedName - |> ExportModule.extendExportModules ~converter ~moduleItemsEmitter ~type_; + resolvedName |> ExportModule.extendExportModules ~moduleItemsEmitter ~type_; let emitters = match hookType with | Some {propsType; resolvedTypeName; typeVars} -> @@ -394,15 +383,13 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName in (* For doc gen (https://github.com/cristianoc/genType/issues/342) *) config.emitImportReact <- true; - emitExportType ~emitters ~config ~typeGetNormalized ~typeNameIsInterface - exportType + emitExportType ~emitters ~config ~typeNameIsInterface exportType | _ -> emitters in let emitters = ((fileNameBs |> ModuleName.toString) - ^ "." - ^ (moduleAccessPath |> Runtime.emitModuleAccessPath ~config) - |> Converter.toJS ~config ~converter ~indent ~nameGen ~variantTables) + ^ "." + ^ (moduleAccessPath |> Runtime.emitModuleAccessPath ~config)) ^ ";" |> EmitType.emitExportConst ~config ~docString ~early:false ~emitters ~name ~type_ ~typeNameIsInterface @@ -415,14 +402,12 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName (envWithRequires, emitters) let emitCodeItems ~config ~outputFileRelative ~emitters ~moduleItemsEmitter ~env - ~fileName ~resolver ~typeNameIsInterface ~typeGetConverter ~inlineOneLevel - ~typeGetNormalized ~variantTables codeItems = + ~fileName ~resolver ~typeNameIsInterface ~inlineOneLevel codeItems = codeItems |> List.fold_left (fun (env, emitters) -> emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName - ~outputFileRelative ~resolver ~typeGetConverter ~inlineOneLevel - ~typeGetNormalized ~typeNameIsInterface ~variantTables) + ~outputFileRelative ~resolver ~inlineOneLevel ~typeNameIsInterface) (env, emitters) let emitRequires ~importedValueOrComponent ~early ~config ~requires emitters = @@ -433,43 +418,9 @@ let emitRequires ~importedValueOrComponent ~early ~config ~requires emitters = ~moduleName) requires emitters -let emitVariantTables ~emitters variantTables = - let typeAnnotation = ": { [key: string]: any }" in - let emitTable ~table ~toJS (variantC : Converter.variantC) = - "const " ^ table ^ typeAnnotation ^ " = {" - ^ (variantC.noPayloads - |> List.map (fun case -> - let js = case |> labelJSToString ~alwaysQuotes:(not toJS) in - let re = - case.label - |> Runtime.emitVariantLabel ~polymorphic:variantC.polymorphic - in - match toJS with - | true -> (re |> EmitText.quotesIfRequired) ^ ": " ^ js - | false -> js ^ ": " ^ re) - |> String.concat ", ") - ^ "};" - in - Hashtbl.fold - (fun (_, toJS) variantC l -> (variantC, toJS) :: l) - variantTables [] - |> List.sort (fun (variantC1, toJS1) (variantC2, toJS2) -> - let n = compare variantC1.Converter.hash variantC2.hash in - match n <> 0 with - | true -> n - | false -> compare toJS2 toJS1) - |> List.fold_left - (fun emitters (variantC, toJS) -> - variantC - |> emitTable - ~table:(variantC.Converter.hash |> variantTable ~toJS) - ~toJS - |> Emitters.requireEarly ~emitters) - emitters - let typeGetInlined ~config ~exportTypeMap type_ = type_ - |> Converter.typeGetNormalized ~config ~inline:true + |> Converter.typeGetInlined ~config ~lookupId:(fun s -> exportTypeMap |> StringMap.find s) ~typeNameIsInterface:(fun _ -> false) @@ -513,7 +464,9 @@ let rec readCmtFilesRecursively ~config ~env ~inputCmtTranslateTypeDeclarations let exportTypeMapFromCmt = typeDeclarations |> createExportTypeMap ~config ~fromCmtReadRecursively:true - ~file:(cmtFile |> Filename.basename |> Filename.chop_extension) + ~file: + (cmtFile |> Filename.basename + |> (Filename.chop_extension [@doesNotRaise])) in let cmtToExportTypeMap = env.cmtToExportTypeMap |> StringMap.add cmtFile exportTypeMapFromCmt @@ -662,7 +615,6 @@ let emitTranslationAsString ~config ~fileName ~inputCmtTranslateTypeDeclarations importedValueOrComponent = false; } in - let variantTables = Hashtbl.create 1 in let exportTypeMap, annotatedSet = translation.typeDeclarations |> createExportTypeMap ~config @@ -692,17 +644,6 @@ let emitTranslationAsString ~config ~fileName ~inputCmtTranslateTypeDeclarations try exportTypeMap |> StringMap.find s with Not_found -> env.exportTypeMapFromOtherFiles |> StringMap.find s in - let typeGetNormalized__ ~inline ~env type_ = - type_ - |> Converter.typeGetNormalized ~config ~inline ~lookupId:(lookupId_ ~env) - ~typeNameIsInterface:(typeNameIsInterface ~env) - in - let typeGetNormalized_ = typeGetNormalized__ ~inline:false in - let typeGetConverter_ ~env type_ = - type_ - |> Converter.typeGetConverter ~config ~lookupId:(lookupId_ ~env) - ~typeNameIsInterface:(typeNameIsInterface ~env) - in let emitters = Emitters.initial and moduleItemsEmitter = ExportModule.createModuleItemsEmitter () and env = initialEnv in @@ -715,8 +656,7 @@ let emitTranslationAsString ~config ~fileName ~inputCmtTranslateTypeDeclarations in let env, emitters = exportFromTypeDeclarations - |> emitExportFromTypeDeclarations ~config ~emitters - ~typeGetNormalized:(typeGetNormalized_ ~env) ~env + |> emitExportFromTypeDeclarations ~config ~emitters ~env ~typeNameIsInterface:(typeNameIsInterface ~env) in let inlineOneLevel type_ = @@ -742,9 +682,7 @@ let emitTranslationAsString ~config ~fileName ~inputCmtTranslateTypeDeclarations translation.codeItems |> emitCodeItems ~config ~emitters ~moduleItemsEmitter ~env ~fileName ~outputFileRelative ~resolver ~inlineOneLevel - ~typeGetNormalized:(typeGetNormalized_ ~env) - ~typeGetConverter:(typeGetConverter_ ~env) - ~typeNameIsInterface:(typeNameIsInterface ~env) ~variantTables + ~typeNameIsInterface:(typeNameIsInterface ~env) in let emitters = match config.emitImportReact with @@ -760,7 +698,6 @@ let emitTranslationAsString ~config ~fileName ~inputCmtTranslateTypeDeclarations | false -> env in let finalEnv = env in - let emitters = variantTables |> emitVariantTables ~emitters in let emitters = moduleItemsEmitter |> ExportModule.emitAllModuleItems ~config ~emitters ~fileName diff --git a/jscomp/gentype/EmitText.ml b/jscomp/gentype/EmitText.ml index 0c208daa30..9ec5c1ec3b 100644 --- a/jscomp/gentype/EmitText.ml +++ b/jscomp/gentype/EmitText.ml @@ -1,71 +1,13 @@ type nameGen = (string, int) Hashtbl.t -let name ~nameGen s = - match Hashtbl.find nameGen s with - | n -> - Hashtbl.replace nameGen s (n + 1); - s ^ string_of_int (n + 1) - | exception Not_found -> - Hashtbl.replace nameGen s 0; - s - let parens xs = "(" ^ (xs |> String.concat ", ") ^ ")" -let arg ~nameGen x = "Arg" ^ x |> name ~nameGen -let argi ~nameGen i = "Arg" ^ (i |> string_of_int) |> name ~nameGen -let array xs = "[" ^ (xs |> String.concat ", ") ^ "]" let comment x = "/* " ^ x ^ " */" -let curry ~args ~numArgs name = - match numArgs with - | 0 | 1 -> name ^ parens args - | (2 | 3 | 4 | 5 | 6 | 7 | 8) as n -> - "Curry._" ^ (n |> string_of_int) ^ parens ([name] @ args) - | _ -> "Curry.app" ^ parens [name; args |> array] - -let funCall ~args ~useCurry name = - match useCurry with - | true -> name |> curry ~args ~numArgs:(args |> List.length) - | false -> name ^ parens args - let genericsString ~typeVars = match typeVars == [] with | true -> "" | false -> "<" ^ String.concat "," typeVars ^ ">" -let funDef ~bodyArgs ~functionName ~funParams ~indent ~mkBody ~typeVars = - "function " - ^ (match functionName with - | None -> "" - | Some name -> name) - ^ genericsString ~typeVars ^ (funParams |> parens) ^ " {" - ^ (bodyArgs |> mkBody) ^ Indent.break ~indent ^ "}" - -let ifThenElse ~indent if_ then_ else_ = - let indent1 = indent |> Indent.more in - if_ ~indent:indent1 ^ Indent.break ~indent ^ "? " ^ then_ ~indent:indent1 - ^ Indent.break ~indent ^ ": " ^ else_ ~indent:indent1 - -let newNameGen () = Hashtbl.create 1 let quotes x = "\"" ^ x ^ "\"" -let quotesIfRequired x = - match String.length x > 0 && x.[0] = '"' with - | true -> x - | false -> quotes x - -let resultName ~nameGen = "result" |> name ~nameGen - -let switch ~indent ~cases expr = - let lastCase = (cases |> List.length) - 1 in - cases - |> List.mapi (fun i (label, code) -> - if i = lastCase then code - else - expr ^ "===" ^ label ^ Indent.break ~indent ^ "? " ^ code - ^ Indent.break ~indent ^ ": ") - |> String.concat "" - -let typeOfObject x = "typeof(" ^ x ^ ")" ^ " === " ^ "'object'" -let addComment ~comment x = "\n/* " ^ comment ^ " */\n " ^ x -let arrayAccess ~index value = value ^ "[" ^ string_of_int index ^ "]" let fieldAccess ~label value = value ^ "." ^ label diff --git a/jscomp/gentype/EmitType.ml b/jscomp/gentype/EmitType.ml index c24f110b2e..caa4756f77 100644 --- a/jscomp/gentype/EmitType.ml +++ b/jscomp/gentype/EmitType.ml @@ -60,7 +60,6 @@ let typeReactRef ~type_ = { mutable_ = Mutable; nameJS = reactRefCurrent; - nameRE = reactRefCurrent; optional = Mandatory; type_ = Null type_; }; @@ -68,8 +67,8 @@ let typeReactRef ~type_ = let isTypeReactRef ~fields = match fields with - | [{mutable_ = Mutable; nameJS; nameRE; optional = Mandatory}] -> - nameJS == reactRefCurrent && nameJS == nameRE + | [{mutable_ = Mutable; nameJS; optional = Mandatory}] -> + nameJS == reactRefCurrent | _ -> false let isTypeFunctionComponent ~fields type_ = @@ -182,7 +181,6 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface { mutable_ = Mutable; nameJS = name; - nameRE = name; optional = Mandatory; type_ = TypeVar value; } @@ -193,20 +191,41 @@ let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface let payloadsRendered = payloads |> List.map (fun {case; t = type_} -> - let typeRendered = - type_ - |> renderType ~config ~indent ~typeNameIsInterface ~inFunType + let render t = + t |> renderType ~config ~indent ~typeNameIsInterface ~inFunType in - match unboxed with - | true -> typeRendered - | false -> + let tagField = + case |> labelJSToString + |> field ~name:(Runtime.jsVariantTag ~polymorphic:false) + in + match (unboxed, type_) with + | true, type_ -> type_ |> render + | false, type_ when polymorphic -> + (* poly variant *) [ case |> labelJSToString |> field ~name:(Runtime.jsVariantTag ~polymorphic); - typeRendered + type_ |> render |> field ~name:(Runtime.jsVariantValue ~polymorphic); ] - |> fields) + |> fields + | false, Object (_, flds) -> + (* inlined record *) + tagField :: flds |> fields + | false, type_ -> + (* ordinary variant *) + let payloads = + match type_ with + | Tuple ts -> ts + | _ -> [type_] + in + let flds = + tagField + :: Ext_list.mapi payloads (fun n t -> + t |> render + |> field ~name:(Runtime.jsVariantPayloadTag ~n)) + in + flds |> fields) in let rendered = inheritsRendered @ noPayloadsRendered @ payloadsRendered in let indent1 = rendered |> Indent.heuristicVariants ~indent in @@ -288,7 +307,7 @@ and renderFunType ~config ~indent ~inFunType ~typeNameIsInterface ~typeVars let typeToString ~config ~typeNameIsInterface type_ = type_ |> renderType ~config ~typeNameIsInterface ~inFunType:false -let ofType ~config ?(typeNameIsInterface = fun _ -> false) ~type_ s = +let ofType ~config ~typeNameIsInterface ~type_ s = s ^ ": " ^ (type_ |> typeToString ~config ~typeNameIsInterface) let emitExportConst ~early ?(comment = "") ~config ?(docString = "") ~emitters @@ -425,7 +444,5 @@ let emitImportTypeAs ~emitters ~config ~typeName ~asTypeName ^ "} from '" ^ importPathString ^ "';" |> Emitters.import ~emitters -let ofTypeAny ~config s = s |> ofType ~config ~type_:typeAny - let emitTypeCast ~config ~type_ ~typeNameIsInterface s = s ^ " as " ^ (type_ |> typeToString ~config ~typeNameIsInterface) diff --git a/jscomp/gentype/ExportModule.ml b/jscomp/gentype/ExportModule.ml index 569526314b..467166f143 100644 --- a/jscomp/gentype/ExportModule.ml +++ b/jscomp/gentype/ExportModule.ml @@ -2,29 +2,17 @@ open GenTypeCommon type exportModuleItem = (string, exportModuleValue) Hashtbl.t -and exportModuleValue = - | S of string * type_ * Converter.t - | M of exportModuleItem +and exportModuleValue = S of string * type_ | M of exportModuleItem type exportModuleItems = (string, exportModuleItem) Hashtbl.t -type types = {typeForValue: type_; typeForType: type_; needsConversion: bool} +type types = {typeForValue: type_; typeForType: type_} -type fieldInfo = { - fieldForValue: field; - fieldForType: field; - needsConversion: bool; -} +type fieldInfo = {fieldForValue: field; fieldForType: field} let rec exportModuleValueToType ~config exportModuleValue = match exportModuleValue with - | S (s, type_, converter) -> - { - typeForValue = ident s; - typeForType = type_; - needsConversion = - not (converter |> Converter.converterIsIdentity ~config ~toJS:true); - } + | S (s, type_) -> {typeForValue = ident s; typeForType = type_} | M exportModuleItem -> let fieldsInfo = exportModuleItem |> exportModuleItemToFields ~config in let fieldsForValue = @@ -33,45 +21,37 @@ let rec exportModuleValueToType ~config exportModuleValue = let fieldsForType = fieldsInfo |> List.map (fun {fieldForType} -> fieldForType) in - let needsConversion = - fieldsInfo - |> List.fold_left - (fun acc {needsConversion} -> acc || needsConversion) - false - in { typeForValue = Object (Open, fieldsForValue); typeForType = Object (Open, fieldsForType); - needsConversion; } and exportModuleItemToFields = (fun ~config exportModuleItem -> Hashtbl.fold (fun fieldName exportModuleValue fields -> - let {typeForValue; typeForType; needsConversion} = + let {typeForValue; typeForType} = exportModuleValue |> exportModuleValueToType ~config in let fieldForType = { mutable_ = Mutable; nameJS = fieldName; - nameRE = fieldName; optional = Mandatory; type_ = typeForType; } in let fieldForValue = {fieldForType with type_ = typeForValue} in - {fieldForValue; fieldForType; needsConversion} :: fields) + {fieldForValue; fieldForType} :: fields) exportModuleItem [] : config:Config.t -> exportModuleItem -> fieldInfo list) -let rec extendExportModuleItem x ~converter - ~(exportModuleItem : exportModuleItem) ~type_ ~valueName = +let rec extendExportModuleItem x ~(exportModuleItem : exportModuleItem) ~type_ + ~valueName = match x with | [] -> () | [fieldName] -> - Hashtbl.replace exportModuleItem fieldName (S (valueName, type_, converter)) + Hashtbl.replace exportModuleItem fieldName (S (valueName, type_)) | fieldName :: rest -> let innerExportModuleItem = match Hashtbl.find exportModuleItem fieldName with @@ -83,11 +63,11 @@ let rec extendExportModuleItem x ~converter innerExportModuleItem in rest - |> extendExportModuleItem ~converter ~exportModuleItem:innerExportModuleItem - ~valueName ~type_ + |> extendExportModuleItem ~exportModuleItem:innerExportModuleItem ~valueName + ~type_ -let extendExportModuleItems x ~converter - ~(exportModuleItems : exportModuleItems) ~type_ ~valueName = +let extendExportModuleItems x ~(exportModuleItems : exportModuleItems) ~type_ + ~valueName = match x with | [] -> assert false | [_valueName] -> () @@ -100,8 +80,7 @@ let extendExportModuleItems x ~converter Hashtbl.replace exportModuleItems moduleName exportModuleItem; exportModuleItem in - rest - |> extendExportModuleItem ~converter ~exportModuleItem ~type_ ~valueName + rest |> extendExportModuleItem ~exportModuleItem ~type_ ~valueName let createModuleItemsEmitter = (fun () -> Hashtbl.create 1 : unit -> exportModuleItems) @@ -115,27 +94,22 @@ let emitAllModuleItems ~config ~emitters ~fileName emitters |> rev_fold (fun moduleName exportModuleItem emitters -> - let {typeForType; needsConversion} = + let {typeForType} = M exportModuleItem |> exportModuleValueToType ~config in - if !Debug.codeItems then - Log_.item "EmitModule %s needsConversion:%b@." moduleName - needsConversion; - if needsConversion then emitters - else - let emittedModuleItem = - ModuleName.forInnerModule ~fileName ~innerModuleName:moduleName - |> ModuleName.toString - in - emittedModuleItem - |> EmitType.emitExportConst ~early:false ~config ~emitters - ~name:moduleName ~type_:typeForType - ~typeNameIsInterface:(fun _ -> false)) + if !Debug.codeItems then Log_.item "EmitModule %s @." moduleName; + let emittedModuleItem = + ModuleName.forInnerModule ~fileName ~innerModuleName:moduleName + |> ModuleName.toString + in + emittedModuleItem + |> EmitType.emitExportConst ~early:false ~config ~emitters + ~name:moduleName ~type_:typeForType ~typeNameIsInterface:(fun _ -> + false)) exportModuleItems -let extendExportModules ~converter ~(moduleItemsEmitter : exportModuleItems) - ~type_ resolvedName = +let extendExportModules ~(moduleItemsEmitter : exportModuleItems) ~type_ + resolvedName = resolvedName |> ResolvedName.toList - |> extendExportModuleItems ~converter ~exportModuleItems:moduleItemsEmitter - ~type_ + |> extendExportModuleItems ~exportModuleItems:moduleItemsEmitter ~type_ ~valueName:(resolvedName |> ResolvedName.toString) diff --git a/jscomp/gentype/GenTypeCommon.ml b/jscomp/gentype/GenTypeCommon.ml index f8b85fd3c0..a77371c4c3 100644 --- a/jscomp/gentype/GenTypeCommon.ml +++ b/jscomp/gentype/GenTypeCommon.ml @@ -18,7 +18,7 @@ type case = {label: string; labelJS: labelJS} let isJSSafePropertyName name = name = "" - || (match name.[0] with + || (match name.[0] [@doesNotRaise] with | 'A' .. 'z' -> true | _ -> false) && name @@ -26,34 +26,28 @@ let isJSSafePropertyName name = | 'A' .. 'z' | '0' .. '9' -> true | _ -> false) -let labelJSToString ?(alwaysQuotes = false) case = - let addQuotes x = - match alwaysQuotes with - | true -> x |> EmitText.quotes - | false -> x - in +let labelJSToString case = let isNumber s = let len = String.length s in len > 0 && (match len > 1 with - | true -> s.[0] > '0' + | true -> (s.[0] [@doesNotRaise]) > '0' | false -> true) && let res = ref true in for i = 0 to len - 1 do - match s.[i] with + match s.[i] [@doesNotRaise] with | '0' .. '9' -> () | _ -> res := false done; res.contents in match case.labelJS with - | BoolLabel b -> b |> string_of_bool |> addQuotes - | FloatLabel s -> s |> addQuotes - | IntLabel i -> i |> addQuotes + | BoolLabel b -> b |> string_of_bool + | FloatLabel s -> s + | IntLabel i -> i | StringLabel s -> - if s = case.label && isNumber s then s |> addQuotes - else s |> EmitText.quotes + if s = case.label && isNumber s then s else s |> EmitText.quotes type closedFlag = Open | Closed @@ -78,7 +72,6 @@ and argType = {aName: string; aType: type_} and field = { mutable_: mutable_; nameJS: string; - nameRE: string; optional: optional; type_: type_; } @@ -95,7 +88,6 @@ and ident = {builtin: bool; name: string; typeArgs: type_ list} and variant = { bsStringOrInt: bool; - hash: int; inherits: type_ list; noPayloads: case list; payloads: payload list; @@ -105,22 +97,6 @@ and variant = { and payload = {case: case; inlineRecord: bool; numArgs: int; t: type_} -let typeIsObject type_ = - match type_ with - | Array _ -> true - | Dict _ -> true - | Function _ -> false - | GroupOfLabeledArgs _ -> false - | Ident _ -> false - | Null _ -> false - | Nullable _ -> false - | Object _ -> true - | Option _ -> false - | Promise _ -> true - | Tuple _ -> true - | TypeVar _ -> false - | Variant _ -> false - type label = Nolabel | Label of string | OptLabel of string type dep = @@ -186,20 +162,8 @@ let rec depToResolvedName (dep : dep) = | Dot (p, s) -> ResolvedName.dot s (p |> depToResolvedName) let createVariant ~bsStringOrInt ~inherits ~noPayloads ~payloads ~polymorphic = - let hash = - noPayloads - |> List.map (fun case -> (case.label, case.labelJS)) - |> Array.of_list |> Hashtbl.hash - in let unboxed = payloads = [] in - Variant - {bsStringOrInt; hash; inherits; noPayloads; payloads; polymorphic; unboxed} - -let variantTable hash ~toJS = - (match toJS with - | true -> "$$toJS" - | false -> "$$toRE") - ^ string_of_int hash + Variant {bsStringOrInt; inherits; noPayloads; payloads; polymorphic; unboxed} let ident ?(builtin = true) ?(typeArgs = []) name = Ident {builtin; name; typeArgs} @@ -248,7 +212,7 @@ module NodeFilename = struct let concat dirname filename = let isDirSep s i = - let c = s.[i] in + let c = (s.[i] [@doesNotRaise]) in c = '/' || c = '\\' || c = ':' in let l = length dirname in diff --git a/jscomp/gentype/GenTypeConfig.ml b/jscomp/gentype/GenTypeConfig.ml index 9f8fdfda80..6e63c7a344 100644 --- a/jscomp/gentype/GenTypeConfig.ml +++ b/jscomp/gentype/GenTypeConfig.ml @@ -76,7 +76,9 @@ let getShims map = | Ext_json_types.Str {str} -> let fromTo = str |> String.split_on_char '=' |> Array.of_list in assert (Array.length fromTo == 2); - shims := (fromTo.(0), fromTo.(1)) :: !shims + shims := + ((fromTo.(0) [@doesNotRaise]), (fromTo.(1) [@doesNotRaise])) + :: !shims | _ -> ()) | _ -> ()); !shims diff --git a/jscomp/gentype/GenTypeMain.ml b/jscomp/gentype/GenTypeMain.ml index 8701ada832..7269de6451 100644 --- a/jscomp/gentype/GenTypeMain.ml +++ b/jscomp/gentype/GenTypeMain.ml @@ -126,7 +126,9 @@ let processCmtFile cmt = inputCMT |> cmtCheckAnnotations ~checkAnnotation in if isInterface then - let cmtFileImpl = (cmtFile |> Filename.chop_extension) ^ ".cmt" in + let cmtFileImpl = + (cmtFile |> (Filename.chop_extension [@doesNotRaise])) ^ ".cmt" + in let inputCMTImpl = readCmt cmtFileImpl in let hasGenTypeAnnotationsImpl = inputCMTImpl @@ -168,3 +170,4 @@ let processCmtFile cmt = else ( outputFile |> GeneratedFiles.logFileAction NoMatch; if Sys.file_exists outputFile then Sys.remove outputFile) + [@@live] diff --git a/jscomp/gentype/GeneratedFiles.ml b/jscomp/gentype/GeneratedFiles.ml index 69ff5a30aa..5b22a99b3d 100644 --- a/jscomp/gentype/GeneratedFiles.ml +++ b/jscomp/gentype/GeneratedFiles.ml @@ -27,7 +27,7 @@ let readLines (file : string) : string list = done; [] with End_of_file -> - close_in chan; + close_in chan [@doesNotRaise]; !lines |> List.rev in finished_lines @@ -37,7 +37,7 @@ let readFile (file : string) : string = String.concat "\n" (readLines file) let writeFile (filePath : string) (contents : string) = let outFile = open_out filePath in output_string outFile contents; - close_out outFile + close_out outFile [@doesNotRaise] let writeFileIfRequired ~outputFile ~fileContents = if Sys.file_exists outputFile then diff --git a/jscomp/gentype/ModuleName.ml b/jscomp/gentype/ModuleName.ml index 90a745018d..0ffb8f15be 100644 --- a/jscomp/gentype/ModuleName.ml +++ b/jscomp/gentype/ModuleName.ml @@ -13,7 +13,9 @@ let sanitizeId s = | c -> c) else s in - if s <> "" && s.[0] >= 'A' && s.[0] <= 'z' then s else "_" ^ s + if s <> "" && (s.[0] [@doesNotRaise]) >= 'A' && (s.[0] [@doesNotRaise]) <= 'z' + then s + else "_" ^ s let forBsFile s = sanitizeId s ^ "BS" diff --git a/jscomp/gentype/NamedArgs.ml b/jscomp/gentype/NamedArgs.ml index e4731a3609..18b39ab58d 100644 --- a/jscomp/gentype/NamedArgs.ml +++ b/jscomp/gentype/NamedArgs.ml @@ -14,25 +14,13 @@ let rec groupReversed ~revCurGroup ~revResult labeledTypes = (* Add it to the current group, not result. *) groupReversed ~revCurGroup: - ({ - mutable_ = Immutable; - nameJS = name; - nameRE = name; - optional = Optional; - type_; - } + ({mutable_ = Immutable; nameJS = name; optional = Optional; type_} :: revCurGroup) ~revResult tl | _, (Label name, type_) :: tl -> groupReversed ~revCurGroup: - ({ - mutable_ = Immutable; - nameJS = name; - nameRE = name; - optional = Mandatory; - type_; - } + ({mutable_ = Immutable; nameJS = name; optional = Mandatory; type_} :: revCurGroup) ~revResult tl | [], [] -> revResult diff --git a/jscomp/gentype/Paths.ml b/jscomp/gentype/Paths.ml index 67d5724f39..c1c35b0c24 100644 --- a/jscomp/gentype/Paths.ml +++ b/jscomp/gentype/Paths.ml @@ -5,25 +5,28 @@ let concat = Filename.concat let handleNamespace cmt = let cutAfterDash s = match String.index s '-' with - | n -> String.sub s 0 n + | n -> String.sub s 0 n [@doesNotRaise] | exception Not_found -> s in let noDir = Filename.basename cmt = cmt in - if noDir then cmt |> Filename.chop_extension |> cutAfterDash + if noDir then cmt |> (Filename.chop_extension [@doesNotRaise]) |> cutAfterDash else let dir = cmt |> Filename.dirname in let base = - cmt |> Filename.basename |> Filename.chop_extension |> cutAfterDash + cmt |> Filename.basename |> (Filename.chop_extension [@doesNotRaise]) + |> cutAfterDash in Filename.concat dir base let findNameSpace cmt = let keepAfterDash s = match String.index s '-' with - | n -> Some (String.sub s (n + 1) (String.length s - n - 1)) + | n -> + Some ((String.sub s (n + 1) [@doesNotRaise]) (String.length s - n - 1)) | exception Not_found -> None in - cmt |> Filename.basename |> Filename.chop_extension |> keepAfterDash + cmt |> Filename.basename |> (Filename.chop_extension [@doesNotRaise]) + |> keepAfterDash let getOutputFileRelative ~config cmt = (cmt |> handleNamespace) ^ EmitType.outputFileSuffix ~config @@ -43,9 +46,11 @@ let getCmtFile cmt = let baseName = pathCmt |> Filename.basename in Filename.concat dirName (baseName |> String.uncapitalize_ascii) in - let pathCmti = Filename.chop_extension pathCmt ^ ".cmti" in + let pathCmti = + (Filename.chop_extension pathCmt [@doesNotRaise]) ^ ".cmti" + in let pathCmtiLowerCase = - Filename.chop_extension pathCmtLowerCase ^ ".cmti" + (Filename.chop_extension pathCmtLowerCase [@doesNotRaise]) ^ ".cmti" in if Sys.file_exists pathCmtiLowerCase then pathCmtiLowerCase else if Sys.file_exists pathCmti then pathCmti @@ -62,27 +67,4 @@ let getBsConfigFile ~projectRoot = | true -> Some bsconfig | false -> None -(** Find the relative path from /.../bs/lib - e.g. /foo/bar/bs/lib/src/Hello.res --> src/Hello.res *) -let relativePathFromBsLib fileName = - if Filename.is_relative fileName then fileName - else - let rec pathToList path = - let isRoot = path |> Filename.basename = path in - match isRoot with - | true -> [path] - | false -> - (path |> Filename.basename) :: (path |> Filename.dirname |> pathToList) - in - let rec fromLibBs ~acc reversedList = - match reversedList with - | "bs" :: "lib" :: _ -> acc - | dir :: dirs -> fromLibBs ~acc:(dir :: acc) dirs - | [] -> [] - in - fileName |> pathToList |> fromLibBs ~acc:[] |> fun l -> - match l with - | [] -> fileName - | root :: dirs -> dirs |> List.fold_left concat root - let readConfig ~namespace = Config.readConfig ~getBsConfigFile ~namespace diff --git a/jscomp/gentype/Runtime.ml b/jscomp/gentype/Runtime.ml index 97a3ace75c..9fef385103 100644 --- a/jscomp/gentype/Runtime.ml +++ b/jscomp/gentype/Runtime.ml @@ -24,75 +24,21 @@ let rec emitModuleAccessPath ~config moduleAccessPath = | Dot (p, moduleItem) -> p |> emitModuleAccessPath ~config |> EmitText.fieldAccess ~label:moduleItem -let emitVariantLabel ~polymorphic label = - if polymorphic then label |> EmitText.quotes else label - -module VariantsAsObjects = struct - let polyVariantLabelName = "NAME" - - let label ~polymorphic = - match polymorphic with - | true -> polyVariantLabelName - | false -> "TAG" - - let indexLabel i = "_" ^ string_of_int i -end - -let emitVariantGetLabel ~polymorphic x = - x |> EmitText.fieldAccess ~label:(VariantsAsObjects.label ~polymorphic) - -let accessVariant ~index x = - x |> EmitText.fieldAccess ~label:(index |> VariantsAsObjects.indexLabel) - -let emitVariantGetPayload ~inlineRecord ~numArgs ~polymorphic x = - if polymorphic then x |> EmitText.fieldAccess ~label:"VAL" - else if numArgs = 1 then - if inlineRecord then - (* inline record is repressented as record plus a tag: - here pass it unchanged as if it was just a record (the payload) - *) x - else x |> accessVariant ~index:0 - else (* payload items extracted later when numArgs != 1 *) x - -let emitVariantWithPayload ~inlineRecord ~label ~polymorphic args = - match args with - | [arg] when polymorphic -> - "{" ^ VariantsAsObjects.polyVariantLabelName ^ ": " - ^ (label |> emitVariantLabel ~polymorphic) - ^ ", VAL: " ^ arg ^ "}" - | [arg] when inlineRecord -> - (* inline records are represented as records plus a `TAG` *) - "Object.assign({TAG: " ^ label ^ "}, " ^ arg ^ ")" - | _ -> - "{TAG: " ^ label ^ ", " - ^ (args - |> List.mapi (fun i s -> (i |> VariantsAsObjects.indexLabel) ^ ":" ^ s) - |> String.concat ", ") - ^ "}" ^ " as any" - let jsVariantTag ~polymorphic = match polymorphic with | true -> "NAME" - | false -> "tag" + | false -> "TAG" + +let jsVariantPayloadTag ~n = "_" ^ string_of_int n let jsVariantValue ~polymorphic = match polymorphic with | true -> "VAL" | false -> "value" -let emitJSVariantGetLabel ~polymorphic x = - x |> EmitText.fieldAccess ~label:(jsVariantTag ~polymorphic) - -let emitJSVariantGetPayload ~polymorphic x = - x |> EmitText.fieldAccess ~label:(jsVariantValue ~polymorphic) - -let emitJSVariantWithPayload ~label ~polymorphic x = - "{" ^ jsVariantTag ~polymorphic ^ ":" ^ label ^ ", " - ^ jsVariantValue ~polymorphic - ^ ":" ^ x ^ "}" - let isMutableObjectField name = - String.length name >= 2 && String.sub name (String.length name - 2) 2 = "#=" + String.length name >= 2 + && (String.sub name (String.length name - 2) 2 [@doesNotRaise]) = "#=" (** Mutable fields, i.e. fields annotated "[@bs.set]" are represented as extra fields called "fieldName#=" @@ -173,12 +119,15 @@ module Mangle = struct *) let translate x = let len = x |> String.length in - if len > 2 && x.[len - 1] = '_' && x.[len - 2] = '_' then - (* "foo__" -> "foo" *) String.sub x 0 (len - 2) - else if len > 1 && x.[0] = '_' then - if x.[1] >= 'A' && x.[1] <= 'Z' then + if + len > 2 + && (x.[len - 1] [@doesNotRaise]) = '_' + && (x.[len - 2] [@doesNotRaise]) = '_' + then (* "foo__" -> "foo" *) String.sub x 0 (len - 2) [@doesNotRaise] + else if len > 1 && (x.[0] [@doesNotRaise]) = '_' then + if (x.[1] [@doesNotRaise]) >= 'A' && (x.[1] [@doesNotRaise]) <= 'Z' then (* "_Uppercase" => "Uppercase"s *) - String.sub x 1 (len - 1) + String.sub x 1 (len - 1) [@doesNotRaise] else (* "_rec" -> "rec" *) match Hashtbl.find table x with diff --git a/jscomp/gentype/Runtime.mli b/jscomp/gentype/Runtime.mli index 941bc62c5a..43867f5e35 100644 --- a/jscomp/gentype/Runtime.mli +++ b/jscomp/gentype/Runtime.mli @@ -5,25 +5,9 @@ type recordValue type moduleItem type moduleAccessPath = Root of string | Dot of moduleAccessPath * moduleItem -val accessVariant : index:int -> string -> string val checkMutableObjectField : previousName:string -> name:string -> bool val default : string val emitModuleAccessPath : config:Config.t -> moduleAccessPath -> string -val emitJSVariantGetLabel : polymorphic:bool -> string -> string -val emitJSVariantGetPayload : polymorphic:bool -> string -> string - -val emitJSVariantWithPayload : - label:string -> polymorphic:bool -> string -> string - -val emitVariantGetLabel : polymorphic:bool -> string -> string - -val emitVariantGetPayload : - inlineRecord:bool -> numArgs:int -> polymorphic:bool -> string -> string - -val emitVariantLabel : polymorphic:bool -> string -> string - -val emitVariantWithPayload : - inlineRecord:bool -> label:string -> polymorphic:bool -> string list -> string val isMutableObjectField : string -> bool val mangleObjectField : string -> string @@ -32,4 +16,5 @@ val newRecordValue : unboxed:bool -> recordGen -> recordValue val recordGen : unit -> recordGen val recordValueToString : recordValue -> string val jsVariantTag : polymorphic:bool -> string +val jsVariantPayloadTag : n:int -> string val jsVariantValue : polymorphic:bool -> string diff --git a/jscomp/gentype/TranslateCoreType.ml b/jscomp/gentype/TranslateCoreType.ml index 5053d3d0ac..6af7576b62 100644 --- a/jscomp/gentype/TranslateCoreType.ml +++ b/jscomp/gentype/TranslateCoreType.ml @@ -93,12 +93,7 @@ let rec translateArrowType ~config ~typeVarsGen ~noFunctionReturnDependencies |> translateArrowType ~config ~typeVarsGen ~noFunctionReturnDependencies ~typeEnv ~revArgDeps:nextRevDeps ~revArgs: - (( OptLabel - (match asLabel = "" with - | true -> lbl |> Runtime.mangleObjectField - | false -> asLabel), - type1 ) - :: revArgs)) + ((OptLabel (lbl |> Runtime.mangleObjectField), type1) :: revArgs)) | _ -> let {dependencies; type_ = retType} = coreType |> translateCoreType_ ~config ~typeVarsGen ~typeEnv diff --git a/jscomp/gentype/TranslateStructure.ml b/jscomp/gentype/TranslateStructure.ml index 0b0bcdd29a..b7ec562c76 100644 --- a/jscomp/gentype/TranslateStructure.ml +++ b/jscomp/gentype/TranslateStructure.ml @@ -20,7 +20,8 @@ let rec addAnnotationsToTypes_ ~config ~(expr : Typedtree.expression) match path |> TranslateTypeExprFromTypes.pathToList |> List.rev with | ["Js"; "Internal"; fn_mk] when (* Uncurried function definition uses Js.Internal.fn_mkX(...) *) - String.length fn_mk >= 5 && String.sub fn_mk 0 5 = "fn_mk" -> + String.length fn_mk >= 5 + && (String.sub fn_mk 0 5 [@doesNotRaise]) = "fn_mk" -> argTypes |> addAnnotationsToTypes_ ~config ~expr:expr1 | _ -> argTypes) | _ -> argTypes @@ -44,11 +45,11 @@ and addAnnotationsToFields ~config (expr : Typedtree.expression) let nextFields1, types1 = addAnnotationsToFields ~config c_rhs nextFields argTypes in - let nameJS, nameRE = + let name = TranslateTypeDeclarations.renameRecordField - ~attributes:expr.exp_attributes ~nameRE:field.nameRE + ~attributes:expr.exp_attributes ~name:field.nameJS in - ({field with nameJS; nameRE} :: nextFields1, types1) + ({field with nameJS = name} :: nextFields1, types1) | _ -> (fields, argTypes) (** Recover from expr the renaming annotations on named arguments. *) diff --git a/jscomp/gentype/TranslateTypeDeclarations.ml b/jscomp/gentype/TranslateTypeDeclarations.ml index a8229d876d..e5155f8c19 100644 --- a/jscomp/gentype/TranslateTypeDeclarations.ml +++ b/jscomp/gentype/TranslateTypeDeclarations.ml @@ -23,10 +23,10 @@ let createCase (label, attributes) = match attributes |> Annotation.getAttributePayload Annotation.tagIsGenTypeAs with - | Some (BoolPayload b) -> {label; labelJS = BoolLabel b} - | Some (FloatPayload s) -> {label; labelJS = FloatLabel s} - | Some (IntPayload i) -> {label; labelJS = IntLabel i} - | Some (StringPayload asLabel) -> {label; labelJS = StringLabel asLabel} + | Some (_, BoolPayload b) -> {label; labelJS = BoolLabel b} + | Some (_, FloatPayload s) -> {label; labelJS = FloatLabel s} + | Some (_, IntPayload i) -> {label; labelJS = IntLabel i} + | Some (_, StringPayload asLabel) -> {label; labelJS = StringLabel asLabel} | _ -> {label; labelJS = StringLabel label} (** @@ -35,15 +35,13 @@ let createCase (label, attributes) = * If @bs.as is used (with records-as-objects active), escape and quote if * the identifier contains characters which are invalid as JS property names. *) -let renameRecordField ~attributes ~nameRE = - match attributes |> Annotation.getGenTypeAsRenaming with - | Some nameJS -> (nameJS, nameRE) - | None -> ( - match attributes |> Annotation.getBsAsRenaming with - | Some nameBS -> - let escapedName = nameBS |> String.escaped in - (escapedName, escapedName) - | None -> (nameRE, nameRE)) +let renameRecordField ~attributes ~name = + attributes |> Annotation.checkUnsupportedGenTypeAsRenaming; + match attributes |> Annotation.getBsAsRenaming with + | Some nameBS -> + let escapedName = nameBS |> String.escaped in + escapedName + | None -> name let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver ~typeAttributes ~typeEnv ~typeName ~typeVars declarationKind : @@ -88,17 +86,16 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver let fieldTranslations = labelDeclarations |> List.map (fun {Types.ld_id; ld_mutable; ld_type; ld_attributes} -> - let nameJS, nameRE = + let name = renameRecordField ~attributes:ld_attributes - ~nameRE:(ld_id |> Ident.name) + ~name:(ld_id |> Ident.name) in let mutability = match ld_mutable = Mutable with | true -> Mutable | false -> Immutable in - ( nameJS, - nameRE, + ( name, mutability, ld_type |> TranslateTypeExprFromTypes.translateTypeExprFromTypes ~config @@ -106,21 +103,19 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver in let dependencies = fieldTranslations - |> List.map (fun (_, _, _, {TranslateTypeExprFromTypes.dependencies}) -> + |> List.map (fun (_, _, {TranslateTypeExprFromTypes.dependencies}) -> dependencies) |> List.concat in let fields = fieldTranslations - |> List.map - (fun (nameJS, nameRE, mutable_, {TranslateTypeExprFromTypes.type_}) - -> + |> List.map (fun (name, mutable_, {TranslateTypeExprFromTypes.type_}) -> let optional, type1 = match type_ with - | Option type1 when isOptional nameRE -> (Optional, type1) + | Option type1 when isOptional name -> (Optional, type1) | _ -> (Mandatory, type_) in - {mutable_; nameJS; nameRE; optional; type_ = type1}) + {mutable_; nameJS = name; optional; type_ = type1}) in let type_ = match fields with @@ -190,7 +185,8 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver variant.payloads |> List.length = (rowFieldsVariants.payloads |> List.length) then - List.combine variant.payloads rowFieldsVariants.payloads + (List.combine variant.payloads rowFieldsVariants.payloads + [@doesNotRaise]) |> List.map (fun (payload, (label, attributes, _)) -> let case = (label, attributes) |> createCase in {payload with case}) diff --git a/jscomp/gentype/TranslateTypeExprFromTypes.ml b/jscomp/gentype/TranslateTypeExprFromTypes.ml index 7d0b966474..4e0edb6bf4 100644 --- a/jscomp/gentype/TranslateTypeExprFromTypes.ml +++ b/jscomp/gentype/TranslateTypeExprFromTypes.ml @@ -45,7 +45,7 @@ let translateObjType closedFlag fieldsTranslations = | _ -> (Mandatory, t) in let name = name |> Runtime.mangleObjectField in - {mutable_; nameJS = name; nameRE = name; optional; type_}) + {mutable_; nameJS = name; optional; type_}) in let type_ = Object (closedFlag, fields) in {dependencies; type_} @@ -124,7 +124,6 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = { mutable_ = Mutable; nameJS = "contents"; - nameRE = "contents"; optional = Mandatory; type_ = paramTranslation.type_; }; @@ -453,7 +452,7 @@ and translateTypeExprFromTypes_ ~config ~typeVarsGen ~typeEnv match typeEnv |> TypeEnv.lookupModuleTypeSignature ~path with | Some (signature, typeEnv) -> let typeEquationsTranslation = - List.combine ids types + (List.combine ids types [@doesNotRaise]) |> List.map (fun (x, t) -> ( x, t |> translateTypeExprFromTypes_ ~config ~typeVarsGen ~typeEnv @@ -503,7 +502,6 @@ and signatureToModuleRuntimeRepresentation ~config ~typeVarsGen ~typeEnv { mutable_ = Immutable; nameJS = id |> Ident.name; - nameRE = id |> Ident.name; optional = Mandatory; type_; } @@ -527,7 +525,6 @@ and signatureToModuleRuntimeRepresentation ~config ~typeVarsGen ~typeEnv { mutable_ = Immutable; nameJS = id |> Ident.name; - nameRE = id |> Ident.name; optional = Mandatory; type_; } diff --git a/jscomp/gentype/Translation.ml b/jscomp/gentype/Translation.ml index bd787eadb9..a7851ceedf 100644 --- a/jscomp/gentype/Translation.ml +++ b/jscomp/gentype/Translation.ml @@ -90,9 +90,9 @@ let translateValue ~attributes ~config ~docString ~outputFileRelative ~resolver |> addAnnotationsToFunction in let resolvedNameOriginal = - name |> TypeEnv.addModulePath ~typeEnv |> ResolvedName.toString + nameAs |> TypeEnv.addModulePath ~typeEnv |> ResolvedName.toString in - let resolvedName = nameAs |> TypeEnv.addModulePath ~typeEnv in + let resolvedName = name |> TypeEnv.addModulePath ~typeEnv in let moduleAccessPath = typeEnv |> TypeEnv.getModuleAccessPath ~name:resolvedNameOriginal in diff --git a/jscomp/gentype_tests/typescript-react-example/src/AutoAnnotate.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/AutoAnnotate.gen.tsx index b5bd5bca66..88f99dbf1d 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/AutoAnnotate.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/AutoAnnotate.gen.tsx @@ -3,7 +3,7 @@ // tslint:disable-next-line:interface-over-type-literal -export type variant = { tag: "R"; value: number }; +export type variant = { TAG: "R"; _0: number }; // tslint:disable-next-line:interface-over-type-literal export type record = { readonly variant: variant }; @@ -19,5 +19,5 @@ export type r4 = { readonly r4: number }; // tslint:disable-next-line:interface-over-type-literal export type annotatedVariant = - { tag: "R2"; value: [r2, r3] } - | { tag: "R4"; value: r4 }; + { TAG: "R2"; _0: r2; _1: r3 } + | { TAG: "R4"; _0: r4 }; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Core.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Core.gen.tsx index 8a5c6608f9..17b7dc2685 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Core.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Core.gen.tsx @@ -6,10 +6,6 @@ import {someFunWithNullThenOptionalArgs as someFunWithNullThenOptionalArgsNotChe import {someFunWithNullUndefinedArg as someFunWithNullUndefinedArgNotChecked} from './CoreTS'; -const $$toJS552311971: { [key: string]: any } = {"0": "A"}; - -const $$toRE552311971: { [key: string]: any } = {"A": 0}; - // In case of type error, check the type of 'someFunWithNullThenOptionalArgs' in 'Core.res' and './CoreTS'. export const someFunWithNullThenOptionalArgsTypeChecked: (_1:(null | string), _2:(undefined | string)) => string = someFunWithNullThenOptionalArgsNotChecked; @@ -26,7 +22,7 @@ export const someFunWithNullUndefinedArg: unknown = someFunWithNullUndefinedArgT const CoreBS = require('./Core.bs'); // tslint:disable-next-line:interface-over-type-literal -export type variant = "A" | { tag: "B"; value: string }; +export type variant = "A" | { TAG: "B"; _0: string }; // tslint:disable-next-line:interface-over-type-literal export type t1 = { readonly x?: string }; @@ -76,11 +72,4 @@ export const weakset1: (x:WeakSet) => WeakSet = CoreBS.weaks export const option0: (x:(undefined | string)) => (undefined | string) = CoreBS.option0; -export const option1: (x:(undefined | variant)) => (undefined | variant) = function (Arg1: any) { - const result = CoreBS.option1((Arg1 == null ? Arg1 : typeof(Arg1) === 'object' - ? {TAG: 0, _0:Arg1.value} as any - : $$toRE552311971[Arg1])); - return (result == null ? result : typeof(result) === 'object' - ? {tag:"B", value:result._0} - : $$toJS552311971[result]) -}; +export const option1: (x:(undefined | variant)) => (undefined | variant) = CoreBS.option1; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.bs.js index 234fe8b1ef..83dc9626b8 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.bs.js @@ -66,11 +66,11 @@ function unitArgWithoutConversionU(param) { } function unitArgWithConversion(param) { - return /* A */0; + return "A"; } function unitArgWithConversionU(param) { - return /* A */0; + return "A"; } var flat = 34; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx index 646ed8d367..2e6ff2cb51 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx @@ -2,12 +2,6 @@ /* eslint-disable import/first */ -const $$toJS453167283: { [key: string]: any } = {"0": "A", "1": "B"}; - -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // @ts-ignore: Implicit any on import import * as DocstringsBS__Es6Import from './Docstrings.bs'; const DocstringsBS: any = DocstringsBS__Es6Import; @@ -23,15 +17,9 @@ export const signMessage: (message:string, key:number) => string = DocstringsBS. export const one: (a:number) => number = DocstringsBS.one; -export const two: (a:number, b:number) => number = function (Arg1: any, Arg2: any) { - const result = Curry._2(DocstringsBS.two, Arg1, Arg2); - return result -}; +export const two: (a:number, b:number) => number = DocstringsBS.two; -export const tree: (a:number, b:number, c:number) => number = function (Arg1: any, Arg2: any, Arg3: any) { - const result = Curry._3(DocstringsBS.tree, Arg1, Arg2, Arg3); - return result -}; +export const tree: (a:number, b:number, c:number) => number = DocstringsBS.tree; export const oneU: (a:number) => number = DocstringsBS.oneU; @@ -47,28 +35,16 @@ export const unnamed1: (param:number) => number = DocstringsBS.unnamed1; export const unnamed1U: (param:number) => number = DocstringsBS.unnamed1U; -export const unnamed2: (param_0:number, param_1:number) => number = function (Arg1: any, Arg2: any) { - const result = Curry._2(DocstringsBS.unnamed2, Arg1, Arg2); - return result -}; +export const unnamed2: (param_0:number, param_1:number) => number = DocstringsBS.unnamed2; export const unnamed2U: (param_0:number, param_1:number) => number = DocstringsBS.unnamed2U; -export const grouped: (_1:{ readonly x: number; readonly y: number }, a:number, b:number, c:number, _5:{ readonly z: number }) => number = function (Arg1: any, Arg2: any, Arg3: any, Arg4: any, Arg5: any) { - const result = Curry._6(DocstringsBS.grouped, Arg1.x, Arg1.y, Arg2, Arg3, Arg4, Arg5.z); - return result -}; +export const grouped: (_1:{ readonly x: number; readonly y: number }, a:number, b:number, c:number, _5:{ readonly z: number }) => number = DocstringsBS.grouped; export const unitArgWithoutConversion: () => string = DocstringsBS.unitArgWithoutConversion; export const unitArgWithoutConversionU: () => string = DocstringsBS.unitArgWithoutConversionU; -export const unitArgWithConversion: () => t = function () { - const result = DocstringsBS.unitArgWithConversion(); - return $$toJS453167283[result] -}; +export const unitArgWithConversion: () => t = DocstringsBS.unitArgWithConversion; -export const unitArgWithConversionU: () => t = function () { - const result = DocstringsBS.unitArgWithConversionU(); - return $$toJS453167283[result] -}; +export const unitArgWithConversionU: () => t = DocstringsBS.unitArgWithConversionU; diff --git a/jscomp/gentype_tests/typescript-react-example/src/EmitModuleIfNoConversion.bs.js b/jscomp/gentype_tests/typescript-react-example/src/EmitModuleIfNoConversion.bs.js index fcfe4dd8b6..f73e0e7ede 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/EmitModuleIfNoConversion.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/EmitModuleIfNoConversion.bs.js @@ -2,11 +2,11 @@ function foo(t) { - if (t) { - console.log("B" + t.name); - } else { + if (typeof t !== "object") { console.log("A"); + return ; } + console.log("B" + t.name); } var X = { diff --git a/jscomp/gentype_tests/typescript-react-example/src/EmitModuleIfNoConversion.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/EmitModuleIfNoConversion.gen.tsx index 5c7facf771..0c8dc66e78 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/EmitModuleIfNoConversion.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/EmitModuleIfNoConversion.gen.tsx @@ -2,24 +2,19 @@ /* eslint-disable import/first */ -const $$toRE552311971: { [key: string]: any } = {"A": 0}; - // @ts-ignore: Implicit any on import import * as EmitModuleIfNoConversionBS__Es6Import from './EmitModuleIfNoConversion.bs'; const EmitModuleIfNoConversionBS: any = EmitModuleIfNoConversionBS__Es6Import; // tslint:disable-next-line:interface-over-type-literal -export type t = "A" | { readonly name: string }; +export type t = "A" | { TAG: "B"; readonly name: string }; -export const X_foo: (t:t) => void = function (Arg1: any) { - const result = EmitModuleIfNoConversionBS.X.foo(typeof(Arg1) === 'object' - ? Object.assign({TAG: 0}, Arg1) - : $$toRE552311971[Arg1]); - return result -}; +export const X_foo: (t:t) => void = EmitModuleIfNoConversionBS.X.foo; export const X_x: number = EmitModuleIfNoConversionBS.X.x; export const Y_x: string = EmitModuleIfNoConversionBS.Y.x; export const Y: { x: string } = EmitModuleIfNoConversionBS.Y + +export const X: { x: number; foo: (t:t) => void } = EmitModuleIfNoConversionBS.X diff --git a/jscomp/gentype_tests/typescript-react-example/src/ExportWithRename.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/ExportWithRename.gen.tsx index 7b7416701c..127a44dd7d 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/ExportWithRename.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/ExportWithRename.gen.tsx @@ -11,4 +11,4 @@ const ExportWithRenameBS: any = ExportWithRenameBS__Es6Import; // tslint:disable-next-line:interface-over-type-literal export type Props = { readonly s: string }; -export const ExportWithRename: React.ComponentType<{ readonly s: string }> = ExportWithRenameBS.make; +export const make: React.ComponentType<{ readonly s: string }> = ExportWithRenameBS.ExportWithRename; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Hooks.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Hooks.gen.tsx index 8ace239838..f4c0651a29 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Hooks.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Hooks.gen.tsx @@ -4,10 +4,6 @@ import * as React from 'react'; -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // @ts-ignore: Implicit any on import import * as HooksBS__Es6Import from './Hooks.bs'; const HooksBS: any = HooksBS__Es6Import; @@ -79,13 +75,7 @@ export const functionWithRenamedArgs: (_1:{ readonly to: vehicle; readonly Type: vehicle; readonly cb: cb -}) => string = function (Arg1: any) { - const result = Curry._3(HooksBS.functionWithRenamedArgs, Arg1.to, Arg1.Type, function (Argto: any) { - const result1 = Arg1.cb({to:Argto}); - return result1 - }); - return result -}; +}) => string = HooksBS.functionWithRenamedArgs; // tslint:disable-next-line:interface-over-type-literal export type WithRename_componentWithRenamedArgs_Props = { @@ -98,19 +88,9 @@ export const WithRename_componentWithRenamedArgs: React.ComponentType<{ readonly Type: vehicle; readonly to: vehicle; readonly cb: cb -}> = function Hooks_WithRename_componentWithRenamedArgs(Arg1: any) { - const $props = {Type:Arg1.Type, to:Arg1.to, cb:function (Argto: any) { - const result1 = Arg1.cb({to:Argto}); - return result1 - }}; - const result = React.createElement(HooksBS.WithRename.componentWithRenamedArgs, $props); - return result -}; +}> = HooksBS.WithRename.componentWithRenamedArgs; -export const WithRef_makeWithRef: (_1:{ readonly vehicle: vehicle }, _2:(null | undefined | any)) => JSX.Element = function (Arg1: any, Arg2: any) { - const result = Curry._2(HooksBS.WithRef.makeWithRef, Arg1, Arg2); - return result -}; +export const WithRef_makeWithRef: (_1:{ readonly vehicle: vehicle }, _2:(null | undefined | any)) => JSX.Element = HooksBS.WithRef.makeWithRef; // tslint:disable-next-line:interface-over-type-literal export type testForwardRef_Props = { readonly vehicle: vehicle }; @@ -172,10 +152,18 @@ export const Inner: { export const RenderPropRequiresConversion: { make: React.ComponentType<{ readonly renderVehicle: React.ComponentType<{ readonly number: number; readonly vehicle: vehicle }> }> } = HooksBS.RenderPropRequiresConversion +export const WithRename: { componentWithRenamedArgs: React.ComponentType<{ + readonly Type: vehicle; + readonly to: vehicle; + readonly cb: cb +}> } = HooksBS.WithRename + export const ForwardRef: { input: React.ComponentType<{ readonly r: r }> } = HooksBS.ForwardRef export const Fun: { functionReturningReactElement: React.ComponentType<{ readonly name: string }> } = HooksBS.Fun +export const WithRef: { makeWithRef: (_1:{ readonly vehicle: vehicle }, _2:(null | undefined | any)) => JSX.Element } = HooksBS.WithRef + export const WithChildren: { aComponentWithChildren: React.ComponentType<{ readonly children: React.ReactNode; readonly vehicle: vehicle }> } = HooksBS.WithChildren export const DD: { make: React.ComponentType<{ readonly array: Js_TypedArray2_Uint8Array_t; readonly name: string }> } = HooksBS.DD diff --git a/jscomp/gentype_tests/typescript-react-example/src/ImportHooks.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/ImportHooks.gen.tsx index 0ffc03894d..e0874a2b7d 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/ImportHooks.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/ImportHooks.gen.tsx @@ -26,10 +26,7 @@ export const makeRenamed: unknown = makeRenamedTypeChecked as React.ComponentTyp export const fooTypeChecked: (_1:{ readonly person: person }) => string = fooNotChecked; // Export 'foo' early to allow circular import from the '.bs.js' file. -export const foo: unknown = function (Argperson: any) { - const result = fooTypeChecked({person:Argperson}); - return result -} as (_1:{ readonly person: person }) => string; +export const foo: unknown = fooTypeChecked as (_1:{ readonly person: person }) => string; // tslint:disable-next-line:interface-over-type-literal export type person = { readonly name: string; readonly age: number }; diff --git a/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx index 66fda441c6..ea763fd2b5 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx @@ -20,10 +20,6 @@ import {polymorphic as polymorphicNotChecked} from './MyMath'; import {default as defaultNotChecked} from './MyMath'; -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // In case of type error, check the type of 'round' in 'ImportJsValue.res' and './MyMath'. export const roundTypeChecked: (_1:number) => number = roundNotChecked; @@ -58,26 +54,13 @@ export const useColor: unknown = useColorTypeChecked as (_1:color) => number; export const higherOrderTypeChecked: (_1:((_1:number, _2:number) => number)) => number = higherOrderNotChecked; // Export 'higherOrder' early to allow circular import from the '.bs.js' file. -export const higherOrder: unknown = function (Arg1: any) { - const result = higherOrderTypeChecked(function (Arg11: any, Arg2: any) { - const result1 = Curry._2(Arg1, Arg11, Arg2); - return result1 - }); - return result -} as (_1:((_1:number, _2:number) => number)) => number; +export const higherOrder: unknown = higherOrderTypeChecked as (_1:((_1:number, _2:number) => number)) => number; // In case of type error, check the type of 'convertVariant' in 'ImportJsValue.res' and './MyMath'. export const convertVariantTypeChecked: (_1:variant) => variant = convertVariantNotChecked; // Export 'convertVariant' early to allow circular import from the '.bs.js' file. -export const convertVariant: unknown = function (Arg1: any) { - const result = convertVariantTypeChecked(Arg1.TAG===0 - ? {tag:"I", value:Arg1._0} - : {tag:"S", value:Arg1._0}); - return result.tag==="I" - ? {TAG: 0, _0:result.value} as any - : {TAG: 1, _0:result.value} as any -} as (_1:variant) => variant; +export const convertVariant: unknown = convertVariantTypeChecked as (_1:variant) => variant; // In case of type error, check the type of 'polymorphic' in 'ImportJsValue.res' and './MyMath'. export const polymorphicTypeChecked: (_1:a) => a = polymorphicNotChecked; @@ -123,8 +106,8 @@ export type color = "tomato" | "gray"; // tslint:disable-next-line:interface-over-type-literal export type variant = - { tag: "I"; value: number } - | { tag: "S"; value: string }; + { TAG: "I"; _0: number } + | { TAG: "S"; _0: string }; // tslint:disable-next-line:interface-over-type-literal export type num = $$num; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Machine.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Machine.bs.js index c700735f9e..6ec89819c8 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Machine.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/Machine.bs.js @@ -1,7 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -var a = /* A */{ +var a = { + TAG: "A", _0: 3 }; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Machine.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Machine.gen.tsx index ab7ac50eb7..da11ae974b 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Machine.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Machine.gen.tsx @@ -7,6 +7,6 @@ import * as MachineBS__Es6Import from './Machine.bs'; const MachineBS: any = MachineBS__Es6Import; // tslint:disable-next-line:interface-over-type-literal -export type aa = { tag: "A"; value: number }; +export type aa = { TAG: "A"; _0: number }; -export const a: aa = {tag:"A", value:MachineBS.a._0}; +export const a: aa = MachineBS.a; diff --git a/jscomp/gentype_tests/typescript-react-example/src/MoreVariants.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/MoreVariants.gen.tsx index ae2339a5e8..5d11efc9ee 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/MoreVariants.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/MoreVariants.gen.tsx @@ -2,10 +2,6 @@ /* eslint-disable import/first */ -const $$toJS912209123: { [key: string]: any } = {"type_": "type", "b": "b"}; - -const $$toRE912209123: { [key: string]: any } = {"type": "type_", "b": "b"}; - // @ts-ignore: Implicit any on import import * as MoreVariantsBS__Es6Import from './MoreVariants.bs'; const MoreVariantsBS: any = MoreVariantsBS__Es6Import; @@ -16,9 +12,6 @@ export type withRenaming = "type" | "b"; // tslint:disable-next-line:interface-over-type-literal export type withoutRenaming = "type_" | "b"; -export const testWithRenaming: (x:withRenaming) => withRenaming = function (Arg1: any) { - const result = MoreVariantsBS.testWithRenaming($$toRE912209123[Arg1]); - return $$toJS912209123[result] -}; +export const testWithRenaming: (x:withRenaming) => withRenaming = MoreVariantsBS.testWithRenaming; export const testWithoutRenaming: (x:withoutRenaming) => withoutRenaming = MoreVariantsBS.testWithoutRenaming; diff --git a/jscomp/gentype_tests/typescript-react-example/src/NestedModules.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/NestedModules.gen.tsx index 37cbfabaff..8a58e86616 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/NestedModules.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/NestedModules.gen.tsx @@ -16,7 +16,7 @@ export type Universe_Nested2_nested2Type = Array; export type Universe_Nested2_Nested3_nested3Type = Array>; // tslint:disable-next-line:interface-over-type-literal -export type Universe_variant = "A" | { tag: "B"; value: string }; +export type Universe_variant = "A" | { TAG: "B"; _0: string }; export const notNested: number = NestedModulesBS.notNested; diff --git a/jscomp/gentype_tests/typescript-react-example/src/NestedVariants.bs.js b/jscomp/gentype_tests/typescript-react-example/src/NestedVariants.bs.js index 6fc78a38fa..96669d6b4e 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/NestedVariants.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/NestedVariants.bs.js @@ -2,7 +2,8 @@ function makeVariant(param) { - return /* NonUnary */{ + return { + TAG: "NonUnary", _0: 5, _1: 3 }; @@ -10,10 +11,10 @@ function makeVariant(param) { function makeABC(param) { return { - TAG: /* A */0, + TAG: "A", _0: { c: { - TAG: /* C */0, + TAG: "C", _0: "a string" } }, @@ -24,7 +25,7 @@ function makeABC(param) { function makeBC(param) { return { c: { - TAG: /* C */0, + TAG: "C", _0: "a string" } }; @@ -32,9 +33,9 @@ function makeBC(param) { function makeAC(param) { return { - TAG: /* A */0, + TAG: "A", _0: { - TAG: /* C */0, + TAG: "C", _0: "a string" }, _1: 5 @@ -43,8 +44,9 @@ function makeAC(param) { function makeAD(param) { return { - TAG: /* A */0, - _0: /* Int */{ + TAG: "A", + _0: { + TAG: "Int", _0: 3 }, _1: 5 @@ -53,7 +55,7 @@ function makeAD(param) { function makeAE(param) { return { - TAG: /* A */0, + TAG: "A", _0: 3, _1: 5 }; @@ -61,8 +63,9 @@ function makeAE(param) { function makeFD(param) { return { - TAG: /* F */0, - _0: /* Int */{ + TAG: "F", + _0: { + TAG: "Int", _0: 3 } }; @@ -70,8 +73,9 @@ function makeFD(param) { function makeHD(param) { return { - TAG: /* H */0, - _0: /* Int */{ + TAG: "H", + _0: { + TAG: "Int", _0: 5 }, _1: 5 @@ -79,23 +83,29 @@ function makeHD(param) { } function makeJ(param) { - return /* J */{ - _0: /* Int */{ + return { + TAG: "J", + _0: { + TAG: "Int", _0: 5 }, - _1: /* Int */{ + _1: { + TAG: "Int", _0: 3 } }; } function makeK(param) { - return /* K */{ + return { + TAG: "K", _0: [ - /* Int */{ + { + TAG: "Int", _0: 5 }, - /* Int */{ + { + TAG: "Int", _0: 3 } ] @@ -111,18 +121,18 @@ function testUnboxedBinary(param) { } function testInline(x) { - switch (x.TAG | 0) { - case /* I */0 : + switch (x.TAG) { + case "I" : return { - TAG: /* I */0, + TAG: "I", i: x.i, j: x.j }; - case /* J */1 : + case "J" : return x; - case /* K */2 : + case "K" : return { - TAG: /* K */2, + TAG: "K", _0: x._1, _1: x._0 }; diff --git a/jscomp/gentype_tests/typescript-react-example/src/NestedVariants.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/NestedVariants.gen.tsx index 7d780d6811..6d33f6cfce 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/NestedVariants.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/NestedVariants.gen.tsx @@ -7,150 +7,78 @@ import * as NestedVariantsBS__Es6Import from './NestedVariants.bs'; const NestedVariantsBS: any = NestedVariantsBS__Es6Import; // tslint:disable-next-line:interface-over-type-literal -export type typeL = [number, number]; +export type typeL = + { TAG: "NonUnary"; _0: number; _1: number }; // tslint:disable-next-line:interface-over-type-literal export type typeC = - { tag: "C"; value: string } - | { tag: "D"; value: string }; + { TAG: "C"; _0: string } + | { TAG: "D"; _0: string }; // tslint:disable-next-line:interface-over-type-literal export type typeB = { readonly c: typeC }; // tslint:disable-next-line:interface-over-type-literal -export type typeD = { tag: "Int"; value: number }; +export type typeD = { TAG: "Int"; _0: number }; // tslint:disable-next-line:interface-over-type-literal export type typeE = number; // tslint:disable-next-line:interface-over-type-literal export type typeA = - { tag: "A"; value: [a, number] } - | { tag: "B"; value: [a, number] }; + { TAG: "A"; _0: a; _1: number } + | { TAG: "B"; _0: a; _1: number }; // tslint:disable-next-line:interface-over-type-literal -export type typeF = - { tag: "F"; value: a } - | { tag: "G"; value: a }; +export type typeF = { TAG: "F"; _0: a } | { TAG: "G"; _0: a }; // tslint:disable-next-line:interface-over-type-literal export type typeH = - { tag: "H"; value: [typeD, number] } - | { tag: "I"; value: [typeD, number] }; + { TAG: "H"; _0: typeD; _1: number } + | { TAG: "I"; _0: typeD; _1: number }; // tslint:disable-next-line:interface-over-type-literal -export type typeJ = [typeD, typeD]; +export type typeJ = { TAG: "J"; _0: typeD; _1: typeD }; // tslint:disable-next-line:interface-over-type-literal -export type typeK = [typeD, typeD]; +export type typeK = { TAG: "K"; _0: typeD; _1: typeD }; // tslint:disable-next-line:interface-over-type-literal export type boxedBinary = - { tag: "BB"; value: [typeD, number] } - | { tag: "Z"; value: number }; + { TAG: "BB"; _0: typeD; _1: number } + | { TAG: "Z"; _0: number }; // tslint:disable-next-line:interface-over-type-literal -export type unboxedBinary = [typeD, number]; +export type unboxedBinary = { TAG: "UB"; _0: typeD; _1: number }; // tslint:disable-next-line:interface-over-type-literal export type inline = - { tag: "I"; value: { readonly i: number; readonly j: number } } - | { tag: "J"; value: { readonly i: number; readonly j: number } } - | { tag: "K"; value: [number, number] }; - -export const makeVariant: () => typeL = function () { - const result = NestedVariantsBS.makeVariant(); - return [result._0, result._1] -}; - -export const makeABC: () => typeA = function () { - const result = NestedVariantsBS.makeABC(); - return result.TAG===0 - ? {tag:"A", value:[{c:result._0.c.TAG===0 - ? {tag:"C", value:result._0.c._0} - : {tag:"D", value:result._0.c._0}}, result._1]} - : {tag:"B", value:[{c:result._0.c.TAG===0 - ? {tag:"C", value:result._0.c._0} - : {tag:"D", value:result._0.c._0}}, result._1]} -}; - -export const makeBC: () => typeB = function () { - const result = NestedVariantsBS.makeBC(); - return {c:result.c.TAG===0 - ? {tag:"C", value:result.c._0} - : {tag:"D", value:result.c._0}} -}; - -export const makeAC: () => typeA = function () { - const result = NestedVariantsBS.makeAC(); - return result.TAG===0 - ? {tag:"A", value:[result._0.TAG===0 - ? {tag:"C", value:result._0._0} - : {tag:"D", value:result._0._0}, result._1]} - : {tag:"B", value:[result._0.TAG===0 - ? {tag:"C", value:result._0._0} - : {tag:"D", value:result._0._0}, result._1]} -}; - -export const makeAD: () => typeA = function () { - const result = NestedVariantsBS.makeAD(); - return result.TAG===0 - ? {tag:"A", value:[{tag:"Int", value:result._0._0}, result._1]} - : {tag:"B", value:[{tag:"Int", value:result._0._0}, result._1]} -}; - -export const makeAE: () => typeA = function () { - const result = NestedVariantsBS.makeAE(); - return result.TAG===0 - ? {tag:"A", value:[result._0, result._1]} - : {tag:"B", value:[result._0, result._1]} -}; - -export const makeFD: () => typeF = function () { - const result = NestedVariantsBS.makeFD(); - return result.TAG===0 - ? {tag:"F", value:{tag:"Int", value:result._0._0}} - : {tag:"G", value:{tag:"Int", value:result._0._0}} -}; - -export const makeHD: () => typeH = function () { - const result = NestedVariantsBS.makeHD(); - return result.TAG===0 - ? {tag:"H", value:[{tag:"Int", value:result._0._0}, result._1]} - : {tag:"I", value:[{tag:"Int", value:result._0._0}, result._1]} -}; - -export const makeJ: () => typeJ = function () { - const result = NestedVariantsBS.makeJ(); - return [{tag:"Int", value:result._0._0}, {tag:"Int", value:result._1._0}] -}; - -export const makeK: () => typeK = function () { - const result = NestedVariantsBS.makeK(); - return [{tag:"Int", value:result._0[0]._0}, {tag:"Int", value:result._0[1]._0}] -}; - -export const testBoxedBinary: (param:boxedBinary) => number = function (Arg1: any) { - const result = NestedVariantsBS.testBoxedBinary(Arg1.tag==="BB" - ? {TAG: 0, _0:{TAG: 0, _0:Arg1.value[0].value} as any, _1:Arg1.value[1]} as any - : {TAG: 1, _0:Arg1.value} as any); - return result -}; - -export const testUnboxedBinary: (param:unboxedBinary) => number = function (Arg1: any) { - const result = NestedVariantsBS.testUnboxedBinary({TAG: 0, _0:{TAG: 0, _0:Arg1[0].value} as any, _1:Arg1[1]} as any); - return result -}; - -export const testInline: (x:inline) => inline = function (Arg1: any) { - const result = NestedVariantsBS.testInline(Arg1.tag==="I" - ? Object.assign({TAG: 0}, Arg1.value) - : Arg1.tag==="J" - ? Object.assign({TAG: 1}, Arg1.value) - : {TAG: 2, _0:Arg1.value[0], _1:Arg1.value[1]} as any); - return result.TAG===0 - ? {tag:"I", value:result} - : result.TAG===1 - ? {tag:"J", value:result} - : {tag:"K", value:[result._0, result._1]} -}; + { TAG: "I"; readonly i: number; readonly j: number } + | { TAG: "J"; readonly i: number; readonly j: number } + | { TAG: "K"; _0: number; _1: number }; + +export const makeVariant: () => typeL = NestedVariantsBS.makeVariant; + +export const makeABC: () => typeA = NestedVariantsBS.makeABC; + +export const makeBC: () => typeB = NestedVariantsBS.makeBC; + +export const makeAC: () => typeA = NestedVariantsBS.makeAC; + +export const makeAD: () => typeA = NestedVariantsBS.makeAD; + +export const makeAE: () => typeA = NestedVariantsBS.makeAE; + +export const makeFD: () => typeF = NestedVariantsBS.makeFD; + +export const makeHD: () => typeH = NestedVariantsBS.makeHD; + +export const makeJ: () => typeJ = NestedVariantsBS.makeJ; + +export const makeK: () => typeK = NestedVariantsBS.makeK; + +export const testBoxedBinary: (param:boxedBinary) => number = NestedVariantsBS.testBoxedBinary; + +export const testUnboxedBinary: (param:unboxedBinary) => number = NestedVariantsBS.testUnboxedBinary; + +export const testInline: (x:inline) => inline = NestedVariantsBS.testInline; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Records.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Records.bs.js index ad5795b116..f72740474c 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Records.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/Records.bs.js @@ -106,7 +106,7 @@ function computeArea4(o) { } function testMyRec(x) { - return x.type_; + return x.type; } function testMyRec2(x) { diff --git a/jscomp/gentype_tests/typescript-react-example/src/Records.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Records.gen.tsx index 65e582ba1a..ef6d6b7615 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Records.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Records.gen.tsx @@ -2,10 +2,6 @@ /* eslint-disable import/first */ -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // @ts-ignore: Implicit any on import import * as RecordsBS__Es6Import from './Records.bs'; const RecordsBS: any = RecordsBS__Es6Import; @@ -76,10 +72,7 @@ export const origin: coord = RecordsBS.origin; export const computeArea: (param:coord) => number = RecordsBS.computeArea; -export const coord2d: (x:number, y:number) => coord = function (Arg1: any, Arg2: any) { - const result = Curry._2(RecordsBS.coord2d, Arg1, Arg2); - return result -}; +export const coord2d: (x:number, y:number) => coord = RecordsBS.coord2d; export const findAddress: (business:business) => list = RecordsBS.findAddress; @@ -113,15 +106,9 @@ export const computeArea4: (o:{ readonly z?: number }) => number = RecordsBS.computeArea4; -export const testMyRec: (x:myRec) => string = function (Arg1: any) { - const result = RecordsBS.testMyRec({type_:Arg1.type}); - return result -}; +export const testMyRec: (x:myRec) => string = RecordsBS.testMyRec; -export const testMyRec2: (x:myRec) => myRec = function (Arg1: any) { - const result = RecordsBS.testMyRec2({type_:Arg1.type}); - return {type:result.type_} -}; +export const testMyRec2: (x:myRec) => myRec = RecordsBS.testMyRec2; export const testMyObj: (x:myObj) => string = RecordsBS.testMyObj; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Records.res b/jscomp/gentype_tests/typescript-react-example/src/Records.res index bfaceb0742..c8485e092e 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Records.res +++ b/jscomp/gentype_tests/typescript-react-example/src/Records.res @@ -108,7 +108,7 @@ let computeArea4 = (o: {"x": int, "y": int, "z": option}) => @genType type myRec = { - @genType.as("type") + @as("type") type_: string, } diff --git a/jscomp/gentype_tests/typescript-react-example/src/References.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/References.gen.tsx index fec3a03b43..ee18c0af0f 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/References.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/References.gen.tsx @@ -2,10 +2,6 @@ /* eslint-disable import/first */ -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // @ts-ignore: Implicit any on import import * as ReferencesBS__Es6Import from './References.bs'; const ReferencesBS: any = ReferencesBS__Es6Import; @@ -29,10 +25,7 @@ export const get: (_1:R_t) => T1 = ReferencesBS.get; export const make: (_1:T1) => R_t = ReferencesBS.make; -export const set: (_1:R_t, _2:T1) => void = function (Arg1: any, Arg2: any) { - const result = Curry._2(ReferencesBS.set, Arg1, Arg2); - return result -}; +export const set: (_1:R_t, _2:T1) => void = ReferencesBS.set; export const destroysRefIdentity: (x:{ contents: requiresConversion }) => { contents: requiresConversion } = ReferencesBS.destroysRefIdentity; diff --git a/jscomp/gentype_tests/typescript-react-example/src/TestPromise.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/TestPromise.gen.tsx index fb57d54ad6..2b8f97eadb 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/TestPromise.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/TestPromise.gen.tsx @@ -2,10 +2,6 @@ /* eslint-disable import/first */ -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // @ts-ignore: Implicit any on import import * as TestPromiseBS__Es6Import from './TestPromise.bs'; const TestPromiseBS: any = TestPromiseBS__Es6Import; @@ -21,7 +17,4 @@ export type toPayload = { readonly result: string }; export const convert: (_1:Promise) => Promise = TestPromiseBS.convert; -export const barx: (_1:{ readonly x?: Promise<(undefined | string)> }, _2:void) => boolean = function (Arg1: any, Arg2: any) { - const result = Curry._2(TestPromiseBS.barx, Arg1.x, Arg2); - return result -}; +export const barx: (_1:{ readonly x?: Promise<(undefined | string)> }, _2:void) => boolean = TestPromiseBS.barx; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Uncurried.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Uncurried.gen.tsx index 27fe26be62..1fa912985f 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Uncurried.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Uncurried.gen.tsx @@ -2,10 +2,6 @@ /* eslint-disable import/first */ -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // @ts-ignore: Implicit any on import import * as UncurriedBS__Es6Import from './Uncurried.bs'; const UncurriedBS: any = UncurriedBS__Es6Import; @@ -36,10 +32,7 @@ export const uncurried2: (x:number, y:string) => string = UncurriedBS.uncurried2 export const uncurried3: (x:number, y:string, z:number) => string = UncurriedBS.uncurried3; -export const curried3: (x:number, y:string, z:number) => string = function (Arg1: any, Arg2: any, Arg3: any) { - const result = Curry._3(UncurriedBS.curried3, Arg1, Arg2, Arg3); - return result -}; +export const curried3: (x:number, y:string, z:number) => string = UncurriedBS.curried3; export const callback: (cb:(() => number)) => string = UncurriedBS.callback; @@ -51,12 +44,6 @@ export const sumU: (n:number, m:number) => void = UncurriedBS.sumU; export const sumU2: (n:number) => (_1:number) => void = UncurriedBS.sumU2; -export const sumCurried: (n:number, _2:number) => void = function (Arg1: any, Arg2: any) { - const result = Curry._2(UncurriedBS.sumCurried, Arg1, Arg2); - return result -}; +export const sumCurried: (n:number, _2:number) => void = UncurriedBS.sumCurried; -export const sumLblCurried: (s:string, _2:{ readonly n: number; readonly m: number }) => void = function (Arg1: any, Arg2: any) { - const result = Curry._3(UncurriedBS.sumLblCurried, Arg1, Arg2.n, Arg2.m); - return result -}; +export const sumLblCurried: (s:string, _2:{ readonly n: number; readonly m: number }) => void = UncurriedBS.sumLblCurried; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Variants.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Variants.gen.tsx index 7244a0abe3..da51badee7 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Variants.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Variants.gen.tsx @@ -2,26 +2,12 @@ /* eslint-disable import/first */ -const $$toJS508922110: { [key: string]: any } = {"type_": "type", "module_": "module", "fortytwo": "42"}; - -const $$toRE508922110: { [key: string]: any } = {"type": "type_", "module": "module_", "42": "fortytwo"}; - -const $$toJS584768163: { [key: string]: any } = {"type_": "type", "module_": "module", "fortytwo": "XXX THIS IS DIFFERENT"}; - -const $$toRE584768163: { [key: string]: any } = {"type": "type_", "module": "module_", "XXX THIS IS DIFFERENT": "fortytwo"}; - -const $$toJS930788378: { [key: string]: any } = {"x": "x", "x1": "same"}; - -const $$toRE930788378: { [key: string]: any } = {"x": "x", "same": "x1"}; - -const $$toJS1061900109: { [key: string]: any } = {"x": "x", "x2": "same"}; - -const $$toRE1061900109: { [key: string]: any } = {"x": "x", "same": "x2"}; - // @ts-ignore: Implicit any on import import * as VariantsBS__Es6Import from './Variants.bs'; const VariantsBS: any = VariantsBS__Es6Import; +import type {list} from '../src/shims/RescriptPervasives.shim'; + // tslint:disable-next-line:interface-over-type-literal export type weekday = "monday" @@ -33,13 +19,13 @@ export type weekday = | "sunday"; // tslint:disable-next-line:interface-over-type-literal -export type testGenTypeAs = "type" | "module" | "42"; +export type testGenTypeAs = "type_" | "module_" | "fortytwo"; // tslint:disable-next-line:interface-over-type-literal -export type testGenTypeAs2 = "type" | "module" | "42"; +export type testGenTypeAs2 = "type_" | "module" | 42; // tslint:disable-next-line:interface-over-type-literal -export type testGenTypeAs3 = "type" | "module" | "XXX THIS IS DIFFERENT"; +export type testGenTypeAs3 = "type_" | "module" | 42; // tslint:disable-next-line:interface-over-type-literal export type x1 = "x" | "same"; @@ -51,20 +37,26 @@ export type x2 = "x" | "same"; export type type_ = "type"; export type type = type_; +// tslint:disable-next-line:interface-over-type-literal +export type myList = "E" | { TAG: "C"; _0: number; _1: myList }; + +// tslint:disable-next-line:interface-over-type-literal +export type builtinList = list; + // tslint:disable-next-line:interface-over-type-literal export type result1 = - { tag: "Ok"; value: a } - | { tag: "Error"; value: b }; + { TAG: "Ok"; _0: a } + | { TAG: "Error"; _0: b }; // tslint:disable-next-line:interface-over-type-literal export type result2 = - { tag: "Ok"; value: a } - | { tag: "Error"; value: b }; + { TAG: "Ok"; _0: a } + | { TAG: "Error"; _0: b }; // tslint:disable-next-line:interface-over-type-literal export type result3 = - { tag: "Ok"; value: a } - | { tag: "Error"; value: b }; + { TAG: "Ok"; _0: a } + | { TAG: "Error"; _0: b }; export const isWeekend: (x:weekday) => boolean = VariantsBS.isWeekend; @@ -78,67 +70,28 @@ export const onlySunday: (param:"sunday") => void = VariantsBS.onlySunday; export const swap: (x:"saturday" | "sunday") => "saturday" | "sunday" = VariantsBS.swap; -export const testConvert: (x:testGenTypeAs) => testGenTypeAs = function (Arg1: any) { - const result = VariantsBS.testConvert($$toRE508922110[Arg1]); - return $$toJS508922110[result] -}; +export const testConvert: (x:testGenTypeAs) => testGenTypeAs = VariantsBS.testConvert; -export const fortytwoOK: testGenTypeAs = $$toJS508922110[VariantsBS.fortytwoOK]; +export const fortytwoOK: testGenTypeAs = VariantsBS.fortytwoOK; export const fortytwoBAD: "fortytwo" = VariantsBS.fortytwoBAD; -export const testConvert2: (x:testGenTypeAs2) => testGenTypeAs2 = function (Arg1: any) { - const result = VariantsBS.testConvert2($$toRE508922110[Arg1]); - return $$toJS508922110[result] -}; +export const testConvert2: (x:testGenTypeAs2) => testGenTypeAs2 = VariantsBS.testConvert2; -export const testConvert3: (x:testGenTypeAs3) => testGenTypeAs3 = function (Arg1: any) { - const result = VariantsBS.testConvert3($$toRE584768163[Arg1]); - return $$toJS584768163[result] -}; +export const testConvert3: (x:testGenTypeAs3) => testGenTypeAs3 = VariantsBS.testConvert3; -export const testConvert2to3: (x:testGenTypeAs2) => testGenTypeAs3 = function (Arg1: any) { - const result = VariantsBS.testConvert2to3($$toRE508922110[Arg1]); - return $$toJS584768163[result] -}; +export const testConvert2to3: (x:testGenTypeAs2) => testGenTypeAs3 = VariantsBS.testConvert2to3; -export const id1: (x:x1) => x1 = function (Arg1: any) { - const result = VariantsBS.id1($$toRE930788378[Arg1]); - return $$toJS930788378[result] -}; +export const id1: (x:x1) => x1 = VariantsBS.id1; -export const id2: (x:x2) => x2 = function (Arg1: any) { - const result = VariantsBS.id2($$toRE1061900109[Arg1]); - return $$toJS1061900109[result] -}; +export const id2: (x:x2) => x2 = VariantsBS.id2; export const polyWithOpt: (foo:string) => (undefined | ( { NAME: "One"; VAL: string } | { NAME: "Two"; VAL: number })) = VariantsBS.polyWithOpt; -export const restResult1: (x:result1) => result1 = function (Arg1: any) { - const result = VariantsBS.restResult1(Arg1.tag==="Ok" - ? {TAG: 0, _0:Arg1.value} as any - : {TAG: 1, _0:Arg1.value} as any); - return result.TAG===0 - ? {tag:"Ok", value:result._0} - : {tag:"Error", value:result._0} -}; - -export const restResult2: (x:result2) => result2 = function (Arg1: any) { - const result = VariantsBS.restResult2(Arg1.tag==="Ok" - ? {TAG: 0, _0:Arg1.value} as any - : {TAG: 1, _0:Arg1.value} as any); - return result.TAG===0 - ? {tag:"Ok", value:result._0} - : {tag:"Error", value:result._0} -}; - -export const restResult3: (x:result3) => result3 = function (Arg1: any) { - const result = VariantsBS.restResult3(Arg1.tag==="Ok" - ? {TAG: 0, _0:Arg1.value} as any - : {TAG: 1, _0:Arg1.value} as any); - return result.TAG===0 - ? {tag:"Ok", value:result._0} - : {tag:"Error", value:result._0} -}; +export const restResult1: (x:result1) => result1 = VariantsBS.restResult1; + +export const restResult2: (x:result2) => result2 = VariantsBS.restResult2; + +export const restResult3: (x:result3) => result3 = VariantsBS.restResult3; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Variants.res b/jscomp/gentype_tests/typescript-react-example/src/Variants.res index 7fb6fb8f1a..4dcde43f9f 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Variants.res +++ b/jscomp/gentype_tests/typescript-react-example/src/Variants.res @@ -31,9 +31,9 @@ let swap = x => @genType type testGenTypeAs = [ - | @genType.as("type") #type_ - | @genType.as("module") #module_ - | @genType.as("42") #fortytwo + | #type_ + | #module_ + | #fortytwo ] @genType let testConvert = (x: testGenTypeAs) => x @@ -45,9 +45,9 @@ type testGenTypeAs = [ @genType type testGenTypeAs2 = [ - | @genType.as("type") #type_ - | @genType.as("module") #module_ - | @genType.as("42") #fortytwo + | #type_ + | #\"module" + | #42 ] /* Since testGenTypeAs2 is the same type as testGenTypeAs1, @@ -56,9 +56,9 @@ type testGenTypeAs2 = [ @genType type testGenTypeAs3 = [ - | @genType.as("type") #type_ - | @genType.as("module") #module_ - | @genType.as("XXX THIS IS DIFFERENT") #fortytwo + | #type_ + | #\"module" + | #42 ] /* Since testGenTypeAs3 has a different representation: @@ -79,6 +79,12 @@ type testGenTypeAs3 = [ @genType @genType.as("type") type type_ = | @genType.as("type") Type +@genType +type rec myList = E | C(int, myList) + +@genType +type builtinList = list + @genType let polyWithOpt = foo => foo === "bar" diff --git a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.bs.js b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.bs.js index 0894e9bc70..b1bd1018b8 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.bs.js @@ -52,22 +52,22 @@ function testVariantWithPayloads(x) { } function printVariantWithPayloads(x) { - if (typeof x === "number") { + if (typeof x !== "object") { console.log("printVariantWithPayloads", "A"); return ; } - switch (x.TAG | 0) { - case /* B */0 : + switch (x.TAG) { + case "B" : console.log("printVariantWithPayloads", "B(" + (String(x._0) + ")")); return ; - case /* C */1 : + case "C" : console.log("printVariantWithPayloads", "C(" + (String(x._0) + (", " + (String(x._1) + ")")))); return ; - case /* D */2 : + case "D" : var match = x._0; console.log("printVariantWithPayloads", "D((" + (String(match[0]) + (", " + (String(match[1]) + "))")))); return ; - case /* E */3 : + case "E" : console.log("printVariantWithPayloads", "E(" + (String(x._0) + (", " + (x._1 + (", " + (String(x._2) + ")")))))); return ; diff --git a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.gen.tsx index 6793c26c27..4420b28595 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.gen.tsx @@ -2,14 +2,6 @@ /* eslint-disable import/first */ -const $$toJS13337556: { [key: string]: any } = {"0": "ARenamed"}; - -const $$toRE13337556: { [key: string]: any } = {"ARenamed": 0}; - -const $$toJS346759412: { [key: string]: any } = {"0": "A", "1": "B", "2": "C"}; - -const $$toRE346759412: { [key: string]: any } = {"A": 0, "B": 1, "C": 2}; - // @ts-ignore: Implicit any on import import * as VariantsWithPayloadBS__Es6Import from './VariantsWithPayload.bs'; const VariantsWithPayloadBS: any = VariantsWithPayloadBS__Es6Import; @@ -37,17 +29,17 @@ export type simpleVariant = "A" | "B" | "C"; // tslint:disable-next-line:interface-over-type-literal export type variantWithPayloads = - "ARenamed" - | { tag: "B"; value: number } - | { tag: "C"; value: [number, number] } - | { tag: "D"; value: [number, number] } - | { tag: "E"; value: [number, string, number] }; + "A" + | { TAG: "B"; _0: number } + | { TAG: "C"; _0: number; _1: number } + | { TAG: "D"; _0: number; _1: number } + | { TAG: "E"; _0: number; _1: string; _2: number }; // tslint:disable-next-line:interface-over-type-literal -export type variant1Int = { tag: "R"; value: number }; +export type variant1Int = { TAG: "R"; _0: number }; // tslint:disable-next-line:interface-over-type-literal -export type variant1Object = payload; +export type variant1Object = { TAG: "R"; _0: payload }; export const testWithPayload: (x:withPayload) => withPayload = VariantsWithPayloadBS.testWithPayload; @@ -57,51 +49,12 @@ export const testManyPayloads: (x:manyPayloads) => manyPayloads = VariantsWithPa export const printManyPayloads: (x:manyPayloads) => void = VariantsWithPayloadBS.printManyPayloads; -export const testSimpleVariant: (x:simpleVariant) => simpleVariant = function (Arg1: any) { - const result = VariantsWithPayloadBS.testSimpleVariant($$toRE346759412[Arg1]); - return $$toJS346759412[result] -}; - -export const testVariantWithPayloads: (x:variantWithPayloads) => variantWithPayloads = function (Arg1: any) { - const result = VariantsWithPayloadBS.testVariantWithPayloads(typeof(Arg1) === 'object' - ? Arg1.tag==="B" - ? {TAG: 0, _0:Arg1.value} as any - : Arg1.tag==="C" - ? {TAG: 1, _0:Arg1.value[0], _1:Arg1.value[1]} as any - : Arg1.tag==="D" - ? {TAG: 2, _0:Arg1.value} as any - : {TAG: 3, _0:Arg1.value[0], _1:Arg1.value[1], _2:Arg1.value[2]} as any - : $$toRE13337556[Arg1]); - return typeof(result) === 'object' - ? result.TAG===0 - ? {tag:"B", value:result._0} - : result.TAG===1 - ? {tag:"C", value:[result._0, result._1]} - : result.TAG===2 - ? {tag:"D", value:result._0} - : {tag:"E", value:[result._0, result._1, result._2]} - : $$toJS13337556[result] -}; - -export const printVariantWithPayloads: (x:variantWithPayloads) => void = function (Arg1: any) { - const result = VariantsWithPayloadBS.printVariantWithPayloads(typeof(Arg1) === 'object' - ? Arg1.tag==="B" - ? {TAG: 0, _0:Arg1.value} as any - : Arg1.tag==="C" - ? {TAG: 1, _0:Arg1.value[0], _1:Arg1.value[1]} as any - : Arg1.tag==="D" - ? {TAG: 2, _0:Arg1.value} as any - : {TAG: 3, _0:Arg1.value[0], _1:Arg1.value[1], _2:Arg1.value[2]} as any - : $$toRE13337556[Arg1]); - return result -}; - -export const testVariant1Int: (x:variant1Int) => variant1Int = function (Arg1: any) { - const result = VariantsWithPayloadBS.testVariant1Int({TAG: 0, _0:Arg1.value} as any); - return {tag:"R", value:result._0} -}; - -export const testVariant1Object: (x:variant1Object) => variant1Object = function (Arg1: any) { - const result = VariantsWithPayloadBS.testVariant1Object({TAG: 0, _0:Arg1} as any); - return result._0 -}; +export const testSimpleVariant: (x:simpleVariant) => simpleVariant = VariantsWithPayloadBS.testSimpleVariant; + +export const testVariantWithPayloads: (x:variantWithPayloads) => variantWithPayloads = VariantsWithPayloadBS.testVariantWithPayloads; + +export const printVariantWithPayloads: (x:variantWithPayloads) => void = VariantsWithPayloadBS.printVariantWithPayloads; + +export const testVariant1Int: (x:variant1Int) => variant1Int = VariantsWithPayloadBS.testVariant1Int; + +export const testVariant1Object: (x:variant1Object) => variant1Object = VariantsWithPayloadBS.testVariant1Object; diff --git a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res index cafe5347a7..0fc87dc5b6 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res +++ b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res @@ -52,7 +52,7 @@ type simpleVariant = @genType type variantWithPayloads = - | @genType.as("ARenamed") A + | A | B(int) | C(int, int) | D((int, int)) diff --git a/jscomp/gentype_tests/typescript-react-example/src/Warnings.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Warnings.gen.tsx index 9eb058b917..ba56d1cfc8 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Warnings.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Warnings.gen.tsx @@ -6,4 +6,4 @@ import * as WarningsBS__Es6Import from './Warnings.bs'; const WarningsBS: any = WarningsBS__Es6Import; -export const ddd: number = WarningsBS.x; +export const x: number = WarningsBS.ddd; diff --git a/jscomp/gentype_tests/typescript-react-example/src/counter.bs.js b/jscomp/gentype_tests/typescript-react-example/src/counter.bs.js index 02873b3e0b..10458c1307 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/counter.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/counter.bs.js @@ -1,7 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -var b = /* A */{ +var b = { + TAG: "A", _0: 12 }; diff --git a/jscomp/gentype_tests/typescript-react-example/src/counter.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/counter.gen.tsx index 64cbda543c..58a59a93e3 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/counter.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/counter.gen.tsx @@ -8,4 +8,4 @@ const counterBS: any = counterBS__Es6Import; import type {aa as Machine_aa} from './Machine.gen'; -export const b: Machine_aa = {tag:"A", value:counterBS.b._0}; +export const b: Machine_aa = counterBS.b; diff --git a/jscomp/gentype_tests/typescript-react-example/src/index.tsx b/jscomp/gentype_tests/typescript-react-example/src/index.tsx index 9b209c8cf1..179abad72d 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/index.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/index.tsx @@ -90,8 +90,8 @@ consoleLog( Variants.testConvert2to3('module') ); consoleLog( - "Variants: testConvert3to2('42') =", - Variants.testConvert2to3('42') + "Variants: testConvert3to2(42) =", + Variants.testConvert2to3(42) ); const absoluteValueInstance = new MyMath.AbsoluteValue(); @@ -114,12 +114,12 @@ printManyPayloads({ NAME: "one", VAL: 34 }); printManyPayloads({ NAME: "two", VAL: ["hello", "world"] }); printManyPayloads(testManyPayloads({ NAME: "three", VAL: { x: 15 } })); -printVariantWithPayloads(testVariantWithPayloads("ARenamed")); -printVariantWithPayloads(testVariantWithPayloads({ tag: "B", value: 4 })); -printVariantWithPayloads(testVariantWithPayloads({ tag: "C", value: [1, 2] })); -printVariantWithPayloads(testVariantWithPayloads({ tag: "D", value: [1, 2] })); +printVariantWithPayloads(testVariantWithPayloads("A")); +printVariantWithPayloads(testVariantWithPayloads({ TAG: "B", _0: 4 })); +printVariantWithPayloads(testVariantWithPayloads({ TAG: "C", _0:1, _1:2 })); +printVariantWithPayloads(testVariantWithPayloads({ TAG: "D", _0:1, _1:2 })); printVariantWithPayloads( - testVariantWithPayloads({ tag: "E", value: [1, "hello", 2] }) + testVariantWithPayloads({ TAG: "E", _0:1, _1:"hello", _2:2 }) ); TestPromise.convert(Promise.resolve({ x: 3, s: "hello" })).then((x) => diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Tuples.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/nested/Tuples.gen.tsx index 67223c651e..1419d29251 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/nested/Tuples.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Tuples.gen.tsx @@ -2,10 +2,6 @@ /* eslint-disable import/first */ -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // @ts-ignore: Implicit any on import import * as TuplesBS__Es6Import from './Tuples.bs'; const TuplesBS: any = TuplesBS__Es6Import; @@ -32,16 +28,10 @@ export const computeAreaWithIdent: (param:coord) => number = TuplesBS.computeAre export const computeAreaNoConverters: (param:[number, number]) => number = TuplesBS.computeAreaNoConverters; -export const coord2d: (x:T1, y:T2) => [T1, T2, (undefined | T3)] = function (Arg1: any, Arg2: any) { - const result = Curry._2(TuplesBS.coord2d, Arg1, Arg2); - return result -}; +export const coord2d: (x:T1, y:T2) => [T1, T2, (undefined | T3)] = TuplesBS.coord2d; export const getFirstName: (param:couple) => string = TuplesBS.getFirstName; -export const marry: (first:person, second:person) => couple = function (Arg1: any, Arg2: any) { - const result = Curry._2(TuplesBS.marry, Arg1, Arg2); - return result -}; +export const marry: (first:person, second:person) => couple = TuplesBS.marry; export const changeSecondAge: (param:couple) => couple = TuplesBS.changeSecondAge; diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx index 3195af09e6..3d4974ee56 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx @@ -2,10 +2,6 @@ /* eslint-disable import/first */ -// @ts-ignore: Implicit any on import -import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; -const Curry: any = Curry__Es6Import; - // @ts-ignore: Implicit any on import import * as TypesBS__Es6Import from './Types.bs'; const TypesBS: any = TypesBS__Es6Import; @@ -25,8 +21,8 @@ export type t = number; // tslint:disable-next-line:interface-over-type-literal export type typeWithVars = - { tag: "A"; value: [x, y] } - | { tag: "B"; value: z }; + { TAG: "A"; _0: x; _1: y } + | { TAG: "B"; _0: z }; // tslint:disable-next-line:interface-over-type-literal export type tree = { @@ -115,10 +111,7 @@ export type tPrimed = [TypeNameSanitize_t_, TypeNameSanitize_M_t__]; export const someIntList: list = TypesBS.someIntList; -export const map: (_1:((_1:T1) => T2), _2:list) => list = function (Arg1: any, Arg2: any) { - const result = Curry._2(TypesBS.map, Arg1, Arg2); - return result -}; +export const map: (_1:((_1:T1) => T2), _2:list) => list = TypesBS.map; export const swap: (tree:tree) => tree = TypesBS.swap; @@ -126,10 +119,7 @@ export const selfRecursiveConverter: (param:selfRecursive) => selfRecursive = Ty export const mutuallyRecursiveConverter: (param:mutuallyRecursiveA) => mutuallyRecursiveB = TypesBS.mutuallyRecursiveConverter; -export const testFunctionOnOptionsAsArgument: (a:(undefined | a), foo:((_1:(undefined | a)) => T1)) => T1 = function (Arg1: any, Arg2: any) { - const result = Curry._2(TypesBS.testFunctionOnOptionsAsArgument, Arg1, Arg2); - return result -}; +export const testFunctionOnOptionsAsArgument: (a:(undefined | a), foo:((_1:(undefined | a)) => T1)) => T1 = TypesBS.testFunctionOnOptionsAsArgument; export const stringT: string = TypesBS.stringT;