├── docs ├── .nojekyll └── index.html ├── src_js ├── types │ └── .gitignore ├── assets │ ├── ocaml.png │ ├── reasonml.png │ ├── re_typescript.png │ └── Assets.re ├── Entry.re ├── Sync.re ├── Worker.re ├── Layout.re └── ExamplePanel.re ├── src ├── js │ ├── examples │ │ ├── typeguards │ │ │ ├── typeof.d.ts │ │ │ ├── instanceof.d.ts │ │ │ ├── meta.json │ │ │ └── keyof.d.ts │ │ ├── literals │ │ │ ├── numeric_literals.d.ts │ │ │ ├── meta.json │ │ │ ├── mixed_literals.d.ts │ │ │ └── string_literals.d.ts │ │ ├── enums │ │ │ ├── enums.d.ts │ │ │ ├── complex_enums.d.ts │ │ │ └── meta.json │ │ ├── arrays │ │ │ ├── meta.json │ │ │ └── arrays.d.ts │ │ ├── tuples │ │ │ ├── meta.json │ │ │ └── tuples.d.ts │ │ ├── unions │ │ │ ├── meta.json │ │ │ ├── parameterized_unions.d.ts │ │ │ ├── recursive_unions.d.ts │ │ │ └── unions.d.ts │ │ ├── any_type │ │ │ ├── meta.json │ │ │ └── any_type.d.ts │ │ ├── imports │ │ │ ├── meta.json │ │ │ ├── import_source.d.ts │ │ │ └── imports.d.ts │ │ ├── functions │ │ │ ├── meta.json │ │ │ ├── inline_functions.d.ts │ │ │ ├── method_signatures.d.ts │ │ │ └── functions.d.ts │ │ ├── intersections │ │ │ ├── meta.json │ │ │ └── intersections.d.ts │ │ ├── type_params │ │ │ ├── meta.json │ │ │ └── type_params.d.ts │ │ ├── interfaces │ │ │ ├── meta.json │ │ │ ├── inline_objects.d.ts │ │ │ ├── basic_interfaces.d.ts │ │ │ └── interface_extension.d.ts │ │ ├── null_undefined │ │ │ ├── meta.json │ │ │ └── null_undefined.d.ts │ │ ├── mapped_object_types │ │ │ ├── meta.json │ │ │ ├── map_keyof.d.ts │ │ │ ├── map_inline.d.ts │ │ │ ├── map_optional.d.ts │ │ │ ├── map_literals.d.ts │ │ │ └── map_type_parameters.d.ts │ │ ├── type_extraction │ │ │ ├── meta.json │ │ │ └── type_extraction.d.ts │ │ └── base_type_declarations │ │ │ ├── meta.json │ │ │ └── base_type_declarations.d.ts │ ├── Re_typescript_js.re │ ├── dune │ ├── fs.re │ ├── example_files.re │ └── generate_examples.js ├── fs │ ├── utils.re │ ├── package_json.atd │ ├── loader_virtual.rei │ ├── loader.re │ ├── file_path.re │ ├── re_typescript_fs.re │ ├── dune │ └── loader_virtual.re ├── printer │ ├── ast_generator_native.rei │ ├── ast_generator_bucklescript.rei │ ├── ast_generator_native.re │ ├── dune │ ├── ast_generator.re │ ├── ast_generator_utils.re │ └── re_typescript_printer.re ├── base │ ├── run_menhir.sh │ ├── dune │ ├── re_typescript_base.re │ ├── parse_info.re │ ├── error.re │ └── parser_token.re ├── config │ ├── parse_info.atd │ ├── dune │ ├── re_typescript_config.re │ ├── bridge.atd │ └── config.atd └── bin │ └── dune ├── tests └── native │ ├── RunTests.re │ ├── __snapshots__ │ ├── arrays.207d122b.0.snapshot │ ├── arrays.207d122b.1.snapshot │ ├── config_flags_effects.ab9a2ad3.0.snapshot │ ├── config_flags_effects.ab9a2ad3.1.snapshot │ ├── tuples.549f0ccf.0.snapshot │ ├── arrays.1a310d3f.0.snapshot │ ├── basic_syntax_for_types.82f6fb38.0.snapshot │ ├── basic_syntax_for_types.82f6fb38.1.snapshot │ ├── basic_syntax_for_types.82f6fb38.2.snapshot │ ├── function_definitions.58f44fb2.0.snapshot │ ├── generates_valid_type_names.539a878e.0.snapshot │ ├── generates_valid_type_names.d86a0797.0.snapshot │ ├── generates_valid_type_names.d86a0797.1.snapshot │ ├── generates_valid_type_names.dca25028.0.snapshot │ ├── generates_valid_type_names.dca25028.2.snapshot │ ├── tuples.6f2c922b.0.snapshot │ ├── clean_enums.4d768d95.0.snapshot │ ├── generates_valid_type_names.dca25028.1.snapshot │ ├── generates_valid_type_names.dca25028.3.snapshot │ ├── tuples.72ea76e0.0.snapshot │ ├── intersection_types.b9af5b99.0.snapshot │ ├── tuples.d80caa3e.0.snapshot │ ├── basic_syntax_for_types.0e270505.0.snapshot │ ├── clean_enums.b8c17ee8.0.snapshot │ ├── reference_resolution.b16fa2fc.0.snapshot │ ├── function_definitions.de8ce31f.0.snapshot │ ├── reference_resolution.4b402e51.0.snapshot │ ├── function_definitions.526ff7aa.0.snapshot │ ├── interfaces.0659e753.0.snapshot │ ├── basic_syntax_for_types.46639c06.0.snapshot │ ├── tuples.0ee5cbbe.0.snapshot │ ├── config_flags_effects.faa41d64.0.snapshot │ ├── function_definitions.d4d55f3b.0.snapshot │ ├── mapped_object_types.9b06b3d2.0.snapshot │ ├── type_parameters_generation_grammar.c333d8a7.0.snapshot │ ├── interface_extension.12936b9c.0.snapshot │ ├── interfaces.10653320.0.snapshot │ ├── type_extractions.df627d0d.0.snapshot │ ├── function_definitions.1dd3d8a0.0.snapshot │ ├── intersection_types.cafc32ac.0.snapshot │ ├── keyof_operator.ea633eae.0.snapshot │ ├── nullable_undefined_unions_are_around_types.674c6164.0.snapshot │ ├── type_parameter_logic.099b94cd.0.snapshot │ ├── keyof_operator.8afb48ce.0.snapshot │ ├── nullable_undefined_unions_are_around_types.a6a789ef.0.snapshot │ ├── type_unions.c8fa2069.0.snapshot │ ├── function_definitions.cbf9b589.0.snapshot │ ├── interface_extension.3c93980a.0.snapshot │ ├── interfaces.1ec58680.0.snapshot │ ├── keyof_operator.b746f32b.0.snapshot │ ├── config_flags_effects.b202c4cf.0.snapshot │ ├── function_definitions.a2ca1b3a.0.snapshot │ ├── config_flags_effects.9d36a70a.0.snapshot │ ├── config_flags_effects.e1c749cb.0.snapshot │ ├── keyof_operator.4dd5e82e.0.snapshot │ ├── nullable_undefined_unions_are_around_types.26790a36.0.snapshot │ ├── config_flags_effects.5bde5409.0.snapshot │ ├── mapped_object_types.07093aa2.0.snapshot │ ├── mapped_object_types.4083180d.0.snapshot │ ├── reference_resolution.1b0dd629.0.snapshot │ ├── type_extractions.7966d398.0.snapshot │ ├── inline_function_definitions.7fa77587.0.snapshot │ ├── keyof_operator.9928ea16.0.snapshot │ ├── type_parameter_logic.83883718.0.snapshot │ ├── config_flags_effects.e1c749cb.1.snapshot │ ├── type_extractions.2799e5bf.0.snapshot │ ├── type_extractions.ed0a3c96.0.snapshot │ ├── type_parameter_logic.37d6992c.0.snapshot │ ├── keyof_operator.cb290a6d.0.snapshot │ ├── function_definitions.d0942ccd.0.snapshot │ ├── function_definitions.d91b9984.0.snapshot │ ├── interfaces.e7af1bc9.0.snapshot │ ├── type_extractions.cc585556.0.snapshot │ ├── type_parameter_logic.f04eeed5.0.snapshot │ ├── config_flags_effects.0822b4c3.0.snapshot │ ├── mapped_object_types.4606c3f9.0.snapshot │ ├── function_definitions.2bb0abfb.0.snapshot │ ├── keyof_operator.ba41fb14.0.snapshot │ ├── mapped_object_types.0a6d083d.0.snapshot │ ├── interface_extension.41ad91ab.0.snapshot │ ├── nullable_undefined_unions_are_around_types.7acf3105.0.snapshot │ ├── type_parameter_logic.4ea66462.0.snapshot │ ├── type_parameter_logic.7a6a9214.0.snapshot │ ├── interface_extension.60855607.0.snapshot │ ├── keyof_operator.85948c28.0.snapshot │ ├── type_extractions.1605987b.0.snapshot │ ├── type_parameter_logic.1a976843.0.snapshot │ ├── inline_function_definitions.bd169eef.0.snapshot │ ├── type_parameter_logic.a794e2cf.0.snapshot │ ├── mapped_object_types.39507417.0.snapshot │ ├── mapped_object_types.afc63d00.0.snapshot │ ├── config_flags_effects.f3b08384.0.snapshot │ ├── mapped_object_types.42475839.0.snapshot │ ├── mixed_unions.d66ff151.0.snapshot │ ├── mapped_object_types.a6981150.0.snapshot │ ├── config_flags_effects.1548e0ef.0.snapshot │ ├── interface_extension.40d51db0.0.snapshot │ ├── number_literal_unions.7b9a9a87.0.snapshot │ ├── type_parameter_logic.f27c896c.0.snapshot │ ├── mapped_object_types.0c1534c3.0.snapshot │ ├── string_literal_unions.cb48e76c.0.snapshot │ ├── type_parameter_logic.aa98ddc4.0.snapshot │ ├── interface_extension.3c99a251.0.snapshot │ ├── mapped_object_types.1dd3551e.0.snapshot │ ├── nullable_undefined_unions_are_around_types.28d1bc50.0.snapshot │ ├── keyof_operator.1d89cb10.0.snapshot │ ├── mapped_object_types.44ed21b7.0.snapshot │ ├── mapped_object_types.e3b7b446.0.snapshot │ ├── mapped_object_types.d1db6328.0.snapshot │ ├── type_unions.a5f0b423.0.snapshot │ ├── mapped_object_types.fa2566ce.0.snapshot │ ├── type_unions.c34a9bc8.0.snapshot │ ├── inline_function_definitions.1b59f527.0.snapshot │ ├── type_unions.2bf5db07.0.snapshot │ ├── mixed_unions.239fb0b7.0.snapshot │ ├── type_parameters_generation_grammar.84e9a21a.0.snapshot │ ├── config_flags_effects.5b9c9a93.0.snapshot │ ├── mapped_object_types.7a88a1da.0.snapshot │ ├── string_literal_unions.cc34917c.0.snapshot │ ├── type_extractions.73402d87.0.snapshot │ ├── mixed_unions.372967e0.0.snapshot │ ├── type_unions.a590181a.0.snapshot │ ├── number_literal_unions.7dc1e4bb.0.snapshot │ ├── type_unions.0fd3a362.0.snapshot │ ├── mapped_object_types.1dc99791.0.snapshot │ ├── string_literal_unions.c31cc892.0.snapshot │ ├── type_parameter_logic.d41c860a.1.snapshot │ ├── function_definitions.c95264d7.0.snapshot │ ├── string_literal_unions.4e633e40.0.snapshot │ ├── type_parameter_logic.d41c860a.0.snapshot │ ├── number_literal_unions.0ede5e77.0.snapshot │ ├── type_unions.42604fa6.0.snapshot │ ├── mapped_object_types.06a30695.0.snapshot │ ├── intersection_types.56082cfd.0.snapshot │ ├── type_parameter_logic.90f51b5b.0.snapshot │ ├── type_unions_should_get_optimized_into_literals_if__.67553d96.0.snapshot │ ├── type_parameter_logic.d8a3eeba.0.snapshot │ ├── type_parameter_logic.41671ba1.0.snapshot │ ├── type_unions_should_get_optimized_into_literals_if__.173aa723.0.snapshot │ ├── type_unions_should_get_optimized_into_literals_if__.7750d934.0.snapshot │ ├── config_flags_effects.ab9a2ad3.2.snapshot │ ├── type_unions_should_get_optimized_into_literals_if__.451bd5c2.0.snapshot │ ├── type_unions_should_get_optimized_into_literals_if__.22cfb2f5.0.snapshot │ ├── type_unions_should_get_optimized_into_literals_if__.346f96f1.0.snapshot │ ├── type_extractions.f5bf7965.0.snapshot │ └── type_unions_should_get_optimized_into_literals_if__.89762c12.0.snapshot │ ├── dune │ ├── Arrays.re │ ├── Enums.re │ ├── TypeSyntax.re │ ├── TypeNames.re │ ├── ReferenceResolution.re │ ├── Intersections.re │ ├── TestFramework.re │ └── Tuples.re ├── esy.lock ├── opam │ ├── seq.base │ │ ├── files │ │ │ ├── seq.install │ │ │ └── META.seq │ │ └── opam │ ├── ocamlfind.1.8.1 │ │ ├── files │ │ │ ├── ocaml-stub │ │ │ └── ocamlfind.install │ │ └── opam │ ├── base-unix.base │ │ └── opam │ ├── base-threads.base │ │ └── opam │ ├── conf-m4.1 │ │ └── opam │ ├── fix.20200131 │ │ └── opam │ ├── ppx_derivers.1.2.1 │ │ └── opam │ ├── result.1.5 │ │ └── opam │ ├── integers.0.4.0 │ │ └── opam │ ├── menhir.20200612 │ │ └── opam │ ├── ppx_yojson_conv_lib.v0.14.0 │ │ └── opam │ ├── menhirLib.20200612 │ │ └── opam │ ├── ppx_tools_versioned.5.4.0 │ │ └── opam │ ├── menhirSdk.20200612 │ │ └── opam │ ├── stdlib-shims.0.1.0 │ │ └── opam │ ├── reason.3.6.0 │ │ └── opam │ ├── js_of_ocaml-ppx.3.6.0 │ │ └── opam │ ├── merlin-extend.0.5 │ │ └── opam │ ├── js_of_ocaml.3.6.0 │ │ └── opam │ ├── junit.2.0.2 │ │ └── opam │ ├── ocamlbuild.0.14.0 │ │ └── opam │ ├── uchar.0.0.2 │ │ └── opam │ ├── re.1.9.0 │ │ └── opam │ ├── cppo.1.6.6 │ │ └── opam │ ├── luv.0.5.2 │ │ └── opam │ ├── dune-private-libs.2.5.1 │ │ └── opam │ ├── yojson.1.7.0 │ │ └── opam │ ├── js_of_ocaml-compiler.3.6.0 │ │ └── opam │ ├── containers.2.8.1 │ │ └── opam │ ├── dune-build-info.2.5.1 │ │ └── opam │ ├── dune-configurator.2.5.1 │ │ └── opam │ ├── ocaml-migrate-parsetree.1.7.3 │ │ └── opam │ ├── uutf.1.0.2 │ │ └── opam │ ├── cmdliner.1.0.4 │ │ └── opam │ ├── tyxml.4.4.0 │ │ └── opam │ ├── conf-pkg-config.1.2 │ │ └── opam │ ├── atdgen-runtime.2.2.1 │ │ └── opam │ ├── ptime.0.8.5 │ │ └── opam │ ├── easy-format.1.3.2 │ │ └── opam │ ├── atd.2.2.1 │ │ └── opam │ ├── biniou.1.2.1 │ │ └── opam │ ├── topkg.1.0.1 │ │ └── opam │ ├── ctypes.0.17.1 │ │ └── opam │ ├── atdgen.2.2.1 │ │ └── opam │ └── dune.2.5.0 │ │ └── opam ├── .gitignore ├── .gitattributes └── overrides │ ├── opam__s__ctypes_opam__c__0.17.1_opam_override │ └── package.json │ ├── opam__s__conf_pkg_config_opam__c__1.2_opam_override │ └── package.json │ ├── opam__s__ocamlbuild_opam__c__0.14.0_opam_override │ └── package.json │ └── opam__s__ocamlfind_opam__c__1.8.1_opam_override │ └── package.json ├── docs.sh ├── ts_inspiration ├── subset.d.ts ├── mapped_with_intersection.d.ts ├── discriminated_union_by_enum.d.ts ├── intersection_mixins.d.ts ├── discriminating_unions.d.ts ├── declare_ namespace.d.ts ├── exported_types_as_global.d.ts ├── intersection.d.ts ├── ___to_fix.d.ts └── global_file_example.d.ts ├── fastpack.json ├── fastpack-worker.json ├── dune ├── .vscode └── settings.json ├── .gitignore ├── types.sh ├── dune-project ├── .github └── workflows │ ├── print_esy_cache.js │ └── pipeline.yml ├── bsconfig.json ├── re_typescript.opam ├── esy.json ├── package.json └── README.md /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src_js/types/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /src/js/examples/typeguards/typeof.d.ts: -------------------------------------------------------------------------------- 1 | // Not yet done 2 | -------------------------------------------------------------------------------- /src/fs/utils.re: -------------------------------------------------------------------------------- 1 | let add_extension = (p: Fp.t('kind)) => {}; 2 | -------------------------------------------------------------------------------- /src/js/examples/typeguards/instanceof.d.ts: -------------------------------------------------------------------------------- 1 | // Not yet done 2 | -------------------------------------------------------------------------------- /src/printer/ast_generator_native.rei: -------------------------------------------------------------------------------- 1 | include Ast_generator.T; 2 | -------------------------------------------------------------------------------- /tests/native/RunTests.re: -------------------------------------------------------------------------------- 1 | Re_typescript_test_lib.TestFramework.cli(); 2 | -------------------------------------------------------------------------------- /esy.lock/opam/seq.base/files/seq.install: -------------------------------------------------------------------------------- 1 | lib:[ 2 | "META.seq" {"META"} 3 | ] 4 | -------------------------------------------------------------------------------- /src/fs/package_json.atd: -------------------------------------------------------------------------------- 1 | type package_json = { 2 | ?types: string option; 3 | } -------------------------------------------------------------------------------- /src/js/examples/literals/numeric_literals.d.ts: -------------------------------------------------------------------------------- 1 | type num_literal = 2 | 4 | 8 | 12; 2 | -------------------------------------------------------------------------------- /docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | esy js-release 3 | yarn types 4 | yarn fpack 5 | yarn fpack-worker -------------------------------------------------------------------------------- /src/base/run_menhir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | menhir parser.mly --dump --explain --unused-tokens -------------------------------------------------------------------------------- /src/js/examples/enums/enums.d.ts: -------------------------------------------------------------------------------- 1 | export enum enum_1 { 2 | Red, 3 | Green, 4 | Blue, 5 | } 6 | -------------------------------------------------------------------------------- /esy.lock/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Reset any possible .gitignore, we want all esy.lock to be un-ignored. 3 | !* 4 | -------------------------------------------------------------------------------- /src_js/assets/ocaml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsiebern/re-typescript/HEAD/src_js/assets/ocaml.png -------------------------------------------------------------------------------- /src/js/examples/enums/complex_enums.d.ts: -------------------------------------------------------------------------------- 1 | // Complex enums (e.g. with default values) are not yet implemented 2 | -------------------------------------------------------------------------------- /src_js/assets/reasonml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsiebern/re-typescript/HEAD/src_js/assets/reasonml.png -------------------------------------------------------------------------------- /src/js/examples/arrays/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Arrays", 3 | "description": "", 4 | "entry": "arrays.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/enums/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Enums", 3 | "description": "", 4 | "entry": "enums.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/tuples/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Tuples", 3 | "description": "", 4 | "entry": "tuples.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/unions/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unions", 3 | "description": "", 4 | "entry": "unions.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/any_type/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Any type", 3 | "description": "", 4 | "entry": "any_type.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/imports/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Imports", 3 | "description": "", 4 | "entry": "imports.d.ts" 5 | } -------------------------------------------------------------------------------- /src_js/assets/re_typescript.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsiebern/re-typescript/HEAD/src_js/assets/re_typescript.png -------------------------------------------------------------------------------- /src/js/examples/functions/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Functions", 3 | "description": "", 4 | "entry": "functions.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/tuples/tuples.d.ts: -------------------------------------------------------------------------------- 1 | type tpl_1 = [string, string, number]; 2 | type tpl_2 = [boolean, { inline: boolean }]; 3 | -------------------------------------------------------------------------------- /src_js/Entry.re: -------------------------------------------------------------------------------- 1 | ReactDOMRe.renderToElementWithId( 2 | , 3 | "app", 4 | ); -------------------------------------------------------------------------------- /src/js/examples/literals/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Literals", 3 | "description": "", 4 | "entry": "string_literals.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/typeguards/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Typeguards", 3 | "description": "", 4 | "entry": "keyof.d.ts" 5 | } 6 | -------------------------------------------------------------------------------- /esy.lock/.gitattributes: -------------------------------------------------------------------------------- 1 | 2 | # Set eol to LF so files aren't converted to CRLF-eol on Windows. 3 | * text eol=lf linguist-generated 4 | -------------------------------------------------------------------------------- /src/js/examples/arrays/arrays.d.ts: -------------------------------------------------------------------------------- 1 | // --- Array declarations 2 | type arr_of_bool = Array; 3 | type arr_of_string = string[]; 4 | -------------------------------------------------------------------------------- /src/js/examples/intersections/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Intersections", 3 | "description": "", 4 | "entry": "intersections.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/type_params/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Type parameters", 3 | "description": "", 4 | "entry": "type_params.d.ts" 5 | } -------------------------------------------------------------------------------- /tests/native/__snapshots__/arrays.207d122b.0.snapshot: -------------------------------------------------------------------------------- 1 | arrays › arrays in record field defs 2 | type obj = {field: array(string)}; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/arrays.207d122b.1.snapshot: -------------------------------------------------------------------------------- 1 | arrays › arrays in record field defs 2 | type obj = {field: array(string)}; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.ab9a2ad3.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › number_mode 2 | type t_number = float; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.ab9a2ad3.1.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › number_mode 2 | type t_number = int; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/tuples.549f0ccf.0.snapshot: -------------------------------------------------------------------------------- 1 | tuples › generates base type tuple 2 | type tpl = (string, float, bool); 3 | 4 | -------------------------------------------------------------------------------- /ts_inspiration/subset.d.ts: -------------------------------------------------------------------------------- 1 | export declare type Subset = { 2 | [key in keyof T]: key extends keyof U ? T[key] : never; 3 | }; 4 | -------------------------------------------------------------------------------- /src/config/parse_info.atd: -------------------------------------------------------------------------------- 1 | type t = { 2 | src: string option; 3 | name: string option; 4 | col: int; 5 | line: int; 6 | idx: int; 7 | } -------------------------------------------------------------------------------- /src/fs/loader_virtual.rei: -------------------------------------------------------------------------------- 1 | module type Config = {let tbl: Hashtbl.t(Fp.t(Fp.absolute), string);}; 2 | module Make: (Config) => Loader.T; 3 | -------------------------------------------------------------------------------- /src/js/examples/interfaces/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Interfaces", 3 | "description": "", 4 | "entry": "basic_interfaces.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/null_undefined/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Null / Undefined", 3 | "description": "", 4 | "entry": "null_undefined.d.ts" 5 | } -------------------------------------------------------------------------------- /ts_inspiration/mapped_with_intersection.d.ts: -------------------------------------------------------------------------------- 1 | type PartialWithNewMember = { 2 | [P in keyof T]?: T[P]; 3 | } & { newMember: boolean }; 4 | -------------------------------------------------------------------------------- /fastpack.json: -------------------------------------------------------------------------------- 1 | { 2 | "entryPoints": ["lib/js/src_js/Entry.bs.js"], 3 | "outputDir": "docs/index", 4 | "outputFilename": "index.js" 5 | } 6 | -------------------------------------------------------------------------------- /src/js/examples/literals/mixed_literals.d.ts: -------------------------------------------------------------------------------- 1 | type mixed_literal_1 = 2 | "string" | 8 | "other_string"; 2 | type mixed_literal_2 = false | 1; 3 | -------------------------------------------------------------------------------- /src/js/examples/typeguards/keyof.d.ts: -------------------------------------------------------------------------------- 1 | interface A { 2 | x: string; 3 | y: number; 4 | } 5 | type B = A | undefined; 6 | type keys = keyof B; 7 | -------------------------------------------------------------------------------- /src/js/examples/mapped_object_types/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Mapped object types", 3 | "description": "", 4 | "entry": "map_literals.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/type_extraction/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Type extraction", 3 | "description": "", 4 | "entry": "type_extraction.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/unions/parameterized_unions.d.ts: -------------------------------------------------------------------------------- 1 | type ValueOrObj = T | { obj_value: T }; 2 | type ValueOrArray = T | Array>; 3 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/arrays.1a310d3f.0.snapshot: -------------------------------------------------------------------------------- 1 | arrays › arrays of inline records 2 | type x_t = {field: string} 3 | and x = array(x_t); 4 | 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/basic_syntax_for_types.82f6fb38.0.snapshot: -------------------------------------------------------------------------------- 1 | basic syntax for types › basic type definition 2 | type t_string = string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/basic_syntax_for_types.82f6fb38.1.snapshot: -------------------------------------------------------------------------------- 1 | basic syntax for types › basic type definition 2 | type t_number = float; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/basic_syntax_for_types.82f6fb38.2.snapshot: -------------------------------------------------------------------------------- 1 | basic syntax for types › basic type definition 2 | type t_bool = bool; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.58f44fb2.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › simple function 2 | type someFunction = unit => unit; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/generates_valid_type_names.539a878e.0.snapshot: -------------------------------------------------------------------------------- 1 | generates valid type names › capitalized 2 | type t_string = string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/generates_valid_type_names.d86a0797.0.snapshot: -------------------------------------------------------------------------------- 1 | generates valid type names › reserved keyword 2 | type rec_ = string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/generates_valid_type_names.d86a0797.1.snapshot: -------------------------------------------------------------------------------- 1 | generates valid type names › reserved keyword 2 | type sig_ = string; 3 | 4 | -------------------------------------------------------------------------------- /fastpack-worker.json: -------------------------------------------------------------------------------- 1 | { 2 | "entryPoints": ["lib/js/src_js/Worker.bs.js"], 3 | "outputDir": "docs/worker", 4 | "outputFilename": "worker.js" 5 | } 6 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/generates_valid_type_names.dca25028.0.snapshot: -------------------------------------------------------------------------------- 1 | generates valid type names › invalid characters 2 | type st_ring = string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/generates_valid_type_names.dca25028.2.snapshot: -------------------------------------------------------------------------------- 1 | generates valid type names › invalid characters 2 | type __string = string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/tuples.6f2c922b.0.snapshot: -------------------------------------------------------------------------------- 1 | tuples › can use tuple inside of an interface 2 | type obj = {field: (string, float, bool)}; 3 | 4 | -------------------------------------------------------------------------------- /dune: -------------------------------------------------------------------------------- 1 | (dirs src tests) 2 | 3 | (env 4 | (dev 5 | (flags 6 | (:standard -w -32-33-42-27))) 7 | (release 8 | (flags 9 | (:standard -O3)))) 10 | -------------------------------------------------------------------------------- /esy.lock/opam/ocamlfind.1.8.1/files/ocaml-stub: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | BINDIR=$(dirname "$(command -v ocamlc)") 4 | "$BINDIR/ocaml" -I "$OCAML_TOPLEVEL_PATH" "$@" 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/clean_enums.4d768d95.0.snapshot: -------------------------------------------------------------------------------- 1 | clean enums › generates uppercase keys 2 | type enum = 3 | | Red 4 | | Green 5 | | Blue; 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/generates_valid_type_names.dca25028.1.snapshot: -------------------------------------------------------------------------------- 1 | generates valid type names › invalid characters 2 | type t__string = string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/generates_valid_type_names.dca25028.3.snapshot: -------------------------------------------------------------------------------- 1 | generates valid type names › invalid characters 2 | type t__string = string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/tuples.72ea76e0.0.snapshot: -------------------------------------------------------------------------------- 1 | tuples › merges extracted tuple members back if possible 2 | type tpl = (string, (float, bool)); 3 | 4 | -------------------------------------------------------------------------------- /src/js/examples/base_type_declarations/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Base type declarations", 3 | "description": "", 4 | "entry": "base_type_declarations.d.ts" 5 | } -------------------------------------------------------------------------------- /src/js/examples/unions/recursive_unions.d.ts: -------------------------------------------------------------------------------- 1 | // --- Recursive unions 2 | type union_3 = string | Array; 3 | type union_4 = string | { field: union_4 }; 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/intersection_types.b9af5b99.0.snapshot: -------------------------------------------------------------------------------- 1 | intersection types › can create simple intersection tuple 2 | type tpl = (string, float); 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/tuples.d80caa3e.0.snapshot: -------------------------------------------------------------------------------- 1 | tuples › can use inline interfaces 2 | type tpl_3 = {field: bool} 3 | and tpl = (string, float, tpl_3); 4 | 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ocaml.sandbox": { 3 | "root": "/Users/jonathansiebern/git/Open_Source/re-typescript", 4 | "kind": "esy" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/basic_syntax_for_types.0e270505.0.snapshot: -------------------------------------------------------------------------------- 1 | basic syntax for types › basic type definition without semicolon 2 | type t_string = string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/clean_enums.b8c17ee8.0.snapshot: -------------------------------------------------------------------------------- 1 | clean enums › generates variants from clean enums 2 | type enum = 3 | | Red 4 | | Green 5 | | Blue; 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/reference_resolution.b16fa2fc.0.snapshot: -------------------------------------------------------------------------------- 1 | reference resolution › resolve simple definitions 2 | type t_str = string 3 | and t_ref = t_str; 4 | 5 | -------------------------------------------------------------------------------- /src/js/examples/imports/import_source.d.ts: -------------------------------------------------------------------------------- 1 | export type str = string; 2 | interface iImport { 3 | get: (a: number) => void; 4 | } 5 | 6 | type b = boolean; 7 | export default b; 8 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.de8ce31f.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › function with arguments 2 | type someFunction = (~a: string, ~b: float) => string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/reference_resolution.4b402e51.0.snapshot: -------------------------------------------------------------------------------- 1 | reference resolution › resolve recursively 2 | type i_Ref = { 3 | f_num: float, 4 | f_inner: i_Ref, 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /esy.lock/opam/seq.base/files/META.seq: -------------------------------------------------------------------------------- 1 | name="seq" 2 | version="[distributed with OCaml 4.07 or above]" 3 | description="dummy backward-compatibility package for iterators" 4 | requires="" 5 | -------------------------------------------------------------------------------- /src/fs/loader.re: -------------------------------------------------------------------------------- 1 | module type T = { 2 | let fs_name: string; 3 | let file_read: Fp.t(Fp.absolute) => CCResult.t(string, string); 4 | let file_exists: Fp.t(Fp.absolute) => bool; 5 | }; 6 | -------------------------------------------------------------------------------- /src/printer/ast_generator_bucklescript.rei: -------------------------------------------------------------------------------- 1 | module type Config = { 2 | let config: Re_typescript_config.Config.bucklescript_config; 3 | }; 4 | module Make: (Config) => Ast_generator.T; 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.526ff7aa.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › functions accept type parameters 2 | type someFunction('A, 'B, 'C) = (~a: 'A, ~b: 'B) => 'C; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interfaces.0659e753.0.snapshot: -------------------------------------------------------------------------------- 1 | interfaces › empty interface should not be omitted when extened 2 | type i_b = {field: string} 3 | and i_a = {field: string}; 4 | 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/basic_syntax_for_types.46639c06.0.snapshot: -------------------------------------------------------------------------------- 1 | basic syntax for types › adds extra type for any 2 | [@unboxed] 3 | type any = 4 | | Any('a): any; 5 | type t_any = any; 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/tuples.0ee5cbbe.0.snapshot: -------------------------------------------------------------------------------- 1 | tuples › can generate an array of tuples 2 | type tpl_arr = array((string, float, bool)) 3 | and tpl_arr2 = array((string, float, bool)); 4 | 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.faa41d64.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › omit_extended_unreferenced_records - on 2 | type i_2 = { 3 | field1: string, 4 | field2: bool, 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.d4d55f3b.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › function with optional arguments 2 | type someFunction = (~a: string, ~b: option(float)=?, unit) => string; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.9b06b3d2.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › map over a single string literal 2 | type key = 3 | | Just_one_key 4 | and flags = {just_one_key: bool}; 5 | 6 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameters_generation_grammar.c333d8a7.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameters generation & grammar › prints correct generics for type parameters 2 | type with_param('ARG) = 'ARG; 3 | 4 | -------------------------------------------------------------------------------- /esy.lock/opam/base-unix.base/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "https://github.com/ocaml/opam-repository/issues" 3 | description: """ 4 | Unix library distributed with the OCaml compiler 5 | """ 6 | 7 | -------------------------------------------------------------------------------- /src/js/examples/any_type/any_type.d.ts: -------------------------------------------------------------------------------- 1 | // --- Any: A separate any type will be created that is marked as unboxed 2 | // --- Currently this would need to be decoded via %identity access 3 | type whatever = any; 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interface_extension.12936b9c.0.snapshot: -------------------------------------------------------------------------------- 1 | interface extension › resolves single call signatures in an interface 2 | type keyValueProcessor = (~key: float, ~value: string) => bool; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interfaces.10653320.0.snapshot: -------------------------------------------------------------------------------- 1 | interfaces › empty objects should be referenced as any 2 | [@unboxed] 3 | type any = 4 | | Any('a): any; 5 | type i_a = any 6 | and x = i_a; 7 | 8 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_extractions.df627d0d.0.snapshot: -------------------------------------------------------------------------------- 1 | type extractions › can create an array after the access 2 | type c = { 3 | a: string, 4 | b: float, 5 | } 6 | and d = array(string); 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .merlin 2 | node_modules/ 3 | _build 4 | _esy 5 | _release 6 | *.byte 7 | *.native 8 | *.install 9 | .DS_Store 10 | .parcel-cache 11 | dist 12 | lib 13 | *.bs.js 14 | .bsb.lock 15 | bundle 16 | notes -------------------------------------------------------------------------------- /esy.lock/opam/base-threads.base/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "https://github.com/ocaml/opam-repository/issues" 3 | description: """ 4 | Threads library distributed with the OCaml compiler 5 | """ 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.1dd3d8a0.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › untyped return becomes any 2 | [@unboxed] 3 | type any = 4 | | Any('a): any; 5 | type someFunction = unit => any; 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/intersection_types.cafc32ac.0.snapshot: -------------------------------------------------------------------------------- 1 | intersection types › can create simple intersection tuple with references 2 | type num_opt = option(float) 3 | and tpl = (string, num_opt); 4 | 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.ea633eae.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › extracts keys from an object 2 | type a = { 3 | x: string, 4 | y: float, 5 | } 6 | and keys = 7 | | X 8 | | Y; 9 | 10 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/nullable_undefined_unions_are_around_types.674c6164.0.snapshot: -------------------------------------------------------------------------------- 1 | nullable / undefined unions are around types › undefined for single base types 2 | type opt_string = option(string); 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.099b94cd.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › does not throw when construcing a faulty type, but will throw on call site 2 | type with_param('a1, 'a2, 'a3) = 'a3; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.8afb48ce.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › extracts keys from an interface 2 | type a = { 3 | x: string, 4 | y: float, 5 | } 6 | and keys = 7 | | X 8 | | Y; 9 | 10 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/nullable_undefined_unions_are_around_types.a6a789ef.0.snapshot: -------------------------------------------------------------------------------- 1 | nullable / undefined unions are around types › nullable for single base types 2 | type null_string = Js.Nullable.t(string); 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions.c8fa2069.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions › can create a nullable of an interface 2 | type some_interface_t = {field: bool} 3 | and some_interface = Js.Nullable.t(some_interface_t); 4 | 5 | -------------------------------------------------------------------------------- /esy.lock/opam/ocamlfind.1.8.1/files/ocamlfind.install: -------------------------------------------------------------------------------- 1 | bin: [ 2 | "src/findlib/ocamlfind" {"ocamlfind"} 3 | "?src/findlib/ocamlfind_opt" {"ocamlfind"} 4 | "?tools/safe_camlp4" 5 | ] 6 | toplevel: ["src/findlib/topfind"] 7 | -------------------------------------------------------------------------------- /src/printer/ast_generator_native.re: -------------------------------------------------------------------------------- 1 | open Migrate_parsetree; 2 | 3 | let generate = (~ctx, _) => 4 | raise( 5 | Tree_utils.Exceptions.Parser_unexpected( 6 | "Cannot generate native mode yet", 7 | ), 8 | ); 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.cbf9b589.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › function returns get merged back if not referenced otherwise 2 | type someFunction('A, 'B, 'C) = (~a: 'A, ~b: 'B) => ('B, 'C); 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interface_extension.3c93980a.0.snapshot: -------------------------------------------------------------------------------- 1 | interface extension › resolves single call signatures in an interface inline 2 | type keyValueProcessor = {both: (~key: float, ~value: string) => bool}; 3 | 4 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interfaces.1ec58680.0.snapshot: -------------------------------------------------------------------------------- 1 | interfaces › empty interface can be target of an extension 2 | [@unboxed] 3 | type any = 4 | | Any('a): any; 5 | type i_a = any 6 | and i_b = {field: string}; 7 | 8 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.b746f32b.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › extracts keys from an inline object 2 | type keys_t = { 3 | x: string, 4 | y: float, 5 | } 6 | and keys = 7 | | X 8 | | Y; 9 | 10 | -------------------------------------------------------------------------------- /src/bin/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name bin) 3 | (public_name re_typescript) 4 | (libraries reason re_typescript.base re_typescript.printer 5 | file-context-printer.lib console.lib pastel.lib) 6 | (ocamlopt_flags (-linkall))) 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.b202c4cf.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › omit_extended_unreferenced_records - on (omits warning if enabled) 2 | type i_2 = { 3 | field1: string, 4 | field2: bool, 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.a2ca1b3a.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › untyped type arguments become any 2 | [@unboxed] 3 | type any = 4 | | Any('a): any; 5 | type someFunction = (~a: any) => string; 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.9d36a70a.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › omit_extended_unreferenced_records - off 2 | type i_1 = {field1: string} 3 | and i_2 = { 4 | field1: string, 5 | field2: bool, 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.e1c749cb.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › suppress_warning_for_extended_records 2 | type i_1 = {field1: string} 3 | and i_2 = { 4 | field1: string, 5 | field2: bool, 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.4dd5e82e.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › extracts keys from a type alias 2 | type a = { 3 | x: string, 4 | y: float, 5 | } 6 | and b = a 7 | and keys = 8 | | X 9 | | Y; 10 | 11 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/nullable_undefined_unions_are_around_types.26790a36.0.snapshot: -------------------------------------------------------------------------------- 1 | nullable / undefined unions are around types › undefined & nullable can be nested 2 | type opt_null_string = option(Js.Nullable.t(string)); 3 | 4 | -------------------------------------------------------------------------------- /src/js/examples/null_undefined/null_undefined.d.ts: -------------------------------------------------------------------------------- 1 | // --- Unions that contain null / undefined are wrapped in the conversion 2 | type s_null = string | null; 3 | type s_opt = string | undefined; 4 | type s_null_opt = string | null | undefined; 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.5bde5409.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › omit_extended_unreferenced_records - on (extension chain) 2 | type i_3 = { 3 | field1: string, 4 | field2: bool, 5 | field3: float, 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.07093aa2.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › map over predefined keys 2 | type keys = 3 | | Option1 4 | | Option2 5 | and flags = { 6 | option1: bool, 7 | option2: bool, 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.4083180d.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › map over inlined keys 2 | type flags_K = 3 | | Option1 4 | | Option2 5 | and flags = { 6 | option1: bool, 7 | option2: bool, 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/reference_resolution.1b0dd629.0.snapshot: -------------------------------------------------------------------------------- 1 | reference resolution › resolve in interface fields 2 | type t_str = string 3 | and i_Ref = { 4 | f_num: float, 5 | f_str: t_str, 6 | } 7 | and r_ref = {inner: i_Ref}; 8 | 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_extractions.7966d398.0.snapshot: -------------------------------------------------------------------------------- 1 | type extractions › properly converts key names to resolve references 2 | type obj = { 3 | [@bs.as \"I_BigField\"] 4 | i_BigField: string, 5 | } 6 | and field_1 = string; 7 | 8 | -------------------------------------------------------------------------------- /src/js/examples/functions/inline_functions.d.ts: -------------------------------------------------------------------------------- 1 | // --- Inline function definitions 2 | interface i_inline_function { 3 | field: string; 4 | action: (a: string, b?: number) => void; 5 | } 6 | type i_inline_access = i_inline_function["action"]; 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/inline_function_definitions.7fa77587.0.snapshot: -------------------------------------------------------------------------------- 1 | inline function definitions › inline function in a function definition 2 | type func = 3 | (~a: string, ~b: (~a: string, ~b: option(float)=?, unit) => string) => unit; 4 | 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.9928ea16.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › extracts keys from an optional wrapper 2 | type a = { 3 | x: string, 4 | y: float, 5 | } 6 | and b = option(a) 7 | and keys = 8 | | X 9 | | Y; 10 | 11 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.83883718.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › can use various default structures 2 | type with_param_a = (string, float) 3 | and with_param('a) = 'a 4 | and call_params = with_param(with_param_a); 5 | 6 | -------------------------------------------------------------------------------- /src/js/examples/base_type_declarations/base_type_declarations.d.ts: -------------------------------------------------------------------------------- 1 | // --- Base type declarations 2 | type s = string; 3 | type n = number; // re-typescript has different number resolution modes, default is "float" 4 | type b = boolean; 5 | type v = void; 6 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.e1c749cb.1.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › suppress_warning_for_extended_records 2 | [@warning \"-30\"]; 3 | type i_1 = {field1: string} 4 | and i_2 = { 5 | field1: string, 6 | field2: bool, 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_extractions.2799e5bf.0.snapshot: -------------------------------------------------------------------------------- 1 | type extractions › can extract a base type from an obj / interface 2 | type obj = { 3 | field_1: string, 4 | field_2: bool, 5 | } 6 | and field_1 = string 7 | and field_2 = bool; 8 | 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_extractions.ed0a3c96.0.snapshot: -------------------------------------------------------------------------------- 1 | type extractions › can resolve inline interfaces 2 | type obj_field_2 = {field_3: bool} 3 | and obj = { 4 | field_1: float, 5 | field_2: obj_field_2, 6 | } 7 | and field_1 = bool; 8 | 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.37d6992c.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › resolves nested params 2 | type a('X) = {field_x: 'X} 3 | and b('Y, 'Z) = { 4 | field_y: 'Y, 5 | field_z: 'Z, 6 | } 7 | and apply = b(a(bool), float); 8 | 9 | -------------------------------------------------------------------------------- /esy.lock/overrides/opam__s__ctypes_opam__c__0.17.1_opam_override/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "exportedEnv": { 3 | "CAML_LD_LIBRARY_PATH": { 4 | "val": "#{self.lib / 'ctypes' : $CAML_LD_LIBRARY_PATH}", 5 | "scope": "global" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.cb290a6d.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › extracts mixed keys if necessary 2 | type a = { 3 | x: string, 4 | [@bs.as \"3\"] 5 | _3: float, 6 | y: bool, 7 | } 8 | and keys = 9 | | X 10 | | _3 11 | | Y; 12 | 13 | -------------------------------------------------------------------------------- /src/js/examples/interfaces/inline_objects.d.ts: -------------------------------------------------------------------------------- 1 | type array_of_inline = Array<{ inline: boolean }>; 2 | interface IInline { 3 | field_1: string; 4 | inline: { 5 | field: number; 6 | nested: { 7 | nested_field: boolean; 8 | }; 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.d0942ccd.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › function with return type 2 | type someFunction = unit => string 3 | and someOtherFunction_return = {inline: string} 4 | and someOtherFunction = unit => someOtherFunction_return; 5 | 6 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.d91b9984.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › inline obj union as function return type 2 | type someOtherFunction_return_t = {inline: string} 3 | and someOtherFunction = unit => Js.Nullable.t(someOtherFunction_return_t); 4 | 5 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interfaces.e7af1bc9.0.snapshot: -------------------------------------------------------------------------------- 1 | interfaces › nested interfaces 2 | type i_a_field_3 = { 3 | inline: bool, 4 | nested: string, 5 | } 6 | and i_a = { 7 | field_1: string, 8 | field_2: string, 9 | field_3: i_a_field_3, 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_extractions.cc585556.0.snapshot: -------------------------------------------------------------------------------- 1 | type extractions › can extract a field from a reference 2 | type i_int = {i_field: float} 3 | and obj = { 4 | field_1: string, 5 | [@bs.as \"if\"] 6 | if_: i_int, 7 | } 8 | and field_1 = float; 9 | 10 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.f04eeed5.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › can have nested default values 2 | type orig_param('a) = 'a 3 | and with_param_a = {b: orig_param(float)} 4 | and with_param('a) = 'a 5 | and call_params = with_param(with_param_a); 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.0822b4c3.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › omit_extended_unreferenced_records - on (resolves type params correctly, even if omitting the interface) 2 | type i_2('A, 'C) = { 3 | field1: 'A, 4 | field2: bool, 5 | field3: 'C, 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.4606c3f9.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › map over predefined keys through a reference 2 | type keys = 3 | | Option1 4 | | Option2 5 | and keysRef = keys 6 | and flags = { 7 | option1: bool, 8 | option2: bool, 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.2bb0abfb.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › function parameters get merged back if not referenced otherwise 2 | type someFunction_b_2 = {field: string} 3 | and someFunction = 4 | (~a: float, ~b: (float, someFunction_b_2)) => (string, bool); 5 | 6 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.ba41fb14.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › extracts keys from a type extraction 2 | type a_b = { 3 | z: bool, 4 | f: string, 5 | } 6 | and a = { 7 | x: string, 8 | y: float, 9 | b: a_b, 10 | } 11 | and keys = 12 | | Z 13 | | F; 14 | 15 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.0a6d083d.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › can use type param (no extraction) as map target 2 | type record_0 = 3 | | A 4 | | B 5 | and record_1 = {field: bool} 6 | and record = { 7 | a: record_1, 8 | b: record_1, 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /src/js/examples/imports/imports.d.ts: -------------------------------------------------------------------------------- 1 | // --- Simple imports 2 | import IsOk from "./import_source"; 3 | import { str } from "./import_source"; 4 | import * as Others from "./import_source"; 5 | 6 | type should_be_bool = IsOk; 7 | type should_be_string = str; 8 | type should_be_obj = Others.iImport; 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interface_extension.41ad91ab.0.snapshot: -------------------------------------------------------------------------------- 1 | interface extension › adds fields from other interfaces 2 | type i_a = { 3 | field_1: string, 4 | field_2: string, 5 | } 6 | and i_b = { 7 | field_1: string, 8 | field_2: string, 9 | field_3: float, 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/nullable_undefined_unions_are_around_types.7acf3105.0.snapshot: -------------------------------------------------------------------------------- 1 | nullable / undefined unions are around types › nullable/undefined for single base types on record fields 2 | type obj = { 3 | opt_string: option(string), 4 | null_string: Js.Nullable.t(string), 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.4ea66462.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › can have inline records as defaults 2 | type with_param_a2 = {inline: bool} 3 | and with_param('a1, 'a2) = { 4 | a1: 'a1, 5 | a2: 'a2, 6 | } 7 | and call_params = with_param(string, with_param_a2); 8 | 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.7a6a9214.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › reference inline params work inside a nested interface 2 | type iParamNested_field2('B) = {field3: 'B} 3 | and iParamNested('A, 'B) = { 4 | field1: 'A, 5 | field2: iParamNested_field2('B), 6 | }; 7 | 8 | -------------------------------------------------------------------------------- /src/js/examples/type_extraction/type_extraction.d.ts: -------------------------------------------------------------------------------- 1 | // --- Basic type extraction 2 | type obj_1 = { key: string }; 3 | interface IExtraction { 4 | key_1: boolean; 5 | key_2: obj_1; 6 | } 7 | type extracted_bool = IExtraction["key_1"]; 8 | type extracted_string_nested = IExtraction["key_2"]["key"]; 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interface_extension.60855607.0.snapshot: -------------------------------------------------------------------------------- 1 | interface extension › fields from current interface take priority 2 | type i_a = { 3 | field_1: string, 4 | field_2: string, 5 | } 6 | and i_b = { 7 | field_2: string, 8 | field_1: bool, 9 | field_3: float, 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.85948c28.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › extracts keys from an extended interface 2 | type a = { 3 | x: string, 4 | y: float, 5 | } 6 | and b = { 7 | x: string, 8 | y: float, 9 | z: bool, 10 | } 11 | and keys = 12 | | X 13 | | Y 14 | | Z; 15 | 16 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_extractions.1605987b.0.snapshot: -------------------------------------------------------------------------------- 1 | type extractions › can access recursive references 2 | type iMain_inline = {num: float} 3 | and iMain = { 4 | simple: string, 5 | inline: iMain_inline, 6 | } 7 | and str = string 8 | and obj = iMain_inline 9 | and num = float; 10 | 11 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.1a976843.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › still generates default inline values, even if overriden 2 | type with_param_a2 = {inline: bool} 3 | and with_param('a1, 'a2) = { 4 | a1: 'a1, 5 | a2: 'a2, 6 | } 7 | and call_params = with_param(string, float); 8 | 9 | -------------------------------------------------------------------------------- /src/js/examples/mapped_object_types/map_keyof.d.ts: -------------------------------------------------------------------------------- 1 | // --- Map over a keyof type 2 | type KeysObj = { option1: string; option2: number }; 3 | type Flags_1 = { [K in keyof KeysObj]: boolean }; 4 | 5 | // --- Map over a keyof inline type 6 | type Flags = { [K in keyof { option1: string; option2: number }]: boolean }; 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/inline_function_definitions.bd169eef.0.snapshot: -------------------------------------------------------------------------------- 1 | inline function definitions › inline function in an interface 2 | type iTest_action = (~a: string, ~b: option(float)=?, unit) => unit 3 | and iTest = { 4 | field: string, 5 | action: iTest_action, 6 | } 7 | and access = iTest_action; 8 | 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.a794e2cf.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › references parameters that are used when inlining a type 2 | type someFunction_return('C, 'B) = { 3 | b: 'B, 4 | c: 'C, 5 | } 6 | and someFunction('A, 'B, 'C) = 7 | (~a: 'A, ~b: 'B) => someFunction_return('C, 'B); 8 | 9 | -------------------------------------------------------------------------------- /esy.lock/overrides/opam__s__conf_pkg_config_opam__c__1.2_opam_override/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": [ 3 | [ 4 | "pkg-config", 5 | "--help" 6 | ] 7 | ], 8 | "dependencies": { 9 | "yarn-pkg-config": "esy-ocaml/yarn-pkg-config#db3a0b63883606dd57c54a7158d560d6cba8cd79" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/js/Re_typescript_js.re: -------------------------------------------------------------------------------- 1 | open Re_typescript_base; 2 | open Re_typescript_config; 3 | open Re_typescript_fs; 4 | open Js_of_ocaml; 5 | 6 | Pastel.setMode(HumanReadable); 7 | 8 | Example_files.register_examples(); 9 | 10 | Js.export("run", Run.run); 11 | Js.export("example_list", Example_files.examples_list); 12 | -------------------------------------------------------------------------------- /src/printer/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name re_typescript_printer) 3 | (public_name re_typescript.printer) 4 | (libraries reason ocaml-migrate-parsetree re_typescript.base 5 | re_typescript.config re_typescript.fs ppx_tools_versioned containers 6 | console.lib) 7 | (preprocess 8 | (pps ppx_tools_versioned.metaquot_406))) 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.39507417.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › maps over type parameters 2 | type keys('A) = { 3 | key_1: string, 4 | key_2: float, 5 | key_3: 'A, 6 | } 7 | and with_keys_K_t_0 = {key_4: bool} 8 | and with_keys_K = 9 | | Key_4 10 | and with_keys = {key_4: bool}; 11 | 12 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.afc63d00.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › map over a keyof instruction 2 | type keysObj = { 3 | option1: string, 4 | option2: float, 5 | } 6 | and flags_K = 7 | | Option1 8 | | Option2 9 | and flags = { 10 | option1: bool, 11 | option2: bool, 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.f3b08384.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › omit_extended_unreferenced_records - on (displays warning if necessary after all) 2 | [@warning \"-30\"]; 3 | type i_1 = {field1: string} 4 | and i_2 = { 5 | field1: string, 6 | field2: bool, 7 | } 8 | and holds_ref = i_1; 9 | 10 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.42475839.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › map over a nested type 2 | type keys = 3 | | Option1 4 | | Option2 5 | and a_flags = { 6 | option1: bool, 7 | option2: bool, 8 | } 9 | and a = { 10 | key_1: string, 11 | key_2: float, 12 | flags: a_flags, 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mixed_unions.d66ff151.0.snapshot: -------------------------------------------------------------------------------- 1 | mixed unions › generates unboxed type 2 | module X: { 3 | type t; 4 | let string: t; 5 | let _1: t; 6 | } = { 7 | [@unboxed] 8 | type t = 9 | | Any('a): t; 10 | let string = Any(\"string\"); 11 | let _1 = Any(1); 12 | }; 13 | type x = X.t; 14 | 15 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.a6981150.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › map over an inline keyof instruction 2 | type flags_K_t = { 3 | option1: string, 4 | option2: float, 5 | } 6 | and flags_K = 7 | | Option1 8 | | Option2 9 | and flags = { 10 | option1: bool, 11 | option2: bool, 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /src/js/examples/interfaces/basic_interfaces.d.ts: -------------------------------------------------------------------------------- 1 | // --- Interfaces & basic interface inheritance 2 | interface IOne { 3 | key_1: string; 4 | key_2: boolean; 5 | } 6 | interface ITwo extends IOne { 7 | key_3: number; 8 | } 9 | 10 | // --- Interfaces & obj types are generated equal as records 11 | type obj = { key: string }; 12 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.1548e0ef.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › omit_extended_unreferenced_records - on (double extension) 2 | type i_3 = { 3 | field1: string, 4 | field2: bool, 5 | field3: float, 6 | } 7 | and i_4 = { 8 | field1: string, 9 | field2: bool, 10 | field4: string, 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interface_extension.40d51db0.0.snapshot: -------------------------------------------------------------------------------- 1 | interface extension › resolves extensions completely 2 | type i_a('A, 'B) = { 3 | field_1: 'A, 4 | field_2: 'B, 5 | field_4: string, 6 | } 7 | and i_b = { 8 | field_1: string, 9 | field_2: bool, 10 | field_4: string, 11 | field_3: float, 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/number_literal_unions.7b9a9a87.0.snapshot: -------------------------------------------------------------------------------- 1 | number literal unions › generates int union from single value 2 | module Variant: { 3 | type t = pri int; 4 | [@bs.inline 32] 5 | let _32: t; 6 | } = { 7 | type t = int; 8 | [@bs.inline] 9 | let _32 = 32; 10 | }; 11 | type variant = Variant.t; 12 | 13 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.f27c896c.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › type parameters can get referenced back to the parent when being applied 2 | type iPromise('X) = {field: 'X} 3 | and resouceResult_2('T) = { 4 | promise: iPromise('T), 5 | resolved: bool, 6 | } 7 | and resouceResult('T) = ('T, resouceResult_2('T)); 8 | 9 | -------------------------------------------------------------------------------- /src_js/assets/Assets.re: -------------------------------------------------------------------------------- 1 | type img = {default: string}; 2 | [@bs.val] external img: string => img = "require"; 3 | let logo_reason = img("./../../../../src_js/assets/reasonml.png").default; 4 | let logo_ocaml = img("./../../../../src_js/assets/ocaml.png").default; 5 | let logo_re_typescript = 6 | img("./../../../../src_js/assets/re_typescript.png").default; -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.0c1534c3.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › omits parsing the mapped obj type if its args require it to be parsed on call 2 | type a = { 3 | x: string, 4 | y: float, 5 | z: bool, 6 | } 7 | and keys = 8 | | X 9 | | Y 10 | and stripped = { 11 | x: string, 12 | y: float, 13 | }; 14 | 15 | -------------------------------------------------------------------------------- /src/js/examples/unions/unions.d.ts: -------------------------------------------------------------------------------- 1 | // --- Type unions (Generates bs.unboxed by default) 2 | // (Creating a variant alongside the unboxed value is planned. Still undecided on how to build the classify structure.) 3 | type string_literal = "double" | "single"; 4 | 5 | type union_1 = string | number | undefined; 6 | type union_2 = string_literal | string; 7 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/string_literal_unions.cb48e76c.0.snapshot: -------------------------------------------------------------------------------- 1 | string literal unions › recognizes single string as union 2 | module Variant: { 3 | type t = pri string; 4 | [@bs.inline \"single\"] 5 | let single: t; 6 | } = { 7 | type t = string; 8 | [@bs.inline] 9 | let single = \"single\"; 10 | }; 11 | type variant = Variant.t; 12 | 13 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.aa98ddc4.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › can have inline records at call site 2 | type with_param_a2 = {inline: bool} 3 | and with_param('a1, 'a2) = { 4 | a1: 'a1, 5 | a2: 'a2, 6 | } 7 | and call_params_0 = {another_inline: float} 8 | and call_params = with_param(call_params_0, with_param_a2); 9 | 10 | -------------------------------------------------------------------------------- /src/base/dune: -------------------------------------------------------------------------------- 1 | (ocamllex 2 | (modules lexer)) 3 | 4 | (menhir 5 | (modules parser) 6 | (flags --unused-tokens --table)) 7 | 8 | (library 9 | (name re_typescript_base) 10 | (public_name re_typescript.base) 11 | (libraries file-context-printer.lib pastel.lib console.lib containers 12 | menhirLib re_typescript.config) 13 | (ocamlopt_flags (-linkall))) 14 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/interface_extension.3c99a251.0.snapshot: -------------------------------------------------------------------------------- 1 | interface extension › can pass a type param on through an extension 2 | type i_a('A, 'B) = { 3 | field_1: 'A, 4 | field_2: 'B, 5 | field_4: string, 6 | } 7 | and i_b('Local, 'Ext) = { 8 | field_1: string, 9 | field_2: 'Ext, 10 | field_4: string, 11 | field_3: 'Local, 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.1dd3551e.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › resolves nested type args when using mapped obj types 2 | type a('X) = { 3 | x: string, 4 | y: 'X, 5 | z: bool, 6 | } 7 | and keys = 8 | | X 9 | | Y 10 | and stripped_0_0 = {obj: float} 11 | and stripped = { 12 | x: string, 13 | y: stripped_0_0, 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/nullable_undefined_unions_are_around_types.28d1bc50.0.snapshot: -------------------------------------------------------------------------------- 1 | nullable / undefined unions are around types › nullable/undefined for single base types in arrays 2 | type opt_in_arr = array(option(string)) 3 | and null_in_arr = array(Js.Nullable.t(bool)) 4 | and arr_null = Js.Nullable.t(array(string)) 5 | and arr_opt = option(array(bool)); 6 | 7 | -------------------------------------------------------------------------------- /src/printer/ast_generator.re: -------------------------------------------------------------------------------- 1 | open Migrate_parsetree; 2 | open Ast_406; 3 | open Parsetree; 4 | 5 | module type T = { 6 | let generate: 7 | ( 8 | ~ctx: Re_typescript_config.Config.config, 9 | ( 10 | list(Tree_utils.Path.t), 11 | Hashtbl.t(Tree_utils.Path.t, Tree_types.ts_type), 12 | ) 13 | ) => 14 | structure; 15 | }; 16 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/keyof_operator.1d89cb10.0.snapshot: -------------------------------------------------------------------------------- 1 | keyof operator › works together with parameterized mapped object types 2 | type a = { 3 | x: string, 4 | y: float, 5 | z: bool, 6 | } 7 | and a_partial_P = 8 | | X 9 | | Y 10 | | Z 11 | and a_partial = { 12 | x: option(string), 13 | y: option(float), 14 | z: option(bool), 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /src/js/examples/functions/method_signatures.d.ts: -------------------------------------------------------------------------------- 1 | // --- Method signature in interfaces 2 | interface method_signature { 3 | func1: (x: number) => number; // Function type literal 4 | func2(x: number): number; // Method signature 5 | func3(x: string, y: boolean): void; // Method signature for extraction 6 | } 7 | type extracted_method_signature = method_signature["func3"]; 8 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.44ed21b7.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › maps over recursively defined interfaces 2 | type a_flags_K = 3 | | Key_1 4 | | Key_2 5 | | Flags 6 | and a_flags = { 7 | key_1: bool, 8 | key_2: bool, 9 | flags: bool, 10 | } 11 | and a = { 12 | key_1: string, 13 | key_2: float, 14 | flags: a_flags, 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.e3b7b446.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › maps optional types 2 | type keys = { 3 | key_1: string, 4 | key_2: float, 5 | } 6 | and with_keys_K = 7 | | Key_1 8 | | Key_2 9 | and with_keys_t = 10 | | A 11 | | B 12 | and with_keys = { 13 | key_1: option(with_keys_t), 14 | key_2: option(with_keys_t), 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /ts_inspiration/discriminated_union_by_enum.d.ts: -------------------------------------------------------------------------------- 1 | export enum ShapeKind { 2 | Circle = "circle", 3 | Square = "square", 4 | } 5 | 6 | interface Circle { 7 | kind: ShapeKind.Circle; 8 | radius: number; 9 | } 10 | 11 | interface Square { 12 | kind: ShapeKind.Square; 13 | sideLength: number; 14 | } 15 | 16 | declare namespace buh { 17 | let c: Circle; 18 | } 19 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.d1db6328.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › can be used inline, for example in an intersection 2 | type keys = { 3 | key_1: string, 4 | key_2: float, 5 | } 6 | and with_keys_1_K = 7 | | Key_1 8 | | Key_2 9 | and with_keys_1 = { 10 | key_1: bool, 11 | key_2: bool, 12 | } 13 | and with_keys = (with_keys_1, keys); 14 | 15 | -------------------------------------------------------------------------------- /types.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | atdg=`esy which atdgen` 3 | rm src_js/types/*.ml* 4 | rm src_js/types/*.atd 5 | cp src/config/*.atd src_js/types 6 | $atdg src_js/types/config.atd -t 7 | $atdg src_js/types/config.atd -bs 8 | $atdg src_js/types/bridge.atd -t 9 | $atdg src_js/types/bridge.atd -bs 10 | $atdg src_js/types/parse_info.atd -t 11 | $atdg src_js/types/parse_info.atd -bs 12 | yarn bs:build -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions.a5f0b423.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions › can use recursion in unions 2 | module Rec_x: { 3 | type t; 4 | let rec_x: t => t; 5 | let str: t; 6 | let _3: t; 7 | } = { 8 | [@unboxed] 9 | type t = 10 | | Any('a): t; 11 | let rec_x = (v: t) => Any(v); 12 | let str = Any(\"str\"); 13 | let _3 = Any(3); 14 | }; 15 | type rec_x = Rec_x.t; 16 | 17 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.fa2566ce.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › maps over extended interfaces 2 | type keysExt = {key_3: bool} 3 | and keys = { 4 | key_3: bool, 5 | key_1: string, 6 | key_2: float, 7 | } 8 | and with_keys_K = 9 | | Key_3 10 | | Key_1 11 | | Key_2 12 | and with_keys = { 13 | key_3: bool, 14 | key_1: bool, 15 | key_2: bool, 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions.c34a9bc8.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions › can use recursion in nested union types 2 | module Rec_x: { 3 | type t; 4 | let rec_x: t => t; 5 | let arr_rec_x: array(t) => t; 6 | } = { 7 | [@unboxed] 8 | type t = 9 | | Any('a): t; 10 | let rec_x = (v: t) => Any(v); 11 | let arr_rec_x = (v: array(t)) => Any(v); 12 | }; 13 | type rec_x = Rec_x.t; 14 | 15 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 1.11) 2 | 3 | (name "re_typescript") 4 | (version 0.0.1) 5 | 6 | (maintainers "Jonathan Siebern") 7 | (authors "Jonathan Siebern") 8 | (source (github jsiebern/re-typescript)) 9 | (homepage https://jsiebern.github.io/re-typescript/) 10 | (documentation https://github.com/jsiebern/re-typescript) 11 | (generate_opam_files true) 12 | 13 | (using fmt 1.2) 14 | (using menhir 2.0) 15 | -------------------------------------------------------------------------------- /src/js/examples/mapped_object_types/map_inline.d.ts: -------------------------------------------------------------------------------- 1 | // --- Resolve an inline mapped type 2 | type Keys = "option1" | "option2"; 3 | interface A { 4 | key_1: string; 5 | key_2: number; 6 | flags: { [K in Keys]: boolean }; 7 | } 8 | 9 | // --- Resolve a recursive inline mapped type 10 | interface B { 11 | key_1: string; 12 | key_2: number; 13 | flags: { [K in keyof B]: boolean }; 14 | } 15 | -------------------------------------------------------------------------------- /src/fs/file_path.re: -------------------------------------------------------------------------------- 1 | include Fp; 2 | 3 | // let append_extension = (path: Fp.t('kind), ext) => switch (path |> Fp.firstClass) { 4 | // | Relative(path) => (Fp.toDebugString(path) ++ ext) |> Fp.relativeExn 5 | // | Absolute(path) => (Fp.toString(path) ++ ext) |> Fp.absoluteExn 6 | // } 7 | 8 | let append_extension = (path: Fp.t(Fp.absolute), ext) => 9 | Fp.toString(path) ++ ext |> Fp.absoluteExn; 10 | -------------------------------------------------------------------------------- /src/js/examples/mapped_object_types/map_optional.d.ts: -------------------------------------------------------------------------------- 1 | type AsRequired = { 2 | [P in keyof T]-?: T[P]; 3 | }; 4 | type AsPartial = { 5 | [P in keyof T]?: T[P]; 6 | }; 7 | type AsNothing = { 8 | [P in keyof T]: T[P]; 9 | }; 10 | interface A { 11 | x: string; 12 | y?: number; 13 | z: boolean; 14 | } 15 | type same = AsNothing; 16 | type req = AsRequired; 17 | type part = AsPartial; 18 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/inline_function_definitions.1b59f527.0.snapshot: -------------------------------------------------------------------------------- 1 | inline function definitions › method signature in an interface 2 | type method_signature_func3 = (~x: string, ~y: bool) => unit 3 | and method_signature = { 4 | func1: (~x: float) => float, 5 | func2: (~x: float) => float, 6 | func3: method_signature_func3, 7 | } 8 | and extracted_method_signature = method_signature_func3; 9 | 10 | -------------------------------------------------------------------------------- /src/js/examples/mapped_object_types/map_literals.d.ts: -------------------------------------------------------------------------------- 1 | // --- Map over an existing string literal type as keys 2 | type Keys = "option1" | "option2"; 3 | type Flags_1 = { [K in Keys]: boolean }; 4 | 5 | // --- Map through a reference 6 | type KeysRef = Keys; 7 | type Flags_2 = { [K in KeysRef]: boolean }; 8 | 9 | // --- Map over an inline string literal 10 | type Flags_3 = { [K in "option1" | "option2"]: boolean }; 11 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions.2bf5db07.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions › can use recursion in unions in combination with type params 2 | module X: { 3 | type t('B); 4 | let string: string => t('B); 5 | let b: 'B => t('B); 6 | } = { 7 | [@unboxed] 8 | type t('B) = 9 | | Any('a): t('B); 10 | let string = (v: string) => Any(v); 11 | let b = (v: 'B) => Any(v); 12 | }; 13 | type x('B) = X.t('B); 14 | 15 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mixed_unions.239fb0b7.0.snapshot: -------------------------------------------------------------------------------- 1 | mixed unions › works with all primitives 2 | module X: { 3 | type t; 4 | let string: t; 5 | let _1: t; 6 | let _3: t; 7 | let false_: t; 8 | } = { 9 | [@unboxed] 10 | type t = 11 | | Any('a): t; 12 | let string = Any(\"string\"); 13 | let _1 = Any(1); 14 | let _3 = Any(3); 15 | let false_ = Any(false); 16 | }; 17 | type x = X.t; 18 | 19 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameters_generation_grammar.84e9a21a.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameters generation & grammar › accepts ts grammar for type parameters 2 | type with_param('a1, 'a2) = { 3 | a1: 'a1, 4 | a2: 'a2, 5 | } 6 | and with_param_2('a1, 'a2, 'a3) = { 7 | a1: 'a1, 8 | a2: 'a2, 9 | a3: 'a3, 10 | } 11 | and with_param_3('a1, 'a2, 'a3) = { 12 | a1: 'a1, 13 | a2: 'a2, 14 | a3: 'a3, 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.5b9c9a93.0.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › omit_extended_unreferenced_records - on (double extension, + ref) 2 | type i_2 = { 3 | field1: string, 4 | field2: bool, 5 | } 6 | and i_3 = { 7 | field1: string, 8 | field2: bool, 9 | field3: float, 10 | } 11 | and i_4 = { 12 | field1: string, 13 | field2: bool, 14 | field4: string, 15 | } 16 | and holds_ref = i_2; 17 | 18 | -------------------------------------------------------------------------------- /src/fs/re_typescript_fs.re: -------------------------------------------------------------------------------- 1 | module Resolver = Resolver; 2 | module Loader = Loader; 3 | module Loader_virtual = Loader_virtual; 4 | 5 | let default_loader: module Loader.T = 6 | (module 7 | Loader_virtual.Make({ 8 | let tbl = Hashtbl.create(0); 9 | })); 10 | let default_resolver: module Resolver.T = 11 | (module 12 | Resolver.Make({ 13 | let config = {Resolver.loader: default_loader, tsconfig: None}; 14 | })); 15 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.7a88a1da.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › can use mapper ident type parameters 2 | type proxy('T) = { 3 | get: unit => 'T, 4 | set: (~value: 'T) => unit, 5 | } 6 | and a = { 7 | x: string, 8 | y: float, 9 | z: bool, 10 | } 11 | and proxied_P = 12 | | X 13 | | Y 14 | | Z 15 | and proxied = { 16 | x: proxy(string), 17 | y: proxy(float), 18 | z: proxy(bool), 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/string_literal_unions.cc34917c.0.snapshot: -------------------------------------------------------------------------------- 1 | string literal unions › can be generated inside optional 2 | module Variant: { 3 | type t = pri string; 4 | [@bs.inline \"blue\"] 5 | let blue: t; 6 | [@bs.inline \"red\"] 7 | let red: t; 8 | } = { 9 | type t = string; 10 | [@bs.inline] 11 | let blue = \"blue\"; 12 | [@bs.inline] 13 | let red = \"red\"; 14 | }; 15 | type variant = option(Variant.t); 16 | 17 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_extractions.73402d87.0.snapshot: -------------------------------------------------------------------------------- 1 | type extractions › can access a string literal of fields 2 | type c = { 3 | a: string, 4 | b: float, 5 | }; 6 | module D: { 7 | type t; 8 | let string: string => t; 9 | let number: float => t; 10 | } = { 11 | [@unboxed] 12 | type t = 13 | | Any('a): t; 14 | let string = (v: string) => Any(v); 15 | let number = (v: float) => Any(v); 16 | }; 17 | type d = D.t; 18 | 19 | -------------------------------------------------------------------------------- /ts_inspiration/intersection_mixins.d.ts: -------------------------------------------------------------------------------- 1 | declare class Person { 2 | constructor(name: string); 3 | } 4 | 5 | interface Loggable { 6 | log(name: string): void; 7 | } 8 | 9 | declare class ConsoleLogger implements Loggable { 10 | log(name: string): void; 11 | } 12 | 13 | // Takes two objects and merges them together 14 | declare function extend( 15 | first: First, 16 | second: Second 17 | ): First & Second; 18 | -------------------------------------------------------------------------------- /tests/native/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name re_typescript_test_lib) 3 | (public_name re_typescript.test_lib) 4 | (ocamlopt_flags -linkall -g) 5 | (libraries reason rely.lib re_typescript.base re_typescript.printer 6 | console.lib containers) 7 | (modules 8 | (:standard \ RunTests))) 9 | 10 | (executable 11 | (package re_typescript) 12 | (name RunTests) 13 | (public_name RunTests.exe) 14 | (libraries re_typescript.test_lib) 15 | (modules RunTests)) 16 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mixed_unions.372967e0.0.snapshot: -------------------------------------------------------------------------------- 1 | mixed unions › can be made optional no matter the position of the undefined 2 | module X: { 3 | type t; 4 | let string: t; 5 | let _3: t; 6 | let _1: t; 7 | let false_: t; 8 | } = { 9 | [@unboxed] 10 | type t = 11 | | Any('a): t; 12 | let string = Any(\"string\"); 13 | let _3 = Any(3); 14 | let _1 = Any(1); 15 | let false_ = Any(false); 16 | }; 17 | type x = option(X.t); 18 | 19 | -------------------------------------------------------------------------------- /.github/workflows/print_esy_cache.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const os = require("os"); 3 | const path = require("path"); 4 | 5 | const ESY_FOLDER = process.env.ESY__PREFIX 6 | ? process.env.ESY__PREFIX 7 | : path.join(os.homedir(), ".esy"); 8 | const esy3 = fs 9 | .readdirSync(ESY_FOLDER) 10 | .filter((name) => name.length > 0 && name[0] === "3") 11 | .sort() 12 | .pop(); 13 | console.log(`::set-output name=esy_cache::${path.join(ESY_FOLDER, esy3, "i")}`); 14 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions.a590181a.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions › can use recursion in nested union types 2 2 | module Rec_y: { 3 | type t 4 | and rec_y_1 = {inline_obj: t}; 5 | let string: string => t; 6 | let rec_y_1: rec_y_1 => t; 7 | } = { 8 | [@unboxed] 9 | type t = 10 | | Any('a): t 11 | and rec_y_1 = {inline_obj: t}; 12 | let string = (v: string) => Any(v); 13 | let rec_y_1 = (v: rec_y_1) => Any(v); 14 | }; 15 | type rec_y = Rec_y.t; 16 | 17 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/number_literal_unions.7dc1e4bb.0.snapshot: -------------------------------------------------------------------------------- 1 | number literal unions › converts floats into ints for now 2 | module Variant: { 3 | type t = pri int; 4 | [@bs.inline 2] 5 | let _2: t; 6 | [@bs.inline 3] 7 | let _3: t; 8 | [@bs.inline 4] 9 | let _4: t; 10 | } = { 11 | type t = int; 12 | [@bs.inline] 13 | let _2 = 2; 14 | [@bs.inline] 15 | let _3 = 3; 16 | [@bs.inline] 17 | let _4 = 4; 18 | }; 19 | type variant = Variant.t; 20 | 21 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions.0fd3a362.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions › can use recursion in nested union types when using type params 2 | module ValueOrArray: { 3 | type t('T); 4 | let t: 'T => t('T); 5 | let arr_valueOrArray: array(t('T)) => t('T); 6 | } = { 7 | [@unboxed] 8 | type t('T) = 9 | | Any('a): t('T); 10 | let t = (v: 'T) => Any(v); 11 | let arr_valueOrArray = (v: array(t('T))) => Any(v); 12 | }; 13 | type valueOrArray('T) = ValueOrArray.t('T); 14 | 15 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.1dc99791.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › can use mapper ident in inlined types 2 | type person = { 3 | name: string, 4 | age: float, 5 | } 6 | and nullablePerson_P = 7 | | Name 8 | | Age 9 | and nullablePerson = { 10 | name: Js.Nullable.t(string), 11 | age: Js.Nullable.t(float), 12 | } 13 | and partialPerson_P = 14 | | Name 15 | | Age 16 | and partialPerson = { 17 | name: option(string), 18 | age: option(float), 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /src/fs/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name re_typescript_fs) 3 | (public_name re_typescript.fs) 4 | (libraries containers console.lib fp biniou atdgen) 5 | (preprocess 6 | (pps ppx_tools_versioned.metaquot_406))) 7 | 8 | (rule 9 | (targets package_json_t.ml package_json_t.mli) 10 | (deps package_json.atd) 11 | (action 12 | (run atdgen -t %{deps}))) 13 | 14 | (rule 15 | (targets package_json_j.ml package_json_j.mli) 16 | (deps package_json.atd) 17 | (action 18 | (run atdgen -j -j-std %{deps}))) 19 | -------------------------------------------------------------------------------- /src/js/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name re_typescript_js) 3 | (libraries re_typescript.base re_typescript.printer re_typescript.fs 4 | file-context-printer.lib console.lib pastel.lib js_of_ocaml containers 5 | re_typescript.config fp) 6 | (preprocess 7 | (pps js_of_ocaml-ppx)) 8 | (modes js)) 9 | 10 | (rule 11 | (target examples.re) 12 | (deps 13 | (:folder 14 | (source_tree examples)) 15 | (:script 16 | (file generate_examples.js))) 17 | (action 18 | (run node %{script}))) 19 | -------------------------------------------------------------------------------- /tests/native/Arrays.re: -------------------------------------------------------------------------------- 1 | open TestFramework; 2 | 3 | describe("arrays", ({test, _}) => { 4 | test("arrays in record field defs", ({expect, _}) => { 5 | expect.string(print({|type obj = { field: string[] }|})).toMatchSnapshot(); 6 | expect.string(print({|type obj = { field: Array, }|})). 7 | toMatchSnapshot(); 8 | }); 9 | 10 | test("arrays of inline records", ({expect, _}) => { 11 | expect.string(print({|type x = {field: string}[];|})).toMatchSnapshot() 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/string_literal_unions.c31cc892.0.snapshot: -------------------------------------------------------------------------------- 1 | string literal unions › can be generated inline 2 | module Obj_field: { 3 | type t = pri string; 4 | [@bs.inline \"red\"] 5 | let red: t; 6 | [@bs.inline \"blue\"] 7 | let blue: t; 8 | } = { 9 | type t = string; 10 | [@bs.inline] 11 | let red = \"red\"; 12 | [@bs.inline] 13 | let blue = \"blue\"; 14 | }; 15 | type obj_field = Obj_field.t; 16 | type obj = {field: obj_field} 17 | and in_arr = array(obj_field); 18 | 19 | -------------------------------------------------------------------------------- /esy.lock/opam/seq.base/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: " " 3 | authors: " " 4 | homepage: " " 5 | depends: [ 6 | "ocaml" {>= "4.07.0"} 7 | ] 8 | dev-repo: "git+https://github.com/ocaml/ocaml.git" 9 | bug-reports: "https://caml.inria.fr/mantis/main_page.php" 10 | synopsis: 11 | "Compatibility package for OCaml's standard iterator type starting from 4.07." 12 | extra-files: [ 13 | ["seq.install" "md5=026b31e1df290373198373d5aaa26e42"] 14 | ["META.seq" "md5=b33c8a1a6c7ed797816ce27df4855107"] 15 | ] 16 | -------------------------------------------------------------------------------- /src/js/examples/intersections/intersections.d.ts: -------------------------------------------------------------------------------- 1 | // --- Simple intersection (default output mode for intersections is a tuple) 2 | type inters_as_tpl = string & number; 3 | interface ErrorHandling { 4 | success: boolean; 5 | error?: { message: string }; 6 | } 7 | interface ArtworksData { 8 | artworks: { title: string }[]; 9 | } 10 | interface ArtistsData { 11 | artists: { name: string }[]; 12 | } 13 | type ArtworksResponse = ArtworksData & ErrorHandling; 14 | type ArtistsResponse = ArtistsData & ErrorHandling; 15 | -------------------------------------------------------------------------------- /src/js/examples/literals/string_literals.d.ts: -------------------------------------------------------------------------------- 1 | // --- String literals 2 | // (String literals have 3 config types: Variant, PolyVariant, BsInline. These will be handled differently for generating the encoder / decoder functions.) 3 | type string_literal = "double" | "single" | "$_bad_string"; 4 | type string_literal_opt = "one" | "two" | undefined; 5 | 6 | // --- Automatic Extension of union literals (keeps around the original) 7 | type string_literal_ext = "x" | "y"; 8 | type string_literal_ext_base = "z" | string_literal_ext; 9 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.d41c860a.1.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › default parameter can be a union of any kind 2 | module With_param2_a: { 3 | type t; 4 | let string: string => t; 5 | let number: float => t; 6 | } = { 7 | [@unboxed] 8 | type t = 9 | | Any('a): t; 10 | let string = (v: string) => Any(v); 11 | let number = (v: float) => Any(v); 12 | }; 13 | type with_param2_a = With_param2_a.t; 14 | type with_param2('a) = 'a 15 | and call_params2 = with_param2(with_param2_a); 16 | 17 | -------------------------------------------------------------------------------- /src/js/examples/interfaces/interface_extension.d.ts: -------------------------------------------------------------------------------- 1 | // --- Interface extensions are resolved properly 2 | // --- Created a configurable warning suppression ([@warning "-30"]) for overlapping fields in extensions 3 | interface Extend_me { 4 | field_1: Fill; 5 | field_2: Default; 6 | field_4: string; 7 | } 8 | interface Extends_one extends Extend_me { 9 | field_3: number; 10 | } 11 | interface Extends_another extends Extend_me { 12 | field_3: PassThrough; 13 | } 14 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/function_definitions.c95264d7.0.snapshot: -------------------------------------------------------------------------------- 1 | function definitions › function with inline arguments 2 | type someFunction_b = {inline: float}; 3 | module SomeFunction_a: { 4 | type t; 5 | let string: string => t; 6 | let number: float => t; 7 | } = { 8 | [@unboxed] 9 | type t = 10 | | Any('a): t; 11 | let string = (v: string) => Any(v); 12 | let number = (v: float) => Any(v); 13 | }; 14 | type someFunction = 15 | (~a: SomeFunction_a.t, ~b: option(someFunction_b)=?, unit) => string; 16 | 17 | -------------------------------------------------------------------------------- /src/fs/loader_virtual.re: -------------------------------------------------------------------------------- 1 | module type Config = {let tbl: Hashtbl.t(Fp.t(Fp.absolute), string);}; 2 | module Make = (C: Config) : Loader.T => { 3 | let fs_name = "Virtual File System"; 4 | 5 | let keys = CCHashtbl.keys_list(C.tbl); 6 | let file_read = (path: Fp.t(Fp.absolute)) => 7 | switch (Hashtbl.find_opt(C.tbl, path)) { 8 | | Some(f) => Ok(f) 9 | | None => 10 | Error(Printf.sprintf("File does not exist: %s", path |> Fp.toString)) 11 | }; 12 | let file_exists = path => keys |> CCList.exists(Fp.eq(path)); 13 | }; 14 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/string_literal_unions.4e633e40.0.snapshot: -------------------------------------------------------------------------------- 1 | string literal unions › can generate simple string unions 2 | module Variant: { 3 | type t = pri string; 4 | [@bs.inline \"str1\"] 5 | let str1: t; 6 | [@bs.inline \"Str1\"] 7 | let str1: t; 8 | [@bs.inline \"X_$STR\"] 9 | let x__STR: t; 10 | } = { 11 | type t = string; 12 | [@bs.inline] 13 | let str1 = \"str1\"; 14 | [@bs.inline] 15 | let str1 = \"Str1\"; 16 | [@bs.inline] 17 | let x__STR = \"X_$STR\"; 18 | }; 19 | type variant = Variant.t; 20 | 21 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.d41c860a.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › default parameter can be a union of any kind 2 | module With_param2_a: { 3 | type t = pri string; 4 | [@bs.inline \"one\"] 5 | let one: t; 6 | [@bs.inline \"two\"] 7 | let two: t; 8 | } = { 9 | type t = string; 10 | [@bs.inline] 11 | let one = \"one\"; 12 | [@bs.inline] 13 | let two = \"two\"; 14 | }; 15 | type with_param2_a = With_param2_a.t; 16 | type with_param2('a) = 'a 17 | and call_params2 = with_param2(with_param2_a); 18 | 19 | -------------------------------------------------------------------------------- /src/js/examples/functions/functions.d.ts: -------------------------------------------------------------------------------- 1 | // --- Function definitions 2 | declare function some_function(): void; 3 | declare function some_other_function(): { inline: string }; 4 | declare function some_function_args(a: string, b: number): string; 5 | declare function some_function_opt_args(a: string, b?: number): string; 6 | declare function some_function_inline_args( 7 | a: string | number, 8 | b?: { inline: number } 9 | ): string; 10 | declare function some_function_as_any(); 11 | declare function some_function_params(a: A, b: B): C; 12 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/number_literal_unions.0ede5e77.0.snapshot: -------------------------------------------------------------------------------- 1 | number literal unions › generates simple int union 2 | module Variant: { 3 | type t = pri int; 4 | [@bs.inline 2] 5 | let _2: t; 6 | [@bs.inline 4] 7 | let _4: t; 8 | [@bs.inline 8] 9 | let _8: t; 10 | [@bs.inline 16] 11 | let _16: t; 12 | } = { 13 | type t = int; 14 | [@bs.inline] 15 | let _2 = 2; 16 | [@bs.inline] 17 | let _4 = 4; 18 | [@bs.inline] 19 | let _8 = 8; 20 | [@bs.inline] 21 | let _16 = 16; 22 | }; 23 | type variant = Variant.t; 24 | 25 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions.42604fa6.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions › can use recursion in nested union types when using type params 2 2 | module ValueOrObj: { 3 | type t('T) 4 | and valueOrObj_1('T) = {obj_value: 'T}; 5 | let t: 'T => t('T); 6 | let valueOrObj_1: valueOrObj_1('T) => t('T); 7 | } = { 8 | [@unboxed] 9 | type t('T) = 10 | | Any('a): t('T) 11 | and valueOrObj_1('T) = {obj_value: 'T}; 12 | let t = (v: 'T) => Any(v); 13 | let valueOrObj_1 = (v: valueOrObj_1('T)) => Any(v); 14 | }; 15 | type valueOrObj('T) = ValueOrObj.t('T); 16 | 17 | -------------------------------------------------------------------------------- /ts_inspiration/discriminating_unions.d.ts: -------------------------------------------------------------------------------- 1 | type NetworkLoadingState = { 2 | state: "loading"; 3 | }; 4 | 5 | type NetworkFailedState = { 6 | state: "failed"; 7 | code: number; 8 | }; 9 | 10 | type NetworkSuccessState = { 11 | state: "success"; 12 | response: { 13 | title: string; 14 | duration: number; 15 | summary: string; 16 | }; 17 | }; 18 | 19 | // Create a type which represents only one of the above types 20 | // but you aren't sure which it is yet. 21 | type NetworkState = 22 | | NetworkLoadingState 23 | | NetworkFailedState 24 | | NetworkSuccessState; 25 | -------------------------------------------------------------------------------- /ts_inspiration/declare_ namespace.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace MyFunction { 2 | export interface LengthReturnType { 3 | width: number; 4 | height: number; 5 | } 6 | export interface NamedReturnType { 7 | firstName: string; 8 | lastName: string; 9 | } 10 | 11 | /*~ If the module also has properties, declare them here. For example, 12 | *~ this declaration says that this code is legal: 13 | *~ import f = require('myFuncLibrary'); 14 | *~ console.log(f.defaultName); 15 | */ 16 | export const defaultName: string; 17 | export let defaultLength: number; 18 | } 19 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/mapped_object_types.06a30695.0.snapshot: -------------------------------------------------------------------------------- 1 | mapped object types › treats the optional status correctly 2 | type a = { 3 | x: string, 4 | y: option(float), 5 | z: bool, 6 | } 7 | and same_P = 8 | | X 9 | | Y 10 | | Z 11 | and same = { 12 | x: string, 13 | y: option(float), 14 | z: bool, 15 | } 16 | and req_P = 17 | | X 18 | | Y 19 | | Z 20 | and req = { 21 | x: string, 22 | y: float, 23 | z: bool, 24 | } 25 | and part_P = 26 | | X 27 | | Y 28 | | Z 29 | and part = { 30 | x: option(string), 31 | y: option(float), 32 | z: option(bool), 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/intersection_types.56082cfd.0.snapshot: -------------------------------------------------------------------------------- 1 | intersection types › can create more complex intersection tuple 2 | type errorHandling_error = {message: string} 3 | and errorHandling = { 4 | success: bool, 5 | error: option(errorHandling_error), 6 | } 7 | and artworksData_artworks_t = {title: string} 8 | and artworksData = {artworks: array(artworksData_artworks_t)} 9 | and artistsData_artists_t = {name: string} 10 | and artistsData = {artists: array(artistsData_artists_t)} 11 | and artworksResponse = (artworksData, errorHandling) 12 | and artistsResponse = (artistsData, errorHandling); 13 | 14 | -------------------------------------------------------------------------------- /tests/native/Enums.re: -------------------------------------------------------------------------------- 1 | open TestFramework; 2 | 3 | describe("clean enums", ({test, _}) => { 4 | test("throws for non declared / exported enum", ({expect, _}) => { 5 | expect.fn(() => print({|enum Enum { Red, Green, Blue }|})).toThrow() 6 | }); 7 | 8 | test("generates variants from clean enums", ({expect, _}) => { 9 | expect.string(print({|export enum Enum { Red, Green, Blue }|})). 10 | toMatchSnapshot() 11 | }); 12 | 13 | test("generates uppercase keys", ({expect, _}) => { 14 | expect.string(print({|declare enum Enum { red, Green, blue }|})). 15 | toMatchSnapshot() 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/js/examples/mapped_object_types/map_type_parameters.d.ts: -------------------------------------------------------------------------------- 1 | interface Keys { 2 | key_1: string; 3 | key_2: number; 4 | key_3: A; 5 | } 6 | type with_keys = { [K in keyof Keys<{ key_4: boolean }>["key_3"]]: boolean }; 7 | 8 | // --- 9 | 10 | type IPick = { 11 | [P in K]: T[P]; 12 | }; 13 | interface A { 14 | x: string; 15 | y: number; 16 | z: boolean; 17 | } 18 | 19 | type keys = "x" | "y"; 20 | type stripped = IPick; 21 | 22 | // --- 23 | 24 | type IRecord = { 25 | [P in K]: T; 26 | }; 27 | 28 | type record = IRecord<"a" | "b", { field: boolean }>; 29 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.90f51b5b.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › bubbling type parameters can be combined with regular ones 2 | type map('A, 'B) = { 3 | a: 'A, 4 | b: 'B, 5 | } 6 | and recoilRootProps_initializeState_options('T, 'C) = { 7 | set: (~recoilVal: 'T, ~newVal: 'T) => unit, 8 | setUnvalidatedAtomValues: (~atomMap: map(string, 'C)) => unit, 9 | } 10 | and recoilRootProps_initializeState('T, 'C) = 11 | (~options: recoilRootProps_initializeState_options('T, 'C)) => unit 12 | and recoilRootProps('C, 'T) = { 13 | initializeState: option(recoilRootProps_initializeState('T, 'C)), 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions_should_get_optimized_into_literals_if__.67553d96.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions should get optimized into literals if possible › string / numeric into mixed literals 2 | module X: { 3 | type t; 4 | let y: t; 5 | let _3: t; 6 | } = { 7 | [@unboxed] 8 | type t = 9 | | Any('a): t; 10 | let y = Any(\"y\"); 11 | let _3 = Any(3); 12 | }; 13 | type x = X.t; 14 | module Y: { 15 | type t; 16 | let z: t; 17 | let y: t; 18 | let _3: t; 19 | } = { 20 | [@unboxed] 21 | type t = 22 | | Any('a): t; 23 | let z = Any(\"z\"); 24 | let y = Any(\"y\"); 25 | let _3 = Any(3); 26 | }; 27 | type y = Y.t; 28 | 29 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.d8a3eeba.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › type parameters that are defined inline will be bubbled up the tree 2 | [@unboxed] 3 | type any = 4 | | Any('a): any; 5 | type map('A, 'B) = { 6 | a: 'A, 7 | b: 'B, 8 | } 9 | and recoilRootProps_initializeState_options('T) = { 10 | set: (~recoilVal: 'T, ~newVal: 'T) => unit, 11 | setUnvalidatedAtomValues: (~atomMap: map(string, any)) => unit, 12 | } 13 | and recoilRootProps_initializeState('T) = 14 | (~options: recoilRootProps_initializeState_options('T)) => unit 15 | and recoilRootProps('T) = { 16 | initializeState: option(recoilRootProps_initializeState('T)), 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_parameter_logic.41671ba1.0.snapshot: -------------------------------------------------------------------------------- 1 | type parameter logic › unresolvable type params get passed on as far down as possible 2 | type map('A, 'B) = { 3 | a: 'A, 4 | b: 'B, 5 | } 6 | and recoilRootProps_initializeState_options('T, 'C) = { 7 | set: (~recoilVal: 'T, ~newVal: 'T) => unit, 8 | setUnvalidatedAtomValues: (~atomMap: map(string, 'C)) => unit, 9 | } 10 | and recoilRootProps_initializeState('T, 'C) = 11 | (~options: recoilRootProps_initializeState_options('T, 'C)) => unit 12 | and recoilRootProps('C, 'T) = { 13 | initializeState: option(recoilRootProps_initializeState('T, 'C)), 14 | } 15 | and use_it('T) = recoilRootProps(string, 'T); 16 | 17 | -------------------------------------------------------------------------------- /bsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "re_typescript", 3 | "namespace": true, 4 | "sources": [ 5 | { 6 | "dir": "src_js", 7 | "subdirs": true 8 | } 9 | ], 10 | "reason": { "react-jsx": 3 }, 11 | "package-specs": { 12 | "module": "commonjs", 13 | "in-source": false 14 | }, 15 | "ppx-flags": ["@davesnx/styled-ppx/styled-ppx"], 16 | "bsc-flags": ["-bs-super-errors"], 17 | "bs-dependencies": [ 18 | "reason-react", 19 | "bs-webworkers", 20 | "@ahrefs/bs-atdgen-codec-runtime", 21 | "@ahrefs/bs-emotion", 22 | "reason-recoil" 23 | ], 24 | "refmt": 3, 25 | "suffix": ".bs.js", 26 | "generate-merlin": true, 27 | "warnings": { 28 | "number": "" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /re_typescript.opam: -------------------------------------------------------------------------------- 1 | # This file is generated by dune, edit dune-project instead 2 | opam-version: "2.0" 3 | version: "0.0.1" 4 | maintainer: ["Jonathan Siebern"] 5 | authors: ["Jonathan Siebern"] 6 | homepage: "https://jsiebern.github.io/re-typescript/" 7 | doc: "https://github.com/jsiebern/re-typescript" 8 | bug-reports: "https://github.com/jsiebern/re-typescript/issues" 9 | depends: [ 10 | "dune" {>= "1.11"} 11 | ] 12 | build: [ 13 | ["dune" "subst"] {pinned} 14 | [ 15 | "dune" 16 | "build" 17 | "-p" 18 | name 19 | "-j" 20 | jobs 21 | "@install" 22 | "@runtest" {with-test} 23 | "@doc" {with-doc} 24 | ] 25 | ] 26 | dev-repo: "git+https://github.com/jsiebern/re-typescript.git" 27 | -------------------------------------------------------------------------------- /esy.lock/overrides/opam__s__ocamlbuild_opam__c__0.14.0_opam_override/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": [ 3 | [ 4 | "bash", 5 | "-c", 6 | "#{os == 'windows' ? 'patch -p1 < ocamlbuild-0.14.0.patch' : 'true'}" 7 | ], 8 | [ 9 | "make", 10 | "-f", 11 | "configure.make", 12 | "all", 13 | "OCAMLBUILD_PREFIX=#{self.install}", 14 | "OCAMLBUILD_BINDIR=#{self.bin}", 15 | "OCAMLBUILD_LIBDIR=#{self.lib}", 16 | "OCAMLBUILD_MANDIR=#{self.man}", 17 | "OCAMLBUILD_NATIVE=true", 18 | "OCAMLBUILD_NATIVE_TOOLS=true" 19 | ], 20 | [ 21 | "make", 22 | "check-if-preinstalled", 23 | "all", 24 | "#{os == 'windows' ? 'install' : 'opam-install'}" 25 | ] 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /src/js/examples/type_params/type_params.d.ts: -------------------------------------------------------------------------------- 1 | type with_param = A; 2 | type use_param = with_param; 3 | 4 | interface IParam { 5 | a: A; 6 | b: B; 7 | c: C; 8 | } 9 | interface IParamExt extends IParam {} 10 | 11 | type use_interface_param = IParamExt; // Default params are lazy, they will be applied at the call site of the parameterized type 12 | 13 | interface IParamDefaultInline

{ 14 | key: string; 15 | p: P; 16 | } 17 | type use_default_inline = IParamDefaultInline; 18 | 19 | // --- Type parameters are tracked across generated inlined types 20 | interface IParamNested { 21 | field1: A; 22 | field2: { 23 | field3: B; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /ts_inspiration/exported_types_as_global.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace React { 2 | export type ReactType = TProps; 3 | export type ReactNode = string; 4 | export type ReactNodeArray = string[]; 5 | export type ReactElement = number; 6 | } 7 | 8 | export type SemanticShorthandItemFunc = ( 9 | component: React.ReactType, 10 | props: TProps, 11 | children?: React.ReactNode | React.ReactNodeArray 12 | ) => React.ReactElement | null; 13 | 14 | export type SemanticShorthandCollection = SemanticShorthandItem< 15 | TProps 16 | >[]; 17 | export type SemanticShorthandContent = React.ReactNode; 18 | export type SemanticShorthandItem = 19 | | React.ReactNode 20 | | TProps 21 | | SemanticShorthandItemFunc; 22 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions_should_get_optimized_into_literals_if__.173aa723.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions should get optimized into literals if possible › string / numeric / bool into mixed literals 2 | module X: { 3 | type t; 4 | let y: t; 5 | let _3: t; 6 | } = { 7 | [@unboxed] 8 | type t = 9 | | Any('a): t; 10 | let y = Any(\"y\"); 11 | let _3 = Any(3); 12 | }; 13 | type x = X.t; 14 | module Y: { 15 | type t; 16 | let z: t; 17 | let y: t; 18 | let _3: t; 19 | let true_: t; 20 | let false_: t; 21 | } = { 22 | [@unboxed] 23 | type t = 24 | | Any('a): t; 25 | let z = Any(\"z\"); 26 | let y = Any(\"y\"); 27 | let _3 = Any(3); 28 | let true_ = Any(true); 29 | let false_ = Any(false); 30 | }; 31 | type y = Y.t; 32 | 33 | -------------------------------------------------------------------------------- /src/base/re_typescript_base.re: -------------------------------------------------------------------------------- 1 | module Ts = Ts; 2 | module Parser = Parser; 3 | module Parser_incr = Parser_incr; 4 | module Lexer = Lexer; 5 | module Error = Error; 6 | module Parse_info = Parse_info; 7 | 8 | let default_parser = content => { 9 | let lexbuf = Lexing.from_string(content |> CCString.trim); 10 | 11 | try(Ok(Parser_incr.parse(lexbuf))) { 12 | | Lexer.SyntaxError(msg) => Error(msg) 13 | | Parser_incr.Parsing_error(pos) => 14 | Error(Error.parser_error_with_info(~content, pos)) 15 | | Parser.Error => 16 | Error( 17 | Error.parser_error( 18 | ~msg=?None, 19 | ~content, 20 | ~start=lexbuf.lex_start_p, 21 | ~end_=lexbuf.lex_curr_p, 22 | ), 23 | ) 24 | | e => Error(Printexc.to_string(e)) 25 | }; 26 | }; 27 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions_should_get_optimized_into_literals_if__.7750d934.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions should get optimized into literals if possible › string literals 2 | module X: { 3 | type t = pri string; 4 | [@bs.inline \"x\"] 5 | let x: t; 6 | [@bs.inline \"y\"] 7 | let y: t; 8 | } = { 9 | type t = string; 10 | [@bs.inline] 11 | let x = \"x\"; 12 | [@bs.inline] 13 | let y = \"y\"; 14 | }; 15 | type x = X.t; 16 | module Y: { 17 | type t = pri string; 18 | [@bs.inline \"z\"] 19 | let z: t; 20 | [@bs.inline \"x\"] 21 | let x: t; 22 | [@bs.inline \"y\"] 23 | let y: t; 24 | } = { 25 | type t = string; 26 | [@bs.inline] 27 | let z = \"z\"; 28 | [@bs.inline] 29 | let x = \"x\"; 30 | [@bs.inline] 31 | let y = \"y\"; 32 | }; 33 | type y = Y.t; 34 | 35 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/config_flags_effects.ab9a2ad3.2.snapshot: -------------------------------------------------------------------------------- 1 | config flags effects › number_mode 2 | module Number: { 3 | type t; 4 | let float: float => t; 5 | let int: int => t; 6 | type case = 7 | | Int(int) 8 | | Float(float); 9 | let classify: t => case; 10 | } = { 11 | [@unboxed] 12 | type t = 13 | | Number('a): t; 14 | let float = (v: float) => Number(v); 15 | let int = (v: int) => Number(v); 16 | type case = 17 | | Int(int) 18 | | Float(float); 19 | let isInteger = v => 20 | Js.typeof(v) === \"number\" 21 | && Js.Float.isFinite(v) 22 | && Js.Math.floor_float(v) === v; 23 | let classify = (Number(v): t) => 24 | isInteger(Obj.magic(v)) 25 | ? Int(Obj.magic(v): int) : Float(Obj.magic(v): float); 26 | }; 27 | type t_number = Number.t; 28 | 29 | -------------------------------------------------------------------------------- /esy.lock/opam/conf-m4.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "tim@gfxmonk.net" 3 | homepage: "http://www.gnu.org/software/m4/m4.html" 4 | bug-reports: "https://github.com/ocaml/opam-repository/issues" 5 | authors: "GNU Project" 6 | license: "GPL-3.0-only" 7 | build: [["sh" "-exc" "echo | m4"]] 8 | depexts: [ 9 | ["m4"] {os-family = "debian"} 10 | ["m4"] {os-distribution = "fedora"} 11 | ["m4"] {os-distribution = "rhel"} 12 | ["m4"] {os-distribution = "centos"} 13 | ["m4"] {os-distribution = "alpine"} 14 | ["m4"] {os-distribution = "nixos"} 15 | ["m4"] {os-family = "suse"} 16 | ["m4"] {os-distribution = "ol"} 17 | ["m4"] {os-distribution = "arch"} 18 | ] 19 | synopsis: "Virtual package relying on m4" 20 | description: 21 | "This package can only install if the m4 binary is installed on the system." 22 | flags: conf 23 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions_should_get_optimized_into_literals_if__.451bd5c2.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions should get optimized into literals if possible › numeric only 2 | module X: { 3 | type t = pri int; 4 | [@bs.inline 3] 5 | let _3: t; 6 | [@bs.inline 4] 7 | let _4: t; 8 | } = { 9 | type t = int; 10 | [@bs.inline] 11 | let _3 = 3; 12 | [@bs.inline] 13 | let _4 = 4; 14 | }; 15 | type x = X.t; 16 | module Y: { 17 | type t = pri int; 18 | [@bs.inline 1] 19 | let _1: t; 20 | [@bs.inline 2] 21 | let _2: t; 22 | [@bs.inline 3] 23 | let _3: t; 24 | [@bs.inline 4] 25 | let _4: t; 26 | } = { 27 | type t = int; 28 | [@bs.inline] 29 | let _1 = 1; 30 | [@bs.inline] 31 | let _2 = 2; 32 | [@bs.inline] 33 | let _3 = 3; 34 | [@bs.inline] 35 | let _4 = 4; 36 | }; 37 | type y = Y.t; 38 | 39 | -------------------------------------------------------------------------------- /esy.lock/opam/fix.20200131/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "francois.pottier@inria.fr" 3 | authors: [ 4 | "François Pottier " 5 | ] 6 | homepage: "https://gitlab.inria.fr/fpottier/fix" 7 | dev-repo: "git+https://gitlab.inria.fr/fpottier/fix.git" 8 | bug-reports: "francois.pottier@inria.fr" 9 | build: [ 10 | ["dune" "build" "-p" name "-j" jobs] 11 | ] 12 | depends: [ 13 | "ocaml" { >= "4.03" } 14 | "dune" { >= "1.3" } 15 | ] 16 | synopsis: "Facilities for memoization and fixed points" 17 | url { 18 | src: 19 | "https://gitlab.inria.fr/fpottier/fix/repository/20200131/archive.tar.gz" 20 | checksum: [ 21 | "md5=991ff031666c662eaab638d2e0f4ac1d" 22 | "sha512=01c45a1d90b02ec0939e968b185a6a373ac6117e2287b9a26d3db9d71e9569d086cea50da60710fcab5c2ed9d3b4c72b76839c0651e436f1fb39c77dc7c04b5e" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions_should_get_optimized_into_literals_if__.22cfb2f5.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions should get optimized into literals if possible › works with array on the original 2 | module X: { 3 | type t = pri int; 4 | [@bs.inline 3] 5 | let _3: t; 6 | [@bs.inline 4] 7 | let _4: t; 8 | } = { 9 | type t = int; 10 | [@bs.inline] 11 | let _3 = 3; 12 | [@bs.inline] 13 | let _4 = 4; 14 | }; 15 | type x = X.t; 16 | module Y: { 17 | type t = pri int; 18 | [@bs.inline 1] 19 | let _1: t; 20 | [@bs.inline 2] 21 | let _2: t; 22 | [@bs.inline 3] 23 | let _3: t; 24 | [@bs.inline 4] 25 | let _4: t; 26 | } = { 27 | type t = int; 28 | [@bs.inline] 29 | let _1 = 1; 30 | [@bs.inline] 31 | let _2 = 2; 32 | [@bs.inline] 33 | let _3 = 3; 34 | [@bs.inline] 35 | let _4 = 4; 36 | }; 37 | type y = array(Y.t); 38 | 39 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions_should_get_optimized_into_literals_if__.346f96f1.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions should get optimized into literals if possible › works with optional on the original 2 | module X: { 3 | type t = pri int; 4 | [@bs.inline 3] 5 | let _3: t; 6 | [@bs.inline 4] 7 | let _4: t; 8 | } = { 9 | type t = int; 10 | [@bs.inline] 11 | let _3 = 3; 12 | [@bs.inline] 13 | let _4 = 4; 14 | }; 15 | type x = X.t; 16 | module Y: { 17 | type t = pri int; 18 | [@bs.inline 2] 19 | let _2: t; 20 | [@bs.inline 1] 21 | let _1: t; 22 | [@bs.inline 3] 23 | let _3: t; 24 | [@bs.inline 4] 25 | let _4: t; 26 | } = { 27 | type t = int; 28 | [@bs.inline] 29 | let _2 = 2; 30 | [@bs.inline] 31 | let _1 = 1; 32 | [@bs.inline] 33 | let _3 = 3; 34 | [@bs.inline] 35 | let _4 = 4; 36 | }; 37 | type y = option(Y.t); 38 | 39 | -------------------------------------------------------------------------------- /esy.lock/opam/ppx_derivers.1.2.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "jeremie@dimino.org" 3 | authors: ["Jérémie Dimino"] 4 | license: "BSD-3-Clause" 5 | homepage: "https://github.com/ocaml-ppx/ppx_derivers" 6 | bug-reports: "https://github.com/ocaml-ppx/ppx_derivers/issues" 7 | dev-repo: "git://github.com/ocaml-ppx/ppx_derivers.git" 8 | build: [ 9 | ["dune" "build" "-p" name "-j" jobs] 10 | ] 11 | depends: [ 12 | "ocaml" 13 | "dune" 14 | ] 15 | synopsis: "Shared [@@deriving] plugin registry" 16 | description: """ 17 | Ppx_derivers is a tiny package whose sole purpose is to allow 18 | ppx_deriving and ppx_type_conv to inter-operate gracefully when linked 19 | as part of the same ocaml-migrate-parsetree driver.""" 20 | url { 21 | src: "https://github.com/ocaml-ppx/ppx_derivers/archive/1.2.1.tar.gz" 22 | checksum: "md5=5dc2bf130c1db3c731fe0fffc5648b41" 23 | } 24 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_extractions.f5bf7965.0.snapshot: -------------------------------------------------------------------------------- 1 | type extractions › extracts multiple key types as refs if necessary 2 | type method_signature_func2 = (~x: float) => float 3 | and method_signature_func3 = (~x: string, ~y: bool) => unit 4 | and method_signature = { 5 | func1: (~x: float) => float, 6 | func2: method_signature_func2, 7 | func3: method_signature_func3, 8 | }; 9 | module Extracted_method_signature: { 10 | type t; 11 | let method_signature_func3: method_signature_func3 => t; 12 | let method_signature_func2: method_signature_func2 => t; 13 | } = { 14 | [@unboxed] 15 | type t = 16 | | Any('a): t; 17 | let method_signature_func3 = (v: method_signature_func3) => Any(v); 18 | let method_signature_func2 = (v: method_signature_func2) => Any(v); 19 | }; 20 | type extracted_method_signature = Extracted_method_signature.t; 21 | 22 | -------------------------------------------------------------------------------- /tests/native/__snapshots__/type_unions_should_get_optimized_into_literals_if__.89762c12.0.snapshot: -------------------------------------------------------------------------------- 1 | type unions should get optimized into literals if possible › works with array / nullable on the original 2 | module X: { 3 | type t = pri int; 4 | [@bs.inline 3] 5 | let _3: t; 6 | [@bs.inline 4] 7 | let _4: t; 8 | } = { 9 | type t = int; 10 | [@bs.inline] 11 | let _3 = 3; 12 | [@bs.inline] 13 | let _4 = 4; 14 | }; 15 | type x = X.t; 16 | module Y: { 17 | type t = pri int; 18 | [@bs.inline 2] 19 | let _2: t; 20 | [@bs.inline 1] 21 | let _1: t; 22 | [@bs.inline 3] 23 | let _3: t; 24 | [@bs.inline 4] 25 | let _4: t; 26 | } = { 27 | type t = int; 28 | [@bs.inline] 29 | let _2 = 2; 30 | [@bs.inline] 31 | let _1 = 1; 32 | [@bs.inline] 33 | let _3 = 3; 34 | [@bs.inline] 35 | let _4 = 4; 36 | }; 37 | type y = array(Js.Nullable.t(Y.t)); 38 | 39 | -------------------------------------------------------------------------------- /src/js/fs.re: -------------------------------------------------------------------------------- 1 | open Js_of_ocaml; 2 | 3 | type path = Fp.t(Fp.absolute); 4 | let base_path = Fp.absoluteExn("/examples"); 5 | 6 | module Loader: Re_typescript_fs.Loader.T = { 7 | let fs_name = "Js_of_ocaml"; 8 | let file_read = path => 9 | try(Ok(Sys_js.read_file(~name=path |> Fp.toString))) { 10 | | e => Error(Printexc.to_string(e)) 11 | }; 12 | let file_exists = path => CCIO.File.exists(path |> Fp.toString); 13 | }; 14 | 15 | module File = CCIO.File; 16 | let list_of_dir = (~recurse=false, path) => { 17 | let base = path |> Fp.toString; 18 | let get_entry = File.read_dir(~recurse, base); 19 | let rec walk = res => { 20 | switch (get_entry()) { 21 | | None => res 22 | | Some(entry) => 23 | let entry = 24 | recurse ? Fp.absoluteExn(entry) : Fp.append(base_path, entry); 25 | walk(res @ [entry]); 26 | }; 27 | }; 28 | walk([]); 29 | }; 30 | -------------------------------------------------------------------------------- /esy.lock/opam/result.1.5/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "opensource@janestreet.com" 3 | authors: ["Jane Street Group, LLC "] 4 | homepage: "https://github.com/janestreet/result" 5 | dev-repo: "git+https://github.com/janestreet/result.git" 6 | bug-reports: "https://github.com/janestreet/result/issues" 7 | license: "BSD-3-Clause" 8 | build: [["dune" "build" "-p" name "-j" jobs]] 9 | depends: [ 10 | "ocaml" 11 | "dune" {>= "1.0"} 12 | ] 13 | synopsis: "Compatibility Result module" 14 | description: """ 15 | Projects that want to use the new result type defined in OCaml >= 4.03 16 | while staying compatible with older version of OCaml should use the 17 | Result module defined in this library.""" 18 | url { 19 | src: 20 | "https://github.com/janestreet/result/releases/download/1.5/result-1.5.tbz" 21 | checksum: "md5=1b82dec78849680b49ae9a8a365b831b" 22 | } 23 | -------------------------------------------------------------------------------- /tests/native/TypeSyntax.re: -------------------------------------------------------------------------------- 1 | open TestFramework; 2 | 3 | describe("basic syntax for types", ({test, _}) => { 4 | test("basic type definition", ({expect, _}) => { 5 | expect.string(print("type t_string = string;")).toMatchSnapshot(); 6 | expect.string(print("type t_number = number;")).toMatchSnapshot(); 7 | expect.string(print("type t_bool = boolean;")).toMatchSnapshot(); 8 | }); 9 | 10 | test("basic type definition without semicolon", ({expect, _}) => { 11 | expect.string(print("type t_string = string")).toMatchSnapshot() 12 | }); 13 | 14 | test("adds extra type for any", ({expect, _}) => { 15 | expect.string(print("type t_any = any")).toMatchSnapshot() 16 | }); 17 | 18 | test("comments should not throw", ({expect, _}) => { 19 | expect.string(print({|// This is a comment|})).toMatch(""); 20 | expect.string(print({|/* This is a comment */|})).toMatch(""); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /esy.lock/opam/integers.0.4.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "yallop@gmail.com" 3 | authors: ["Jeremy Yallop" 4 | "Demi Obenour" 5 | "Stephane Glondu" 6 | "Andreas Hauptmann"] 7 | homepage: "https://github.com/ocamllabs/ocaml-integers" 8 | bug-reports: "https://github.com/ocamllabs/ocaml-integers/issues" 9 | dev-repo: "git+https://github.com/ocamllabs/ocaml-integers.git" 10 | license: "MIT" 11 | 12 | build: [ 13 | ["dune" "subst"] {pinned} 14 | ["dune" "build" "-p" name "-j" jobs] 15 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 16 | ] 17 | 18 | depends: [ 19 | "ocaml" {>= "4.02"} 20 | "dune" 21 | ] 22 | doc: "http://ocamllabs.github.io/ocaml-integers/api.docdir/" 23 | synopsis: "Various signed and unsigned integer types for OCaml" 24 | url { 25 | src: "https://github.com/ocamllabs/ocaml-integers/archive/0.4.0.tar.gz" 26 | checksum: "md5=c1492352e6525048790508c57aad93c3" 27 | } 28 | -------------------------------------------------------------------------------- /src/config/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name re_typescript_config) 3 | (public_name re_typescript.config) 4 | (libraries biniou atdgen yojson)) 5 | 6 | (rule 7 | (targets config_t.ml config_t.mli) 8 | (deps config.atd) 9 | (action 10 | (run atdgen -t %{deps}))) 11 | 12 | (rule 13 | (targets config_j.ml config_j.mli) 14 | (deps config.atd) 15 | (action 16 | (run atdgen -j -j-std %{deps}))) 17 | 18 | (rule 19 | (targets bridge_t.ml bridge_t.mli) 20 | (deps bridge.atd) 21 | (action 22 | (run atdgen -t %{deps}))) 23 | 24 | (rule 25 | (targets bridge_j.ml bridge_j.mli) 26 | (deps bridge.atd) 27 | (action 28 | (run atdgen -j -j-std %{deps}))) 29 | 30 | (rule 31 | (targets parse_info_t.ml parse_info_t.mli) 32 | (deps parse_info.atd) 33 | (action 34 | (run atdgen -t %{deps}))) 35 | 36 | (rule 37 | (targets parse_info_j.ml parse_info_j.mli) 38 | (deps parse_info.atd) 39 | (action 40 | (run atdgen -j -j-std %{deps}))) 41 | -------------------------------------------------------------------------------- /src/config/re_typescript_config.re: -------------------------------------------------------------------------------- 1 | module Config = Config_j; 2 | module Bridge = Bridge_j; 3 | module Parse_info = Parse_info_j; 4 | 5 | open Config; 6 | 7 | let default_bucklescript_config = { 8 | string_variant_mode: `BsInline, 9 | mixed_variant_mode: `BsUnboxed, 10 | number_variant_mode: `BsInline(Some({prefix: "_", suffix: ""})), 11 | union_mode: `KeepLiterals, 12 | }; 13 | 14 | let default_config: config = { 15 | suppress_warning_for_extended_records: false, 16 | omit_extended_unreferenced_records: false, 17 | output_type: Bucklescript, 18 | bucklescript_config: default_bucklescript_config, 19 | array_mode: Array, 20 | number_mode: Float, 21 | intersection_mode: { 22 | objects: Tuple, 23 | unions: Tuple, 24 | classes: Tuple, 25 | functions: Tuple, 26 | other: Tuple, 27 | tuple_members_optional: false, 28 | }, 29 | generate_parser: false, 30 | generate_serializer: false, 31 | }; 32 | -------------------------------------------------------------------------------- /esy.lock/opam/menhir.20200612/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "francois.pottier@inria.fr" 3 | authors: [ 4 | "François Pottier " 5 | "Yann Régis-Gianas " 6 | ] 7 | homepage: "http://gitlab.inria.fr/fpottier/menhir" 8 | dev-repo: "git+https://gitlab.inria.fr/fpottier/menhir.git" 9 | bug-reports: "menhir@inria.fr" 10 | build: [ 11 | ["dune" "build" "-p" name "-j" jobs] 12 | ] 13 | depends: [ 14 | "ocaml" {>= "4.02.3"} 15 | "dune" { >= "2.2.0"} 16 | "menhirLib" {= version} 17 | "menhirSdk" {= version} 18 | ] 19 | synopsis: "An LR(1) parser generator" 20 | url { 21 | src: 22 | "https://gitlab.inria.fr/fpottier/menhir/repository/20200612/archive.tar.gz" 23 | checksum: [ 24 | "md5=eb1c13439a00195ee01e4a2e83b3e991" 25 | "sha512=c94ddc2b2d8b9f5d05d8493a3ccd4a32e4512c3bd19ac8948905eb64bb6f2fd9e236344d2baf3d2ebae379d08d5169c99aa5e721c65926127e22ea283eba6167" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /src_js/Sync.re: -------------------------------------------------------------------------------- 1 | open Config_t; 2 | open! Bridge_bs; 3 | 4 | let default_bucklescript_config = { 5 | string_variant_mode: `BsInline, 6 | mixed_variant_mode: `BsUnboxed, 7 | number_variant_mode: `BsInline(None), 8 | union_mode: `KeepLiterals, 9 | }; 10 | 11 | let default_config: config = { 12 | suppress_warning_for_extended_records: false, 13 | omit_extended_unreferenced_records: false, 14 | output_type: Bucklescript, 15 | bucklescript_config: default_bucklescript_config, 16 | array_mode: Array, 17 | number_mode: Float, 18 | intersection_mode: { 19 | objects: Tuple, 20 | unions: Tuple, 21 | classes: Tuple, 22 | functions: Tuple, 23 | other: Tuple, 24 | tuple_members_optional: false, 25 | }, 26 | generate_parser: false, 27 | generate_serializer: false, 28 | }; 29 | 30 | let config = { 31 | ...default_config, 32 | number_mode: Int, 33 | output_type: Bucklescript, 34 | omit_extended_unreferenced_records: true, 35 | }; -------------------------------------------------------------------------------- /esy.lock/opam/ppx_yojson_conv_lib.v0.14.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "opensource@janestreet.com" 3 | authors: ["Jane Street Group, LLC "] 4 | homepage: "https://github.com/janestreet/ppx_yojson_conv_lib" 5 | bug-reports: "https://github.com/janestreet/ppx_yojson_conv_lib/issues" 6 | dev-repo: "git+https://github.com/janestreet/ppx_yojson_conv_lib.git" 7 | doc: "https://ocaml.janestreet.com/ocaml-core/latest/doc/ppx_yojson_conv_lib/index.html" 8 | license: "MIT" 9 | build: [ 10 | ["dune" "build" "-p" name "-j" jobs] 11 | ] 12 | depends: [ 13 | "ocaml" {>= "4.02.3"} 14 | "dune" {>= "2.0.0"} 15 | "yojson" {>= "1.7.0"} 16 | ] 17 | synopsis: "Runtime lib for ppx_yojson_conv" 18 | description: " 19 | Part of the Jane Street's PPX rewriters collection. 20 | " 21 | url { 22 | src: "https://ocaml.janestreet.com/ocaml-core/v0.14/files/ppx_yojson_conv_lib-v0.14.0.tar.gz" 23 | checksum: "md5=e23c5593a7211ad4fb09e26e9a74698a" 24 | } 25 | -------------------------------------------------------------------------------- /esy.lock/opam/menhirLib.20200612/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "francois.pottier@inria.fr" 3 | authors: [ 4 | "François Pottier " 5 | "Yann Régis-Gianas " 6 | ] 7 | homepage: "http://gitlab.inria.fr/fpottier/menhir" 8 | dev-repo: "git+https://gitlab.inria.fr/fpottier/menhir.git" 9 | bug-reports: "menhir@inria.fr" 10 | build: [ 11 | ["dune" "build" "-p" name "-j" jobs] 12 | ] 13 | depends: [ 14 | "ocaml" { >= "4.02.3" } 15 | "dune" { >= "2.0.0" } 16 | ] 17 | conflicts: [ 18 | "menhir" { != version } 19 | ] 20 | synopsis: "Runtime support library for parsers generated by Menhir" 21 | url { 22 | src: 23 | "https://gitlab.inria.fr/fpottier/menhir/repository/20200612/archive.tar.gz" 24 | checksum: [ 25 | "md5=eb1c13439a00195ee01e4a2e83b3e991" 26 | "sha512=c94ddc2b2d8b9f5d05d8493a3ccd4a32e4512c3bd19ac8948905eb64bb6f2fd9e236344d2baf3d2ebae379d08d5169c99aa5e721c65926127e22ea283eba6167" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /esy.lock/opam/ppx_tools_versioned.5.4.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | version: "5.4.0" 3 | maintainer: "frederic.bour@lakaban.net" 4 | authors: [ 5 | "Frédéric Bour " 6 | "Alain Frisch " 7 | ] 8 | license: "MIT" 9 | homepage: "https://github.com/ocaml-ppx/ppx_tools_versioned" 10 | bug-reports: "https://github.com/ocaml-ppx/ppx_tools_versioned/issues" 11 | dev-repo: "git://github.com/ocaml-ppx/ppx_tools_versioned.git" 12 | tags: [ "syntax" ] 13 | build: [ 14 | ["dune" "subst"] {pinned} 15 | ["dune" "build" "-p" name "-j" jobs] 16 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 17 | ] 18 | depends: [ 19 | "ocaml" {>= "4.02.0"} 20 | "dune" {>= "1.0"} 21 | "ocaml-migrate-parsetree" {>= "1.7.0"} 22 | ] 23 | synopsis: "A variant of ppx_tools based on ocaml-migrate-parsetree" 24 | url { 25 | src: "https://github.com/ocaml-ppx/ppx_tools_versioned/archive/5.4.0.tar.gz" 26 | checksum: "md5=3e809a11cae99f57c051d3d0100311f6" 27 | } 28 | -------------------------------------------------------------------------------- /tests/native/TypeNames.re: -------------------------------------------------------------------------------- 1 | open TestFramework; 2 | 3 | describe("generates valid type names", ({test, _}) => { 4 | test("capitalized", ({expect, _}) => { 5 | expect.string(print("type T_string = string")).toMatchSnapshot() 6 | }); 7 | test("reserved keyword", ({expect, _}) => { 8 | expect.string(print("type rec = string")).toMatchSnapshot(); 9 | expect.string(print("type sig = string")).toMatchSnapshot(); 10 | }); 11 | test("invalid characters", ({expect, _}) => { 12 | expect.string(print("type st$ring = string")).toMatchSnapshot(); 13 | expect.string(print("type t_$string = string")).toMatchSnapshot(); 14 | expect.string(print("type $_string = string")).toMatchSnapshot(); 15 | expect.string(print("type t_$string = string")).toMatchSnapshot(); 16 | // Invalid TS typenames should not be parsed at all 17 | expect.fn(() => print("type 1_string = string")).toThrow(); 18 | expect.fn(() => print("type st.ring = string")).toThrow(); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /esy.lock/opam/menhirSdk.20200612/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "francois.pottier@inria.fr" 3 | authors: [ 4 | "François Pottier " 5 | "Yann Régis-Gianas " 6 | ] 7 | homepage: "http://gitlab.inria.fr/fpottier/menhir" 8 | dev-repo: "git+https://gitlab.inria.fr/fpottier/menhir.git" 9 | bug-reports: "menhir@inria.fr" 10 | build: [ 11 | ["dune" "build" "-p" name "-j" jobs] 12 | ] 13 | depends: [ 14 | "ocaml" { >= "4.02.3" } 15 | "dune" { >= "2.0.0" } 16 | ] 17 | conflicts: [ 18 | "menhir" { != version } 19 | ] 20 | synopsis: "Compile-time library for auxiliary tools related to Menhir" 21 | url { 22 | src: 23 | "https://gitlab.inria.fr/fpottier/menhir/repository/20200612/archive.tar.gz" 24 | checksum: [ 25 | "md5=eb1c13439a00195ee01e4a2e83b3e991" 26 | "sha512=c94ddc2b2d8b9f5d05d8493a3ccd4a32e4512c3bd19ac8948905eb64bb6f2fd9e236344d2baf3d2ebae379d08d5169c99aa5e721c65926127e22ea283eba6167" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /src/base/parse_info.re: -------------------------------------------------------------------------------- 1 | open Re_typescript_config.Parse_info; 2 | 3 | type t = Re_typescript_config.Parse_info.t; 4 | 5 | let zero = {src: None, name: None, col: 0, line: 0, idx: 0}; 6 | 7 | let t_of_lexbuf = (lexbuf): t => { 8 | let idx = lexbuf.Lexing.lex_start_p.Lexing.pos_cnum; 9 | let (line, col) = ( 10 | lexbuf.Lexing.lex_start_p.pos_lnum, 11 | lexbuf.Lexing.lex_start_p.pos_cnum - lexbuf.Lexing.lex_start_p.pos_bol, 12 | ); 13 | 14 | let name = Some(lexbuf.Lexing.lex_start_p.pos_fname); 15 | let src = Some(lexbuf.Lexing.lex_start_p.pos_fname); 16 | {idx, line, col, name, src}; 17 | }; 18 | 19 | let start_position = (t: t) => { 20 | Lexing.pos_fname: CCOpt.get_or(~default="", t.name), 21 | pos_lnum: t.line, 22 | pos_bol: t.idx - t.col, 23 | pos_cnum: t.idx, 24 | }; 25 | 26 | let t_of_position = (~src, pos) => { 27 | name: Some(pos.Lexing.pos_fname), 28 | src, 29 | line: pos.Lexing.pos_lnum, 30 | col: pos.Lexing.pos_cnum - pos.Lexing.pos_bol, 31 | idx: 0, 32 | }; 33 | -------------------------------------------------------------------------------- /src_js/Worker.re: -------------------------------------------------------------------------------- 1 | [@bs.val] 2 | [@bs.module "./../../../_build/default/src/js/re_typescript_js.bc.js"] 3 | external run: string => string = "run"; 4 | [@bs.val] 5 | [@bs.module "./../../../_build/default/src/js/re_typescript_js.bc.js"] 6 | external example_list: unit => string = "example_list"; 7 | 8 | WebWorkers.setWorkerOnMessage( 9 | WebWorkers.self, 10 | (e: WebWorkers.MessageEvent.t) => { 11 | let data = WebWorkers.MessageEvent.data(e); 12 | switch (data) { 13 | | Bridge_t.Parse(parse_request) => 14 | Bridge_t.Res_Parse( 15 | run( 16 | parse_request |> Bridge_bs.write_parse_request |> Js.Json.stringify, 17 | ) 18 | |> Js.Json.parseExn 19 | |> Bridge_bs.read_parse_result, 20 | ) 21 | |> WebWorkers.postMessageFromWorker 22 | | Bridge_t.ExampleList => 23 | Bridge_t.Res_ExampleList( 24 | example_list() |> Js.Json.parseExn |> Bridge_bs.read_example_list, 25 | ) 26 | |> WebWorkers.postMessageFromWorker 27 | }; 28 | }, 29 | ); -------------------------------------------------------------------------------- /tests/native/ReferenceResolution.re: -------------------------------------------------------------------------------- 1 | open TestFramework; 2 | 3 | describe("reference resolution", ({test, _}) => { 4 | test("resolve simple definitions", ({expect, _}) => { 5 | expect.string( 6 | print({| 7 | type t_str = string; 8 | type t_ref = t_str; 9 | |}), 10 | ). 11 | toMatchSnapshot() 12 | }); 13 | 14 | test("resolve in interface fields", ({expect, _}) => { 15 | expect.string( 16 | print( 17 | {| 18 | type t_str = string; 19 | interface I_Ref { 20 | f_num: number; 21 | f_str: t_str; 22 | }; 23 | type r_ref = { 24 | inner: I_Ref 25 | } 26 | |}, 27 | ), 28 | ). 29 | toMatchSnapshot() 30 | }); 31 | 32 | test("resolve recursively", ({expect, _}) => { 33 | expect.string( 34 | print( 35 | {| 36 | interface I_Ref { 37 | f_num: number; 38 | f_inner: I_Ref 39 | }; 40 | |}, 41 | ), 42 | ). 43 | toMatchSnapshot() 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /esy.lock/opam/stdlib-shims.0.1.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "The stdlib-shims programmers" 3 | authors: "The stdlib-shims programmers" 4 | homepage: "https://github.com/ocaml/stdlib-shims" 5 | doc: "https://ocaml.github.io/stdlib-shims/" 6 | dev-repo: "git+https://github.com/ocaml/stdlib-shims.git" 7 | bug-reports: "https://github.com/ocaml/stdlib-shims/issues" 8 | tags: ["stdlib" "compatibility" "org:ocaml"] 9 | license: ["typeof OCaml system"] 10 | depends: [ 11 | "dune" 12 | "ocaml" {>= "4.02.3"} 13 | ] 14 | build: [ "dune" "build" "-p" name "-j" jobs ] 15 | synopsis: "Backport some of the new stdlib features to older compiler" 16 | description: """ 17 | Backport some of the new stdlib features to older compiler, 18 | such as the Stdlib module. 19 | 20 | This allows projects that require compatibility with older compiler to 21 | use these new features in their code. 22 | """ 23 | url { 24 | src: 25 | "https://github.com/ocaml/stdlib-shims/releases/download/0.1.0/stdlib-shims-0.1.0.tbz" 26 | checksum: "md5=12b5704eed70c6bff5ac39a16db1425d" 27 | } 28 | -------------------------------------------------------------------------------- /esy.lock/opam/reason.3.6.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Jordan Walke " 3 | authors: [ "Jordan Walke " ] 4 | license: "MIT" 5 | homepage: "https://github.com/facebook/reason" 6 | doc: "http://reasonml.github.io/" 7 | bug-reports: "https://github.com/facebook/reason/issues" 8 | dev-repo: "git://github.com/facebook/reason.git" 9 | tags: [ "syntax" ] 10 | build: [ 11 | ["dune" "build" "-p" name "-j" jobs] 12 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 13 | ] 14 | depends: [ 15 | "ocaml" {>= "4.03" & < "4.11"} 16 | "dune" {>= "1.4"} 17 | "ocamlfind" {build} 18 | "menhir" {>= "20170418"} 19 | "merlin-extend" {>= "0.4"} 20 | "fix" 21 | "result" 22 | "ocaml-migrate-parsetree" 23 | ] 24 | synopsis: "Reason: Syntax & Toolchain for OCaml" 25 | description: """ 26 | Reason gives OCaml a new syntax that is remniscient of languages like 27 | JavaScript. It's also the umbrella project for a set of tools for the OCaml & 28 | JavaScript ecosystem.""" 29 | url { 30 | src: "https://registry.npmjs.org/@esy-ocaml/reason/-/reason-3.6.0.tgz" 31 | checksum: "md5=d4d729804bc509bca0ac6223e06f7314" 32 | } 33 | -------------------------------------------------------------------------------- /esy.lock/opam/js_of_ocaml-ppx.3.6.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "dev@ocsigen.org" 3 | authors: "Ocsigen team" 4 | bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" 5 | homepage: "http://ocsigen.github.io/js_of_ocaml" 6 | dev-repo: "git+https://github.com/ocsigen/js_of_ocaml.git" 7 | synopsis: "Compiler from OCaml bytecode to Javascript" 8 | description: """ 9 | Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. 10 | It makes it possible to run pure OCaml programs in JavaScript 11 | environment like browsers and Node.js 12 | """ 13 | 14 | build: [["dune" "build" "-p" name "-j" jobs]] 15 | 16 | depends: [ 17 | "ocaml" {>= "4.02.0"} 18 | "dune" {>= "2.5"} 19 | "ocaml-migrate-parsetree" {>= "1.4"} 20 | "ppx_tools_versioned" {>= "5.2.3"} 21 | "js_of_ocaml" {= version} 22 | ] 23 | url { 24 | src: 25 | "https://github.com/ocsigen/js_of_ocaml/releases/download/3.6.0/js_of_ocaml-3.6.0.tbz" 26 | checksum: [ 27 | "sha256=51eaa89c83ef3168ef270bf7997cbc35a747936d3f51aa6fac58fb0323b4cbb0" 28 | "sha512=a2171a2583e9a1be6b4a87c9958aa2b4936b1f19030f09d787c4824d04db864773dd1da10d0dd56822f279309c8217093552b94e2e93c8b01eba5f432afc7718" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /esy.lock/opam/merlin-extend.0.5/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Frederic Bour " 3 | authors: "Frederic Bour " 4 | homepage: "https://github.com/let-def/merlin-extend" 5 | bug-reports: "https://github.com/let-def/merlin-extend" 6 | license: "MIT" 7 | dev-repo: "git+https://github.com/let-def/merlin-extend.git" 8 | build: [ 9 | ["dune" "subst"] {pinned} 10 | ["dune" "build" "-p" name "-j" jobs] 11 | ] 12 | depends: [ 13 | "dune" {>= "1.0"} 14 | "cppo" {build} 15 | "ocaml" {>= "4.02.3" & < "4.11"} 16 | ] 17 | synopsis: "A protocol to provide custom frontend to Merlin" 18 | description: """ 19 | This protocol allows to replace the OCaml frontend of Merlin. 20 | It extends what used to be done with the `-pp' flag to handle a few more cases.""" 21 | doc: "https://let-def.github.io/merlin-extend" 22 | url { 23 | src: 24 | "https://github.com/let-def/merlin-extend/releases/download/v0.5/merlin-extend-v0.5.tbz" 25 | checksum: [ 26 | "sha256=ca3a38c360c7d4827eb4789abf7a6aa4b6e3b4e3c3ef69a5be64dce4601ec227" 27 | "sha512=55c5a3637337abb8ca8db679128a81ca8ccce567bc214d55b2e6444dc0e905b74c64d629bdea2457d0fe4be5306414feefcdbc4d4761fdafd59aa107550936b6" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /ts_inspiration/intersection.d.ts: -------------------------------------------------------------------------------- 1 | interface ErrorHandling { 2 | success: boolean; 3 | error?: { message: string }; 4 | } 5 | 6 | interface ArtworksData { 7 | artworks: { title: string }[]; 8 | } 9 | 10 | interface ArtistsData { 11 | artists: { name: string }[]; 12 | } 13 | 14 | // These interfaces are composed to have 15 | // consistent error handling, and their own data. 16 | 17 | type ArtworksResponse = ArtworksData & ErrorHandling; 18 | type ArtistsResponse = ArtistsData & ErrorHandling; 19 | 20 | export const handleArtistsResponse: (response: ArtistsResponse) => void; 21 | 22 | // ----------------------------------- 23 | 24 | // interface A { 25 | // a: number; 26 | // } 27 | // interface B { 28 | // b: number; 29 | // } 30 | 31 | // var ab: A & B = { a: 1, b: 1 }; 32 | // var a: A = ab; // A & B assignable to A 33 | // var b: B = ab; // A & B assignable to B 34 | 35 | // interface X { 36 | // p: A; 37 | // } 38 | // interface Y { 39 | // p: B; 40 | // } 41 | 42 | // var xy: X & Y = { p: ab }; // X & Y has property p of type A & B 43 | 44 | // type F1 = (a: string, b: string) => void; 45 | // type F2 = (a: number, b: number) => void; 46 | 47 | // type F3 = F1 & F2; 48 | // var f: (a: string | number, b: string | number) => {}; 49 | -------------------------------------------------------------------------------- /esy.lock/opam/js_of_ocaml.3.6.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "dev@ocsigen.org" 3 | authors: "Ocsigen team" 4 | bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" 5 | homepage: "http://ocsigen.github.io/js_of_ocaml" 6 | dev-repo: "git+https://github.com/ocsigen/js_of_ocaml.git" 7 | synopsis: "Compiler from OCaml bytecode to Javascript" 8 | description: """ 9 | Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. 10 | It makes it possible to run pure OCaml programs in JavaScript 11 | environment like browsers and Node.js 12 | """ 13 | 14 | name: "js_of_ocaml" 15 | 16 | build: [["dune" "build" "-p" name "-j" jobs]] 17 | 18 | depends: [ 19 | "ocaml" {>= "4.02.0"} 20 | "dune" {>= "2.5"} 21 | "ocaml-migrate-parsetree" {>= "1.4"} 22 | "ppx_tools_versioned" {>= "5.2.3"} 23 | "uchar" 24 | "js_of_ocaml-compiler" {= version} 25 | ] 26 | url { 27 | src: 28 | "https://github.com/ocsigen/js_of_ocaml/releases/download/3.6.0/js_of_ocaml-3.6.0.tbz" 29 | checksum: [ 30 | "sha256=51eaa89c83ef3168ef270bf7997cbc35a747936d3f51aa6fac58fb0323b4cbb0" 31 | "sha512=a2171a2583e9a1be6b4a87c9958aa2b4936b1f19030f09d787c4824d04db864773dd1da10d0dd56822f279309c8217093552b94e2e93c8b01eba5f432afc7718" 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /esy.lock/overrides/opam__s__ocamlfind_opam__c__1.8.1_opam_override/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": [ 3 | [ 4 | "bash", 5 | "-c", 6 | "#{os == 'windows' ? 'patch -p1 < findlib-1.8.1.patch' : 'true'}" 7 | ], 8 | [ 9 | "./configure", 10 | "-bindir", 11 | "#{self.bin}", 12 | "-sitelib", 13 | "#{self.lib}", 14 | "-mandir", 15 | "#{self.man}", 16 | "-config", 17 | "#{self.lib}/findlib.conf", 18 | "-no-custom", 19 | "-no-topfind" 20 | ], 21 | [ 22 | "make", 23 | "all" 24 | ], 25 | [ 26 | "make", 27 | "opt" 28 | ] 29 | ], 30 | "install": [ 31 | [ 32 | "make", 33 | "install" 34 | ], 35 | [ 36 | "install", 37 | "-m", 38 | "0755", 39 | "ocaml-stub", 40 | "#{self.bin}/ocaml" 41 | ], 42 | [ 43 | "mkdir", 44 | "-p", 45 | "#{self.toplevel}" 46 | ], 47 | [ 48 | "install", 49 | "-m", 50 | "0644", 51 | "src/findlib/topfind", 52 | "#{self.toplevel}/topfind" 53 | ] 54 | ], 55 | "exportedEnv": { 56 | "OCAML_TOPLEVEL_PATH": { 57 | "val": "#{self.toplevel}", 58 | "scope": "global" 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | re-typescript Playground 6 | 38 | 42 | 48 | 49 | 50 |

51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /esy.lock/opam/junit.2.0.2/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Louis Roché " 3 | authors: "Louis Roché " 4 | homepage: "https://github.com/Khady/ocaml-junit" 5 | bug-reports: "https://github.com/Khady/ocaml-junit/issues" 6 | license: "LGPLv3+ with OCaml linking exception" 7 | dev-repo: "git+https://github.com/Khady/ocaml-junit.git" 8 | doc: "https://khady.github.io/ocaml-junit/" 9 | tags: ["junit" "jenkins"] 10 | depends: [ 11 | "dune" {>= "1.0"} 12 | "ptime" 13 | "tyxml" {>= "4.0.0"} 14 | "odoc" {with-doc & >= "1.1.1"} 15 | ] 16 | build: [ 17 | ["dune" "subst"] {pinned} 18 | ["dune" "build" "-p" name "-j" jobs] 19 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 20 | ["dune" "build" "-p" name "-j" jobs] {with-doc} 21 | ] 22 | name: "junit" 23 | synopsis: "JUnit XML reports generation library" 24 | description: "JUnit XML reports generation library" 25 | url { 26 | src: 27 | "https://github.com/Khady/ocaml-junit/releases/download/2.0.2/junit-2.0.2.tbz" 28 | checksum: [ 29 | "sha256=fda941b653613a4a5731f9b3557364b12baa341daa13c01676c9eb8d64e96b01" 30 | "sha512=5a9fa803c4861748bb8482fc51197420bf3cc3b9540989a489c4ffb65fdd02386aaa60437eae29182209dae0903b0e537c095249e19d395a451b8e8214f15f03" 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /esy.lock/opam/ocamlbuild.0.14.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Gabriel Scherer " 3 | authors: ["Nicolas Pouillard" "Berke Durak"] 4 | homepage: "https://github.com/ocaml/ocamlbuild/" 5 | bug-reports: "https://github.com/ocaml/ocamlbuild/issues" 6 | license: "LGPL-2.1-only with OCaml-LGPL-linking-exception" 7 | doc: "https://github.com/ocaml/ocamlbuild/blob/master/manual/manual.adoc" 8 | dev-repo: "git+https://github.com/ocaml/ocamlbuild.git" 9 | build: [ 10 | [ 11 | make 12 | "-f" 13 | "configure.make" 14 | "all" 15 | "OCAMLBUILD_PREFIX=%{prefix}%" 16 | "OCAMLBUILD_BINDIR=%{bin}%" 17 | "OCAMLBUILD_LIBDIR=%{lib}%" 18 | "OCAMLBUILD_MANDIR=%{man}%" 19 | "OCAML_NATIVE=%{ocaml:native}%" 20 | "OCAML_NATIVE_TOOLS=%{ocaml:native}%" 21 | ] 22 | [make "check-if-preinstalled" "all" "opam-install"] 23 | ] 24 | conflicts: [ 25 | "base-ocamlbuild" 26 | "ocamlfind" {< "1.6.2"} 27 | ] 28 | synopsis: 29 | "OCamlbuild is a build system with builtin rules to easily build most OCaml projects." 30 | depends: [ 31 | "ocaml" {>= "4.03"} 32 | ] 33 | url { 34 | src: "https://github.com/ocaml/ocamlbuild/archive/0.14.0.tar.gz" 35 | checksum: "sha256=87b29ce96958096c0a1a8eeafeb6268077b2d11e1bf2b3de0f5ebc9cf8d42e78" 36 | } 37 | -------------------------------------------------------------------------------- /esy.lock/opam/uchar.0.0.2/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Daniel Bünzli " 3 | authors: ["Daniel Bünzli "] 4 | homepage: "http://ocaml.org" 5 | doc: "https://ocaml.github.io/uchar/" 6 | dev-repo: "git+https://github.com/ocaml/uchar.git" 7 | bug-reports: "https://github.com/ocaml/uchar/issues" 8 | tags: [ "text" "character" "unicode" "compatibility" "org:ocaml.org" ] 9 | license: "typeof OCaml system" 10 | depends: [ 11 | "ocaml" {>= "3.12.0"} 12 | "ocamlbuild" {build} 13 | ] 14 | build: [ 15 | ["ocaml" "pkg/git.ml"] 16 | [ 17 | "ocaml" 18 | "pkg/build.ml" 19 | "native=%{ocaml:native}%" 20 | "native-dynlink=%{ocaml:native-dynlink}%" 21 | ] 22 | ] 23 | synopsis: "Compatibility library for OCaml's Uchar module" 24 | description: """ 25 | The `uchar` package provides a compatibility library for the 26 | [`Uchar`][1] module introduced in OCaml 4.03. 27 | 28 | The `uchar` package is distributed under the license of the OCaml 29 | compiler. See [LICENSE](LICENSE) for details. 30 | 31 | [1]: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Uchar.html""" 32 | url { 33 | src: 34 | "https://github.com/ocaml/uchar/releases/download/v0.0.2/uchar-0.0.2.tbz" 35 | checksum: "md5=c9ba2c738d264c420c642f7bb1cf4a36" 36 | } 37 | -------------------------------------------------------------------------------- /esy.lock/opam/re.1.9.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | 3 | maintainer: "rudi.grinberg@gmail.com" 4 | authors: [ 5 | "Jerome Vouillon" 6 | "Thomas Gazagnaire" 7 | "Anil Madhavapeddy" 8 | "Rudi Grinberg" 9 | "Gabriel Radanne" 10 | ] 11 | license: "LGPL-2.0-only with OCaml-LGPL-linking-exception" 12 | homepage: "https://github.com/ocaml/ocaml-re" 13 | bug-reports: "https://github.com/ocaml/ocaml-re/issues" 14 | dev-repo: "git+https://github.com/ocaml/ocaml-re.git" 15 | 16 | build: [ 17 | ["dune" "subst"] {pinned} 18 | ["dune" "build" "-p" name "-j" jobs] 19 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 20 | ] 21 | 22 | depends: [ 23 | "ocaml" {>= "4.02"} 24 | "dune" 25 | "ounit" {with-test} 26 | "seq" 27 | ] 28 | 29 | synopsis: "RE is a regular expression library for OCaml" 30 | description: """ 31 | Pure OCaml regular expressions with: 32 | * Perl-style regular expressions (module Re.Perl) 33 | * Posix extended regular expressions (module Re.Posix) 34 | * Emacs-style regular expressions (module Re.Emacs) 35 | * Shell-style file globbing (module Re.Glob) 36 | * Compatibility layer for OCaml's built-in Str module (module Re.Str) 37 | """ 38 | url { 39 | src: 40 | "https://github.com/ocaml/ocaml-re/releases/download/1.9.0/re-1.9.0.tbz" 41 | checksum: "md5=bddaed4f386a22cace7850c9c7dac296" 42 | } 43 | -------------------------------------------------------------------------------- /.github/workflows/pipeline.yml: -------------------------------------------------------------------------------- 1 | name: re-typescript pipeline 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | run_tests: 7 | name: ${{ matrix.os }}/node-${{ matrix.node-version }} 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | node-version: [12.x] 12 | os: [windows-latest, macOS-latest, ubuntu-latest] 13 | 14 | steps: 15 | - uses: actions/checkout@v1 16 | 17 | - name: Use Node.js ${{ matrix.node-version }} 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | 22 | - name: Install esy 23 | run: | 24 | npm install -g esy@latest 25 | 26 | - name: Install 27 | run: esy install 28 | 29 | - name: Print esy cache 30 | id: print_esy_cache 31 | run: node .github/workflows/print_esy_cache.js 32 | 33 | - name: Try to restore dependencies cache 34 | id: deps-cache-macos 35 | uses: actions/cache@v1 36 | with: 37 | path: ${{ steps.print_esy_cache.outputs.esy_cache }} 38 | key: ${{ matrix.os }}-${{ hashFiles('**/index.json') }} 39 | 40 | - name: build 41 | run: esy b 42 | 43 | - name: run-tests 44 | run: | 45 | esy test 46 | env: 47 | CI: true 48 | -------------------------------------------------------------------------------- /esy.lock/opam/cppo.1.6.6/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "martin@mjambon.com" 3 | authors: "Martin Jambon" 4 | license: "BSD-3-Clause" 5 | homepage: "http://mjambon.com/cppo.html" 6 | doc: "https://ocaml-community.github.io/cppo/" 7 | bug-reports: "https://github.com/ocaml-community/cppo/issues" 8 | depends: [ 9 | "ocaml" {>= "4.03"} 10 | "dune" {>= "1.0"} 11 | "base-unix" 12 | ] 13 | build: [ 14 | ["dune" "subst"] {pinned} 15 | ["dune" "build" "-p" name "-j" jobs] 16 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 17 | ] 18 | dev-repo: "git+https://github.com/ocaml-community/cppo.git" 19 | synopsis: "Code preprocessor like cpp for OCaml" 20 | description: """ 21 | Cppo is an equivalent of the C preprocessor for OCaml programs. 22 | It allows the definition of simple macros and file inclusion. 23 | 24 | Cppo is: 25 | 26 | * more OCaml-friendly than cpp 27 | * easy to learn without consulting a manual 28 | * reasonably fast 29 | * simple to install and to maintain 30 | """ 31 | url { 32 | src: "https://github.com/ocaml-community/cppo/releases/download/v1.6.6/cppo-v1.6.6.tbz" 33 | checksum: [ 34 | "sha256=e7272996a7789175b87bb998efd079794a8db6625aae990d73f7b4484a07b8a0" 35 | "sha512=44ecf9d225d9e45490a2feac0bde04865ca398dba6c3579e3370fcd1ea255707b8883590852af8b2df87123801062b9f3acce2455c092deabf431f9c4fb8d8eb" 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /esy.lock/opam/luv.0.5.2/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | 3 | synopsis: "Binding to libuv: cross-platform asynchronous I/O" 4 | 5 | version: "0.5.2" 6 | license: "MIT" 7 | homepage: "https://github.com/aantron/luv" 8 | doc: "https://aantron.github.io/luv" 9 | bug-reports: "https://github.com/aantron/luv/issues" 10 | 11 | authors: "Anton Bachin " 12 | maintainer: "Anton Bachin " 13 | dev-repo: "git+https://github.com/aantron/luv.git" 14 | 15 | depends: [ 16 | "base-unix" {build} 17 | "ctypes" {>= "0.13.0"} 18 | "dune" {>= "2.0.0"} 19 | "ocaml" {>= "4.02.0"} 20 | "result" 21 | 22 | "alcotest" {with-test & >= "0.8.1"} 23 | "base-unix" {with-test} 24 | ] 25 | 26 | build: [ 27 | ["dune" "build" "-p" name "-j" jobs] 28 | ] 29 | 30 | description: "Luv is a binding to libuv, the cross-platform C library that does 31 | asynchronous I/O in Node.js and runs its main loop. 32 | 33 | Besides asynchronous I/O, libuv also supports multiprocessing and 34 | multithreading. Multiple event loops can be run in different threads. libuv also 35 | exposes a lot of other functionality, amounting to a full OS API, and an 36 | alternative to the standard module Unix." 37 | 38 | url { 39 | src: "https://github.com/aantron/luv/releases/download/0.5.2/luv-0.5.2.tar.gz" 40 | checksum: "md5=a196396b63bbe9ff9e8b932b58010b18" 41 | } 42 | -------------------------------------------------------------------------------- /esy.lock/opam/dune-private-libs.2.5.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "Private libraries of Dune" 3 | description: """ 4 | !!!!!!!!!!!!!!!!!!!!!! 5 | !!!!! DO NOT USE !!!!! 6 | !!!!!!!!!!!!!!!!!!!!!! 7 | 8 | This package contains code that is shared between various dune-xxx 9 | packages. However, it is not meant for public consumption and provides 10 | no stability guarantee. 11 | """ 12 | maintainer: ["Jane Street Group, LLC "] 13 | authors: ["Jane Street Group, LLC "] 14 | license: "MIT" 15 | homepage: "https://github.com/ocaml/dune" 16 | doc: "https://dune.readthedocs.io/" 17 | bug-reports: "https://github.com/ocaml/dune/issues" 18 | depends: [ 19 | "dune" {>= "2.3"} 20 | "ocaml" {>= "4.07"} 21 | ] 22 | dev-repo: "git+https://github.com/ocaml/dune.git" 23 | build: [ 24 | ["dune" "subst"] {pinned} 25 | [ 26 | "dune" 27 | "build" 28 | "-p" 29 | name 30 | "-j" 31 | jobs 32 | "@install" 33 | "@doc" {with-doc} 34 | ] 35 | ] 36 | url { 37 | src: "https://github.com/ocaml/dune/releases/download/2.5.1/dune-2.5.1.tbz" 38 | checksum: [ 39 | "sha256=8f77d3a87f208e0d7cccaa1c48c4bb1bb87d62d07c3f25e9b8ba298e028ce52b" 40 | "sha512=f209f12ced10c1abf8782bdb0143f4cec77795f7174d2cc75130afb1e01550b01f2f77b9e3ec4888efdad83d2f9878d179b39126f824f4e522f3ef4da34bf27e" 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /tests/native/Intersections.re: -------------------------------------------------------------------------------- 1 | open TestFramework; 2 | 3 | describe("intersection types", ({test, _}) => { 4 | test("can create simple intersection tuple", ({expect, _}) => { 5 | expect.string(print({| 6 | type tpl = string & number; 7 | |})). 8 | toMatchSnapshot() 9 | }); 10 | test("can create simple intersection tuple with references", ({expect, _}) => { 11 | expect.string( 12 | print( 13 | {| 14 | type num_opt = number | undefined 15 | type tpl = string & num_opt; 16 | |}, 17 | ), 18 | ). 19 | toMatchSnapshot() 20 | }); 21 | test("can create more complex intersection tuple", ({expect, _}) => { 22 | expect.string( 23 | print( 24 | {| 25 | interface ErrorHandling { 26 | success: boolean; 27 | error?: { message: string }; 28 | } 29 | 30 | interface ArtworksData { 31 | artworks: { title: string }[]; 32 | } 33 | 34 | interface ArtistsData { 35 | artists: { name: string }[]; 36 | } 37 | 38 | // These interfaces are composed to have 39 | // consistent error handling, and their own data. 40 | 41 | type ArtworksResponse = ArtworksData & ErrorHandling; 42 | type ArtistsResponse = ArtistsData & ErrorHandling; 43 | |}, 44 | ), 45 | ). 46 | toMatchSnapshot() 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /src/printer/ast_generator_utils.re: -------------------------------------------------------------------------------- 1 | open Migrate_parsetree; 2 | open Ast_406; 3 | open Parsetree; 4 | open Ast_helper; 5 | 6 | let generate_base_type = (~inner=[], name) => { 7 | Typ.constr(Location.mknoloc(Longident.parse(name)), inner); 8 | }; 9 | 10 | let generate_record_kind = 11 | (fields: list((string, core_type, list(attribute)))) => 12 | Ptype_record( 13 | fields 14 | |> List.map(((name, type_, attrs)) => 15 | Type.field(~attrs, Location.mknoloc(name), type_) 16 | ), 17 | ); 18 | 19 | let generate_array_of = wrap_type => { 20 | generate_base_type(~inner=[wrap_type], "array"); 21 | }; 22 | 23 | let generate_list_of = wrap_type => { 24 | generate_base_type(~inner=[wrap_type], "list"); 25 | }; 26 | 27 | let generate_option_of = wrap_type => { 28 | generate_base_type(~inner=[wrap_type], "option"); 29 | }; 30 | 31 | let generate_tuple_of = types => { 32 | Typ.tuple(types); 33 | }; 34 | 35 | let generate_variant_kind = (names: list(string)) => { 36 | Ptype_variant( 37 | names 38 | |> CCListLabels.map(~f=name => Type.constructor(Location.mknoloc(name))), 39 | ); 40 | }; 41 | 42 | let generate_poly_variant = (names: list(string)) => { 43 | Typ.variant( 44 | names 45 | |> CCListLabels.map(~f=name => 46 | Rtag(Location.mknoloc(name), [], false, []) 47 | ), 48 | Closed, 49 | None, 50 | ); 51 | }; 52 | -------------------------------------------------------------------------------- /tests/native/TestFramework.re: -------------------------------------------------------------------------------- 1 | include Rely.Make({ 2 | let config = 3 | Rely.TestFrameworkConfig.initialize({ 4 | snapshotDir: "tests/native/__snapshots__", 5 | projectDir: "src", 6 | }); 7 | }); 8 | 9 | open Re_typescript_base; 10 | open Re_typescript_fs; 11 | module Exceptions = Re_typescript_printer.Tree_utils.Exceptions; 12 | 13 | type x = {x: Hashtbl.t(Fp.t(Fp.absolute), string)}; 14 | let x = {x: Hashtbl.create(0)}; 15 | let test_loader: module Loader.T = 16 | (module 17 | Loader_virtual.Make({ 18 | let tbl = x.x; 19 | })); 20 | let test_resolver: module Resolver.T = 21 | (module 22 | Resolver.Make({ 23 | let config = {Resolver.loader: test_loader, tsconfig: None}; 24 | })); 25 | let test_path = Fp.absoluteExn("/test_framework.d.ts"); 26 | 27 | let config = Re_typescript_config.default_config; 28 | let print = (~ctx=config, value) => { 29 | Hashtbl.replace(x.x, test_path, value); 30 | 31 | let str = 32 | Re_typescript_printer.structure_from_ts( 33 | ~ctx, 34 | ~parser= 35 | content => 36 | Ok( 37 | Parser_incr.parse(Lexing.from_string(content |> CCString.trim)), 38 | ), 39 | ~resolver=test_resolver, 40 | test_path, 41 | ); 42 | Reason_toolchain.RE.print_implementation_with_comments( 43 | Format.str_formatter, 44 | (str, []), 45 | ); 46 | Format.flush_str_formatter(); 47 | }; 48 | -------------------------------------------------------------------------------- /esy.lock/opam/yojson.1.7.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "martin@mjambon.com" 3 | authors: ["Martin Jambon"] 4 | homepage: "https://github.com/ocaml-community/yojson" 5 | bug-reports: "https://github.com/ocaml-community/yojson/issues" 6 | dev-repo: "git+https://github.com/ocaml-community/yojson.git" 7 | doc: "https://ocaml-community.github.io/yojson/" 8 | build: [ 9 | ["dune" "subst"] {pinned} 10 | ["dune" "build" "-p" name "-j" jobs] 11 | ] 12 | run-test: [["dune" "runtest" "-p" name "-j" jobs]] 13 | depends: [ 14 | "ocaml" {>= "4.02.3"} 15 | "dune" 16 | "cppo" {build} 17 | "easy-format" 18 | "biniou" {>= "1.2.0"} 19 | "alcotest" {with-test & >= "0.8.5"} 20 | ] 21 | synopsis: 22 | "Yojson is an optimized parsing and printing library for the JSON format" 23 | description: """ 24 | Yojson is an optimized parsing and printing library for the JSON format. 25 | 26 | It addresses a few shortcomings of json-wheel including 2x speedup, 27 | polymorphic variants and optional syntax for tuples and variants. 28 | 29 | ydump is a pretty-printing command-line program provided with the 30 | yojson package. 31 | 32 | The program atdgen can be used to derive OCaml-JSON serializers and 33 | deserializers from type definitions.""" 34 | url { 35 | src: 36 | "https://github.com/ocaml-community/yojson/releases/download/1.7.0/yojson-1.7.0.tbz" 37 | checksum: "md5=b89d39ca3f8c532abe5f547ad3b8f84d" 38 | } 39 | -------------------------------------------------------------------------------- /esy.lock/opam/js_of_ocaml-compiler.3.6.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "dev@ocsigen.org" 3 | authors: "Ocsigen team" 4 | bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" 5 | homepage: "http://ocsigen.github.io/js_of_ocaml" 6 | dev-repo: "git+https://github.com/ocsigen/js_of_ocaml.git" 7 | synopsis: "Compiler from OCaml bytecode to Javascript" 8 | description: """ 9 | Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. 10 | It makes it possible to run pure OCaml programs in JavaScript 11 | environment like browsers and Node.js 12 | """ 13 | 14 | build: [["dune" "build" "-p" name "-j" jobs]] 15 | 16 | depends: [ 17 | "ocaml" {>= "4.02.0" & < "4.11"} 18 | "dune" {>= "2.5"} 19 | "ppx_expect" {with-test & >= "v0.12.0" & < "v0.14"} 20 | "cmdliner" 21 | "ocaml-migrate-parsetree" 22 | "yojson" # It's optional, but we want users to be able to use source-map without pain. 23 | ] 24 | 25 | depopts: [ "ocamlfind" ] 26 | 27 | conflicts: [ 28 | "ocamlfind" {< "1.5.1"} 29 | "js_of_ocaml" {< "3.0"} 30 | ] 31 | url { 32 | src: 33 | "https://github.com/ocsigen/js_of_ocaml/releases/download/3.6.0/js_of_ocaml-3.6.0.tbz" 34 | checksum: [ 35 | "sha256=51eaa89c83ef3168ef270bf7997cbc35a747936d3f51aa6fac58fb0323b4cbb0" 36 | "sha512=a2171a2583e9a1be6b4a87c9958aa2b4936b1f19030f09d787c4824d04db864773dd1da10d0dd56822f279309c8217093552b94e2e93c8b01eba5f432afc7718" 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /esy.lock/opam/containers.2.8.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "simon.cruanes.2007@m4x.org" 3 | synopsis: "A modular, clean and powerful extension of the OCaml standard library" 4 | build: [ 5 | ["dune" "build" "-p" name "-j" jobs] 6 | ["dune" "build" "@doc" "-p" name ] {with-doc} 7 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 8 | ] 9 | depends: [ 10 | "ocaml" { >= "4.03.0" } 11 | "dune" { >= "1.1" } 12 | "dune-configurator" 13 | "seq" 14 | "qtest" { with-test } 15 | "qcheck" { with-test } 16 | "ounit" { with-test } 17 | "iter" { with-test } 18 | "gen" { with-test } 19 | "uutf" { with-test } 20 | "mdx" { with-test & >= "1.5.0" & < "2.0.0" } 21 | "odoc" { with-doc } 22 | ] 23 | depopts: [ 24 | "base-unix" 25 | "base-threads" 26 | ] 27 | tags: [ "stdlib" "containers" "iterators" "list" "heap" "queue" ] 28 | homepage: "https://github.com/c-cube/ocaml-containers/" 29 | doc: "https://c-cube.github.io/ocaml-containers" 30 | dev-repo: "git+https://github.com/c-cube/ocaml-containers.git" 31 | bug-reports: "https://github.com/c-cube/ocaml-containers/issues/" 32 | authors: "Simon Cruanes" 33 | url { 34 | src: "https://github.com/c-cube/ocaml-containers/archive/v2.8.1.tar.gz" 35 | checksum: [ 36 | "md5=d84e09c5d0abc501aa17cd502e31a038" 37 | "sha512=8b832f4ada6035e80d81be0cfb7bdffb695ec67d465ed6097a144019e2b8a8f909095e78019c3da2d8181cc3cd730cd48f7519e87d3162442562103b7f36aabb" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /src/config/bridge.atd: -------------------------------------------------------------------------------- 1 | type config = abstract 2 | type position = abstract 3 | 4 | type parse_language = [ 5 | | Reason 6 | | Ocaml 7 | ] 8 | type parse_request = { 9 | language: parse_language; 10 | content: string option; 11 | config: config; 12 | file_path: string; 13 | } 14 | 15 | type parse_result = [ 16 | | Error of (parse_error_kind * string) 17 | | Ok of (string * string option) 18 | ] 19 | 20 | type parse_error_kind = [ 21 | | Parser_unexpected 22 | | Parser_error 23 | | Parser_parameter_error 24 | | Parser_unsupported of position 25 | | Optimizer_error 26 | | Reason_error 27 | | Syntax_error 28 | | Base_parser_error 29 | | Base_lexer_error 30 | | Js_unknown 31 | ] 32 | 33 | type example_meta = { 34 | name: string; 35 | description: string; 36 | entry: string; 37 | } 38 | 39 | type example_tree = [ 40 | | Folder of (string * example_tree list) 41 | | File of string 42 | ] 43 | 44 | type example = { 45 | path: string; 46 | meta: example_meta; 47 | files: example_tree list; 48 | } 49 | type example_list = example list 50 | 51 | type worker_request = [ 52 | | Parse of parse_request 53 | | ExampleList 54 | ] 55 | 56 | type worker_response = [ 57 | | Res_Parse of parse_result 58 | | Res_ExampleList of example_list 59 | ] -------------------------------------------------------------------------------- /esy.lock/opam/dune-build-info.2.5.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "Embed build informations inside executable" 3 | description: """ 4 | The build-info library allows to access information about how the 5 | executable was built, such as the version of the project at which it 6 | was built or the list of statically linked libraries with their 7 | versions. It supports reporting the version from the version control 8 | system during development to get an precise reference of when the 9 | executable was built. 10 | """ 11 | maintainer: ["Jane Street Group, LLC "] 12 | authors: ["Jane Street Group, LLC "] 13 | license: "MIT" 14 | homepage: "https://github.com/ocaml/dune" 15 | doc: "https://dune.readthedocs.io/" 16 | bug-reports: "https://github.com/ocaml/dune/issues" 17 | depends: [ 18 | "dune" {>= "2.3"} 19 | ] 20 | dev-repo: "git+https://github.com/ocaml/dune.git" 21 | build: [ 22 | ["dune" "subst"] {pinned} 23 | [ 24 | "dune" 25 | "build" 26 | "-p" 27 | name 28 | "-j" 29 | jobs 30 | "@install" 31 | "@doc" {with-doc} 32 | ] 33 | ] 34 | url { 35 | src: "https://github.com/ocaml/dune/releases/download/2.5.1/dune-2.5.1.tbz" 36 | checksum: [ 37 | "sha256=8f77d3a87f208e0d7cccaa1c48c4bb1bb87d62d07c3f25e9b8ba298e028ce52b" 38 | "sha512=f209f12ced10c1abf8782bdb0143f4cec77795f7174d2cc75130afb1e01550b01f2f77b9e3ec4888efdad83d2f9878d179b39126f824f4e522f3ef4da34bf27e" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /esy.lock/opam/dune-configurator.2.5.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "Helper library for gathering system configuration" 3 | description: """ 4 | dune-configurator is a small library that helps writing OCaml scripts that 5 | test features available on the system, in order to generate config.h 6 | files for instance. 7 | Among other things, dune-configurator allows one to: 8 | - test if a C program compiles 9 | - query pkg-config 10 | - import #define from OCaml header files 11 | - generate config.h file 12 | """ 13 | maintainer: ["Jane Street Group, LLC "] 14 | authors: ["Jane Street Group, LLC "] 15 | license: "MIT" 16 | homepage: "https://github.com/ocaml/dune" 17 | doc: "https://dune.readthedocs.io/" 18 | bug-reports: "https://github.com/ocaml/dune/issues" 19 | depends: [ 20 | "dune" {>= "2.3"} 21 | "dune-private-libs" {= version} 22 | ] 23 | dev-repo: "git+https://github.com/ocaml/dune.git" 24 | build: [ 25 | ["dune" "subst"] {pinned} 26 | [ 27 | "dune" 28 | "build" 29 | "-p" 30 | name 31 | "-j" 32 | jobs 33 | "@install" 34 | "@doc" {with-doc} 35 | ] 36 | ] 37 | url { 38 | src: "https://github.com/ocaml/dune/releases/download/2.5.1/dune-2.5.1.tbz" 39 | checksum: [ 40 | "sha256=8f77d3a87f208e0d7cccaa1c48c4bb1bb87d62d07c3f25e9b8ba298e028ce52b" 41 | "sha512=f209f12ced10c1abf8782bdb0143f4cec77795f7174d2cc75130afb1e01550b01f2f77b9e3ec4888efdad83d2f9878d179b39126f824f4e522f3ef4da34bf27e" 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /tests/native/Tuples.re: -------------------------------------------------------------------------------- 1 | include TestFramework; 2 | 3 | describe("tuples", ({test, _}) => { 4 | test("generates base type tuple", ({expect, _}) => { 5 | expect.string( 6 | print({| 7 | type tpl = [string, number, boolean]; 8 | |}), 9 | ). 10 | toMatchSnapshot() 11 | }); 12 | 13 | test("can use tuple inside of an interface", ({expect, _}) => { 14 | expect.string( 15 | print( 16 | {| 17 | interface obj { 18 | field: [string, number, boolean]; 19 | } 20 | |}, 21 | ), 22 | ). 23 | toMatchSnapshot() 24 | }); 25 | 26 | test("can generate an array of tuples", ({expect, _}) => { 27 | expect.string( 28 | print( 29 | {| 30 | type tpl_arr = [string, number, boolean][]; 31 | type tpl_arr2 = Array<[string, number, boolean]>; 32 | |}, 33 | ), 34 | ). 35 | toMatchSnapshot() 36 | }); 37 | 38 | test("can use inline interfaces", ({expect, _}) => { 39 | expect.string( 40 | print( 41 | {| 42 | type tpl = [string, number, { field: boolean }]; 43 | |}, 44 | ), 45 | ). 46 | toMatchSnapshot() 47 | }); 48 | 49 | test("merges extracted tuple members back if possible", ({expect, _}) => { 50 | expect.string( 51 | print( 52 | {| 53 | type tpl = [ string, [ number, boolean ] ]; 54 | |}, 55 | ), 56 | ). 57 | toMatchSnapshot() 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /esy.lock/opam/ocaml-migrate-parsetree.1.7.3/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "frederic.bour@lakaban.net" 3 | authors: [ 4 | "Frédéric Bour " 5 | "Jérémie Dimino " 6 | ] 7 | license: "LGPL-2.1 with OCaml linking exception" 8 | homepage: "https://github.com/ocaml-ppx/ocaml-migrate-parsetree" 9 | bug-reports: "https://github.com/ocaml-ppx/ocaml-migrate-parsetree/issues" 10 | dev-repo: "git+https://github.com/ocaml-ppx/ocaml-migrate-parsetree.git" 11 | doc: "https://ocaml-ppx.github.io/ocaml-migrate-parsetree/" 12 | tags: [ "syntax" "org:ocamllabs" ] 13 | build: [ 14 | ["dune" "build" "-p" name "-j" jobs] 15 | ] 16 | depends: [ 17 | "result" 18 | "ppx_derivers" 19 | "dune" {>= "1.9.0"} 20 | "ocaml" {>= "4.02.3" & < "4.12"} 21 | ] 22 | synopsis: "Convert OCaml parsetrees between different versions" 23 | description: """ 24 | Convert OCaml parsetrees between different versions 25 | 26 | This library converts parsetrees, outcometree and ast mappers between 27 | different OCaml versions. High-level functions help making PPX 28 | rewriters independent of a compiler version. 29 | """ 30 | url { 31 | src: 32 | "https://github.com/ocaml-ppx/ocaml-migrate-parsetree/releases/download/v1.7.3/ocaml-migrate-parsetree-v1.7.3.tbz" 33 | checksum: [ 34 | "sha256=6d85717bcf476b87f290714872ed4fbde0233dc899c3158a27f439d70224fb55" 35 | "sha512=fe9c74a244d160d973d8ca62e356edad4c872fc46471ddc668f854456d3979576895d446d49da2aee61c65b441b72c573225b0b254ab2eac4a0fb4debdbce9d4" 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /src/printer/re_typescript_printer.re: -------------------------------------------------------------------------------- 1 | open Migrate_parsetree; 2 | open Re_typescript_config.Config; 3 | 4 | module Tree_utils = Tree_utils; 5 | 6 | let get_generator: (~ctx: config) => (module Ast_generator.T) = 7 | (~ctx: config) => 8 | switch (ctx.output_type) { 9 | | Bucklescript 10 | | BucklescriptBindings => 11 | (module 12 | Ast_generator_bucklescript.Make({ 13 | let config = ctx.bucklescript_config; 14 | })) 15 | | Native => (module Ast_generator_native) 16 | }; 17 | 18 | let structure_from_ts = 19 | ( 20 | ~ctx: config, 21 | ~resolver: (module Re_typescript_fs.Resolver.T), 22 | ~parser: 23 | string => 24 | CCResult.t(list(Re_typescript_base.Ts.declaration), string), 25 | entry: Fp.t(Fp.absolute), 26 | ) => { 27 | module Generator = (val get_generator(~ctx): Ast_generator.T); 28 | let ast = 29 | Generator.generate( 30 | ~ctx, 31 | Tree_parse.parse__entry(~ctx, ~resolver, ~parser, entry), 32 | ); 33 | let migration = 34 | Versions.migrate(Versions.ocaml_406, Versions.ocaml_current); 35 | 36 | migration.copy_structure(ast); 37 | }; 38 | let print_from_ts = 39 | ( 40 | ~ctx: config, 41 | ~resolver: (module Re_typescript_fs.Resolver.T), 42 | ~parser: 43 | string => 44 | CCResult.t(list(Re_typescript_base.Ts.declaration), string), 45 | entry: Fp.t(Fp.absolute), 46 | ) => { 47 | Pprintast.string_of_structure( 48 | structure_from_ts(~ctx, ~resolver, ~parser, entry), 49 | ); 50 | }; 51 | -------------------------------------------------------------------------------- /esy.lock/opam/uutf.1.0.2/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Daniel Bünzli " 3 | authors: ["Daniel Bünzli "] 4 | homepage: "http://erratique.ch/software/uutf" 5 | doc: "http://erratique.ch/software/uutf/doc/Uutf" 6 | dev-repo: "git+http://erratique.ch/repos/uutf.git" 7 | bug-reports: "https://github.com/dbuenzli/uutf/issues" 8 | tags: [ "unicode" "text" "utf-8" "utf-16" "codec" "org:erratique" ] 9 | license: "ISC" 10 | depends: [ 11 | "ocaml" {>= "4.01.0"} 12 | "ocamlfind" {build} 13 | "ocamlbuild" {build} 14 | "topkg" {build} 15 | "uchar" 16 | ] 17 | depopts: ["cmdliner"] 18 | conflicts: ["cmdliner" { < "0.9.6"} ] 19 | build: [[ 20 | "ocaml" "pkg/pkg.ml" "build" 21 | "--pinned" "%{pinned}%" 22 | "--with-cmdliner" "%{cmdliner:installed}%" ]] 23 | synopsis: """Non-blocking streaming Unicode codec for OCaml""" 24 | description: """\ 25 | 26 | Uutf is a non-blocking streaming codec to decode and encode the UTF-8, 27 | UTF-16, UTF-16LE and UTF-16BE encoding schemes. It can efficiently 28 | work character by character without blocking on IO. Decoders perform 29 | character position tracking and support newline normalization. 30 | 31 | Functions are also provided to fold over the characters of UTF encoded 32 | OCaml string values and to directly encode characters in OCaml 33 | Buffer.t values. 34 | 35 | Uutf has no dependency and is distributed under the ISC license. 36 | """ 37 | url { 38 | archive: "http://erratique.ch/software/uutf/releases/uutf-1.0.2.tbz" 39 | checksum: "a7c542405a39630c689a82bd7ef2292c" 40 | } 41 | -------------------------------------------------------------------------------- /esy.lock/opam/cmdliner.1.0.4/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Daniel Bünzli " 3 | authors: ["Daniel Bünzli "] 4 | homepage: "http://erratique.ch/software/cmdliner" 5 | doc: "http://erratique.ch/software/cmdliner/doc/Cmdliner" 6 | dev-repo: "git+http://erratique.ch/repos/cmdliner.git" 7 | bug-reports: "https://github.com/dbuenzli/cmdliner/issues" 8 | tags: [ "cli" "system" "declarative" "org:erratique" ] 9 | license: "ISC" 10 | depends:[ "ocaml" {>= "4.03.0"} ] 11 | build: [[ make "all" "PREFIX=%{prefix}%" ]] 12 | install: 13 | [[make "install" "LIBDIR=%{_:lib}%" "DOCDIR=%{_:doc}%" ] 14 | [make "install-doc" "LIBDIR=%{_:lib}%" "DOCDIR=%{_:doc}%" ]] 15 | 16 | synopsis: """Declarative definition of command line interfaces for OCaml""" 17 | description: """\ 18 | 19 | Cmdliner allows the declarative definition of command line interfaces 20 | for OCaml. 21 | 22 | It provides a simple and compositional mechanism to convert command 23 | line arguments to OCaml values and pass them to your functions. The 24 | module automatically handles syntax errors, help messages and UNIX man 25 | page generation. It supports programs with single or multiple commands 26 | and respects most of the [POSIX][1] and [GNU][2] conventions. 27 | 28 | Cmdliner has no dependencies and is distributed under the ISC license. 29 | 30 | [1]: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html 31 | [2]: http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html 32 | """ 33 | url { 34 | archive: "http://erratique.ch/software/cmdliner/releases/cmdliner-1.0.4.tbz" 35 | checksum: "fe2213d0bc63b1e10a2d0aa66d2fc8d9" 36 | } 37 | -------------------------------------------------------------------------------- /src/config/config.atd: -------------------------------------------------------------------------------- 1 | type bucklescript_config = { 2 | string_variant_mode: string_variant_mode; 3 | number_variant_mode: number_variant_mode; 4 | mixed_variant_mode: mixed_variant_mode; 5 | union_mode: union_mode; 6 | } 7 | type string_variant_mode = [ Variant | PolyVariant | BsInline ] 8 | type number_variant_mode = [ Variant of number_variant_mode_name option 9 | | PolyVariant of number_variant_mode_name option 10 | | BsInline of number_variant_mode_name option 11 | ] 12 | type mixed_variant_mode = [ BsUnboxed | Variant | PolyVariant ] 13 | type number_variant_mode_name = { 14 | prefix: string; 15 | suffix: string; 16 | } 17 | type union_mode = [ ExtractLiterals | KeepLiterals ] 18 | type output_type = [ 19 | | BucklescriptBindings 20 | | Bucklescript 21 | | Native 22 | ] 23 | type array_mode = [ 24 | | List 25 | | Array 26 | ] 27 | type number_mode = [ 28 | | Int 29 | | Float 30 | | Unboxed 31 | ] 32 | type intersection_def = [ 33 | | Merge 34 | | Tuple 35 | | Ignore 36 | ] 37 | 38 | type intersection_mode = { 39 | objects: intersection_def; 40 | unions: intersection_def; 41 | classes: intersection_def; 42 | functions: intersection_def; 43 | other: intersection_def; 44 | tuple_members_optional: bool; 45 | } 46 | 47 | type config = { 48 | suppress_warning_for_extended_records: bool; 49 | omit_extended_unreferenced_records: bool; 50 | output_type: output_type; 51 | bucklescript_config: bucklescript_config; 52 | array_mode: array_mode; 53 | intersection_mode: intersection_mode; 54 | number_mode: number_mode; 55 | generate_parser: bool; 56 | generate_serializer: bool; 57 | } -------------------------------------------------------------------------------- /esy.lock/opam/ocamlfind.1.8.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "A library manager for OCaml" 3 | maintainer: "Thomas Gazagnaire " 4 | authors: "Gerd Stolpmann " 5 | homepage: "http://projects.camlcity.org/projects/findlib.html" 6 | bug-reports: "https://gitlab.camlcity.org/gerd/lib-findlib/issues" 7 | dev-repo: "git+https://gitlab.camlcity.org/gerd/lib-findlib.git" 8 | description: """ 9 | Findlib is a library manager for OCaml. It provides a convention how 10 | to store libraries, and a file format ("META") to describe the 11 | properties of libraries. There is also a tool (ocamlfind) for 12 | interpreting the META files, so that it is very easy to use libraries 13 | in programs and scripts. 14 | """ 15 | build: [ 16 | [ 17 | "./configure" 18 | "-bindir" 19 | bin 20 | "-sitelib" 21 | lib 22 | "-mandir" 23 | man 24 | "-config" 25 | "%{lib}%/findlib.conf" 26 | "-no-custom" 27 | "-no-camlp4" {!ocaml:preinstalled & ocaml:version >= "4.02.0"} 28 | "-no-topfind" {ocaml:preinstalled} 29 | ] 30 | [make "all"] 31 | [make "opt"] {ocaml:native} 32 | ] 33 | install: [ 34 | [make "install"] 35 | ["install" "-m" "0755" "ocaml-stub" "%{bin}%/ocaml"] {ocaml:preinstalled} 36 | ] 37 | depends: [ 38 | "ocaml" {>= "4.00.0"} 39 | "conf-m4" {build} 40 | ] 41 | extra-files: [ 42 | ["ocamlfind.install" "md5=06f2c282ab52d93aa6adeeadd82a2543"] 43 | ["ocaml-stub" "md5=181f259c9e0bad9ef523e7d4abfdf87a"] 44 | ] 45 | url { 46 | src: "http://download.camlcity.org/download/findlib-1.8.1.tar.gz" 47 | checksum: "md5=18ca650982c15536616dea0e422cbd8c" 48 | mirrors: "http://download2.camlcity.org/download/findlib-1.8.1.tar.gz" 49 | } 50 | depopts: ["graphics"] 51 | -------------------------------------------------------------------------------- /esy.lock/opam/tyxml.4.4.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "dev@ocsigen.org" 3 | homepage: "https://github.com/ocsigen/tyxml/" 4 | bug-reports: "https://github.com/ocsigen/tyxml/issues" 5 | doc: "https://ocsigen.org/tyxml/manual/" 6 | dev-repo: "git+https://github.com/ocsigen/tyxml.git" 7 | license: "LGPL-2.1 with OCaml linking exception" 8 | 9 | build: [ 10 | ["dune" "subst"] {pinned} 11 | ["dune" "build" "-p" name "-j" jobs] 12 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 13 | ] 14 | 15 | depends: [ 16 | "ocaml" {>= "4.02"} 17 | "dune" 18 | "alcotest" {with-test} 19 | "seq" 20 | "uutf" {>= "1.0.0"} 21 | "re" {>= "1.5.0"} 22 | ] 23 | 24 | synopsis:"TyXML is a library for building correct HTML and SVG documents" 25 | description:""" 26 | TyXML provides a set of convenient combinators that uses the OCaml 27 | type system to ensure the validity of the generated documents. TyXML 28 | can be used with any representation of HTML and SVG: the textual one, 29 | provided directly by this package, or DOM trees (`js_of_ocaml-tyxml`) 30 | virtual DOM (`virtual-dom`) and reactive or replicated trees 31 | (`eliom`). You can also create your own representation and use it to 32 | instantiate a new set of combinators. 33 | 34 | ```ocaml 35 | open Tyxml 36 | let to_ocaml = Html.(a ~a:[a_href "ocaml.org"] [txt "OCaml!"]) 37 | ``` 38 | """ 39 | authors: "The ocsigen team" 40 | url { 41 | src: 42 | "https://github.com/ocsigen/tyxml/releases/download/4.4.0/tyxml-4.4.0.tbz" 43 | checksum: [ 44 | "sha256=516394dd4a5c31726997c51d66aa31cacb91e3c46d4e16c7699130e204042530" 45 | "sha512=d5f2187f8410524cec7a14b28e8950837070eb0b6571b015dd06076c2841eb7ccaffa86d5d2307eaf1950ee62f9fb926477dac01c870d9c1a2f525853cb44d0c" 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /src_js/Layout.re: -------------------------------------------------------------------------------- 1 | module Styles = { 2 | let container = [%css 3 | {| 4 | width: 100vw; 5 | height: 100vh; 6 | position: relative; 7 | display: flex; 8 | flex-direction: column; 9 | |} 10 | ]; 11 | let header = [%css {| 12 | width: 100vw; 13 | height: 65px; 14 | |}]; 15 | 16 | let panelheight = "calc(100vh - 65px)"; 17 | let panelContainer = [%css 18 | {j| 19 | width: 100vw; 20 | height: $panelheight; 21 | display: flex; 22 | flex-direction: row; 23 | |j} 24 | ]; 25 | let panelEditor = [%css 26 | {j| 27 | width: 50vw; 28 | height: $panelheight; 29 | position: relative; 30 | |j} 31 | ]; 32 | let panelPreview = [%css 33 | {j| 34 | width: 50vw; 35 | height: $panelheight; 36 | position: relative; 37 | |j} 38 | ]; 39 | }; 40 | 41 | module PreviewLabel = { 42 | [@react.component] 43 | let make = () => { 44 | let lang = Recoil.useRecoilValue(State.language); 45 | 46 | SemanticUi.( 47 | 59 | ); 60 | }; 61 | }; 62 | 63 | [@react.component] 64 | let make = () => { 65 |
66 |
67 | 68 |
69 |
70 |
71 |
72 |
73 |
; 74 | }; -------------------------------------------------------------------------------- /esy.lock/opam/conf-pkg-config.1.2/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "unixjunkie@sdf.org" 3 | authors: ["Francois Berenger"] 4 | homepage: "http://www.freedesktop.org/wiki/Software/pkg-config/" 5 | bug-reports: "https://github.com/ocaml/opam-repository/issues" 6 | license: "GPL-1.0-or-later" 7 | build: [ 8 | ["pkg-config" "--help"] 9 | ] 10 | install: [ 11 | ["ln" "-s" "/usr/local/bin/pkgconf" "%{bin}%/pkg-config"] {os = "openbsd"} 12 | ] 13 | remove: [ 14 | ["rm" "-f" "%{bin}%/pkg-config"] {os = "openbsd"} 15 | ] 16 | post-messages: [ 17 | "conf-pkg-config: A symlink to /usr/local/bin/pkgconf has been installed in the OPAM bin directory (%{bin}%) on your PATH as 'pkg-config'. This is necessary for correct operation." {os = "openbsd"} 18 | ] 19 | depexts: [ 20 | ["pkg-config"] {os-family = "debian"} 21 | ["pkgconf"] {os-distribution = "arch"} 22 | ["pkgconfig"] {os-distribution = "fedora"} 23 | ["pkgconfig"] {os-distribution = "centos" & os-version <= "7"} 24 | ["pkgconfig"] {os-distribution = "mageia"} 25 | ["pkgconfig"] {os-distribution = "rhel" & os-version <= "7"} 26 | ["pkgconfig"] {os-distribution = "ol"} 27 | ["pkgconf"] {os-distribution = "alpine"} 28 | ["pkgconfig"] {os-distribution = "nixos"} 29 | ["devel/pkgconf"] {os = "openbsd"} 30 | ["pkg-config"] {os = "macos" & os-distribution = "homebrew"} 31 | ["pkgconf"] {os = "freebsd"} 32 | ["pkgconf-pkg-config"] {os-distribution = "rhel" & os-version >= "8"} 33 | ["pkgconf-pkg-config"] {os-distribution = "centos" & os-version >= "8"} 34 | ["pkg-config"] {os-distribution = "cygwinports"} 35 | ] 36 | synopsis: "Virtual package relying on pkg-config installation" 37 | description: """ 38 | This package can only install if the pkg-config package is installed 39 | on the system.""" 40 | flags: conf 41 | -------------------------------------------------------------------------------- /src/base/error.re: -------------------------------------------------------------------------------- 1 | module FCP = 2 | FileContextPrinter.Make({ 3 | let config = 4 | FileContextPrinter.Config.initialize({linesBefore: 1, linesAfter: 3}); 5 | }); 6 | 7 | let print_error = (~msg=?, ~content, highlight) => { 8 | let location = 9 | FCP.print( 10 | content |> CCString.trim |> CCString.split(~by="\n"), 11 | ~highlight, 12 | ); 13 | Pastel.( 14 | 15 | "\n" 16 | "ReTypescript Error\n" 17 | 18 | "----------------------------------------------------" 19 | 20 | 21 | "\n" 22 | location 23 | "\n" 24 | 25 | 26 | "----------------------------------------------------" 27 | 28 | 29 | {Printf.sprintf( 30 | "\n%s\n", 31 | msg 32 | |> CCOpt.value( 33 | ~default="Check your input at the corresponding position", 34 | ), 35 | )} 36 | 37 | 38 | ); 39 | }; 40 | 41 | let parser_error_with_info = (~msg=?, ~content, pos: Parse_info.t) => { 42 | print_error( 43 | ~msg?, 44 | ~content, 45 | ((pos.line, pos.col + 1), (pos.line, pos.col + pos.idx + 1)), 46 | ); 47 | }; 48 | 49 | let parser_error = 50 | (~msg=?, ~content, ~start: Lexing.position, ~end_: Lexing.position) => { 51 | print_error( 52 | ~msg?, 53 | ~content, 54 | ( 55 | (start.pos_lnum, start.pos_cnum - start.pos_bol + 1), 56 | (end_.pos_lnum, end_.pos_cnum - end_.pos_bol + 1), 57 | ), 58 | ); 59 | }; 60 | -------------------------------------------------------------------------------- /esy.lock/opam/atdgen-runtime.2.2.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "Runtime library for code generated by atdgen" 3 | description: """ 4 | This package should be used only in conjunction with the stdgen code 5 | generator""" 6 | maintainer: ["Rudi Grinberg "] 7 | authors: [ 8 | "Martin Jambon " 9 | "David Sheets " 10 | "Rudi Grinberg " 11 | "Ivan Jager " 12 | "Jeff Meister " 13 | "Carmelo Piccione " 14 | "Raman Varabets " 15 | "Mathieu Baudet " 16 | "Rauan Mayemir " 17 | "Louis Roché " 18 | "Brendan Long " 19 | "Christophe Troestler " 20 | "Vincent Bernardoff " 21 | "haoyang " 22 | ] 23 | license: "MIT" 24 | homepage: "https://github.com/ahrefs/atd" 25 | bug-reports: "https://github.com/ahrefs/atd/issues" 26 | depends: [ 27 | "ocaml" {>= "4.02"} 28 | "dune" {>= "2.0"} 29 | "yojson" {>= "1.7.0"} 30 | "biniou" {>= "1.0.6"} 31 | "re" 32 | ] 33 | dev-repo: "git+https://github.com/ahrefs/atd.git" 34 | build: [ 35 | ["dune" "subst"] {pinned} 36 | [ 37 | "dune" 38 | "build" 39 | "-p" 40 | name 41 | "-j" 42 | jobs 43 | "@install" 44 | "@doc" {with-doc} 45 | ] 46 | ] 47 | url { 48 | src: "https://github.com/ahrefs/atd/releases/download/2.2.1/atd-2.2.1.tbz" 49 | checksum: [ 50 | "sha256=db6b4c1a6293b214a7b7a3da435e681abd1b16b55d5aa246b93d26736d3a559e" 51 | "sha512=0c7f1985cc4d87ddd541bb2f7085b72f81aaef69468653319a4a52e6cd6c9318511229784a12cdb413ae500e7a5b8195759e0d8d49946a9b00f62e8dda07e8a2" 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /esy.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "re_typescript", 3 | "description": "", 4 | "scripts": { 5 | "format": "dune build @fmt --auto-promote --root .", 6 | "run": "esy x Re_typescript", 7 | "watch": "esy x redemon --paths=src --extensions=re,atd,mll,mly esy x Re_typescript", 8 | "watch-test": "esy x redemon --paths=tests,src --extensions=re,atd,mll,mly esy x RunTests.exe", 9 | "test": "esy x RunTests.exe", 10 | "test-u": "esy x RunTests.exe -u", 11 | "js": "esy dune build ./src/js/re_typescript_js.bc.js", 12 | "js-release": "esy dune build ./src/js/re_typescript_js.bc.js --profile release-static", 13 | "release-static": "dune build --root . --only-packages '#{self.name}' --ignore-promoted-rules --no-config --profile release-static" 14 | }, 15 | "dependencies": { 16 | "@opam/atdgen": "2.2.1", 17 | "@opam/containers": "2.8.1", 18 | "@opam/dune": "*", 19 | "@opam/js_of_ocaml": "3.6.0", 20 | "@opam/js_of_ocaml-ppx": "3.6.0", 21 | "@opam/menhir": "*", 22 | "@opam/ocaml-migrate-parsetree": "*", 23 | "@opam/ppx_tools_versioned": "*", 24 | "@reason-native/console": "^0.1.0", 25 | "@reason-native/file-context-printer": "^0.0.3", 26 | "@reason-native/fp": "^0.0.1", 27 | "@reason-native/pastel": "^0.3.0" 28 | }, 29 | "devDependencies": { 30 | "@opam/reason": ">=3.6.0", 31 | "ocaml": "~4.8.0", 32 | "@opam/js_of_ocaml-compiler": "3.6.0", 33 | "refmterr": "~3.3.0", 34 | "@opam/ocaml-lsp-server": "ocaml/ocaml-lsp:ocaml-lsp-server.opam", 35 | "@opam/redemon": "ulrikstrid/redemon:redemon.opam", 36 | "@reason-native/rely": "^3.2.1" 37 | }, 38 | "esy": { 39 | "build": [ 40 | ["refmterr", "dune", "build", "--profile", "dev", "-p", "#{self.name}"] 41 | ], 42 | "buildsInSource": "_build" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "re-typescript", 3 | "version": "1.0.0", 4 | "main": "dist/index.html", 5 | "license": "MIT", 6 | "scripts": { 7 | "bs:build": "bsb -make-world", 8 | "bs:clean": "bsb -clean-world", 9 | "fpack": "./node_modules/.bin/fpack build --dev --mock constants:constants-browserify --mock fs --mock child_process --mock tty --preprocess='\\.css$:style-loader!css-loader' --preprocess='\\.(png|svg)$:url-loader'", 10 | "fpack-watch": "./node_modules/.bin/fpack watch --dev --mock constants:constants-browserify --mock fs --mock child_process --mock tty --preprocess='\\.css$:style-loader!css-loader' --preprocess='\\.(png|svg)$:url-loader'", 11 | "fpack-worker": "./node_modules/.bin/fpack build -c fastpack-worker.json --dev --mock constants:constants-browserify --mock fs --mock child_process --mock tty --preprocess='\\.css$:style-loader!css-loader'", 12 | "docs": "./docs.sh", 13 | "types": "./types.sh", 14 | "start": "cd docs; python -m SimpleHTTPServer" 15 | }, 16 | "devDependencies": { 17 | "bs-platform": "^7.3.2", 18 | "constants-browserify": "^1.0.0", 19 | "css-loader": "^3.5.3", 20 | "fastpack": "^0.9.1", 21 | "style-loader": "^1.2.1", 22 | "url-loader": "^4.1.0" 23 | }, 24 | "dependencies": { 25 | "@ahrefs/bs-atdgen-codec-runtime": "^2.0.1", 26 | "@ahrefs/bs-emotion": "^1.0.1", 27 | "@babel/runtime": "^7.9.6", 28 | "@davesnx/styled-ppx": "^0.19.0", 29 | "@monaco-editor/react": "^3.3.0", 30 | "babel-runtime": "^6.26.0", 31 | "bs-webworkers": "^0.2.4", 32 | "react": "^16.13.1", 33 | "react-dom": "^16.13.1", 34 | "react-syntax-highlighter": "^12.2.1", 35 | "reason-react": "^0.8.0", 36 | "reason-recoil": "^0.8.0", 37 | "recoil": "^0.0.8", 38 | "semantic-ui-react": "^0.88.2" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /esy.lock/opam/ptime.0.8.5/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Daniel Bünzli " 3 | authors: ["The ptime programmers"] 4 | homepage: "https://erratique.ch/software/ptime" 5 | doc: "https://erratique.ch/software/ptime/doc" 6 | dev-repo: "git+http://erratique.ch/repos/ptime.git" 7 | bug-reports: "https://github.com/dbuenzli/ptime/issues" 8 | tags: [ "time" "posix" "system" "org:erratique" ] 9 | license: "ISC" 10 | depends: [ 11 | "ocaml" {>= "4.01.0"} 12 | "ocamlfind" {build} 13 | "ocamlbuild" {build} 14 | "topkg" {build} 15 | "result" 16 | ] 17 | depopts: [ "js_of_ocaml" ] 18 | conflicts: [ "js_of_ocaml" { < "3.3.0" } ] 19 | build:[[ 20 | "ocaml" "pkg/pkg.ml" "build" 21 | "--pinned" "%{pinned}%" 22 | "--with-js_of_ocaml" "%{js_of_ocaml:installed}%" ]] 23 | 24 | synopsis: """POSIX time for OCaml""" 25 | description: """\ 26 | 27 | Ptime has platform independent POSIX time support in pure OCaml. It 28 | provides a type to represent a well-defined range of POSIX timestamps 29 | with picosecond precision, conversion with date-time values, 30 | conversion with [RFC 3339 timestamps][rfc3339] and pretty printing to a 31 | human-readable, locale-independent representation. 32 | 33 | The additional Ptime_clock library provides access to a system POSIX 34 | clock and to the system's current time zone offset. 35 | 36 | Ptime is not a calendar library. 37 | 38 | Ptime depends on the `result` compatibility package. Ptime_clock 39 | depends on your system library. Ptime_clock's optional JavaScript 40 | support depends on [js_of_ocaml][jsoo]. Ptime and its libraries are 41 | distributed under the ISC license. 42 | 43 | [rfc3339]: http://tools.ietf.org/html/rfc3339 44 | [jsoo]: http://ocsigen.org/js_of_ocaml/ 45 | """ 46 | url { 47 | archive: "https://erratique.ch/software/ptime/releases/ptime-0.8.5.tbz" 48 | checksum: "4d48055d623ecf2db792439b3e96a520" 49 | } 50 | -------------------------------------------------------------------------------- /esy.lock/opam/easy-format.1.3.2/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | build: [ 3 | ["dune" "subst"] {pinned} 4 | ["dune" "build" "-p" name "-j" jobs] 5 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 6 | ["dune" "build" "-p" name "@doc"] {with-doc} 7 | ] 8 | maintainer: ["martin@mjambon.com" "rudi.grinberg@gmail.com"] 9 | authors: ["Martin Jambon"] 10 | bug-reports: "https://github.com/mjambon/easy-format/issues" 11 | homepage: "https://github.com/mjambon/easy-format" 12 | doc: "https://mjambon.github.io/easy-format/" 13 | license: "BSD-3-Clause" 14 | dev-repo: "git+https://github.com/mjambon/easy-format.git" 15 | synopsis: 16 | "High-level and functional interface to the Format module of the OCaml standard library" 17 | description: """ 18 | 19 | This module offers a high-level and functional interface to the Format module of 20 | the OCaml standard library. It is a pretty-printing facility, i.e. it takes as 21 | input some code represented as a tree and formats this code into the most 22 | visually satisfying result, breaking and indenting lines of code where 23 | appropriate. 24 | 25 | Input data must be first modelled and converted into a tree using 3 kinds of 26 | nodes: 27 | 28 | * atoms 29 | * lists 30 | * labelled nodes 31 | 32 | Atoms represent any text that is guaranteed to be printed as-is. Lists can model 33 | any sequence of items such as arrays of data or lists of definitions that are 34 | labelled with something like "int main", "let x =" or "x:".""" 35 | depends: [ 36 | "dune" {>= "1.10"} 37 | "ocaml" {>= "4.02.3"} 38 | ] 39 | url { 40 | src: 41 | "https://github.com/mjambon/easy-format/releases/download/1.3.2/easy-format-1.3.2.tbz" 42 | checksum: [ 43 | "sha256=3440c2b882d537ae5e9011eb06abb53f5667e651ea4bb3b460ea8230fa8c1926" 44 | "sha512=e39377a2ff020ceb9ac29e8515a89d9bdbc91dfcfa871c4e3baafa56753fac2896768e5d9822a050dc1e2ade43c8967afb69391a386c0a8ecd4e1f774e236135" 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /esy.lock/opam/atd.2.2.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "Parser for the ATD data format description language" 3 | description: """ 4 | ATD is the OCaml library providing a parser for the ATD language and various 5 | utilities. ATD stands for Adjustable Type Definitions in reference to its main 6 | property of supporting annotations that allow a good fit with a variety of data 7 | formats. """ 8 | maintainer: ["Rudi Grinberg "] 9 | authors: [ 10 | "Martin Jambon " 11 | "David Sheets " 12 | "Rudi Grinberg " 13 | "Ivan Jager " 14 | "Jeff Meister " 15 | "Carmelo Piccione " 16 | "Raman Varabets " 17 | "Mathieu Baudet " 18 | "Rauan Mayemir " 19 | "Louis Roché " 20 | "Brendan Long " 21 | "Christophe Troestler " 22 | "Vincent Bernardoff " 23 | "haoyang " 24 | ] 25 | license: "MIT" 26 | homepage: "https://github.com/ahrefs/atd" 27 | bug-reports: "https://github.com/ahrefs/atd/issues" 28 | depends: [ 29 | "ocaml" {>= "4.02"} 30 | "dune" {>= "2.0"} 31 | "menhir" 32 | "easy-format" 33 | "re" 34 | ] 35 | dev-repo: "git+https://github.com/ahrefs/atd.git" 36 | build: [ 37 | ["dune" "subst"] {pinned} 38 | [ 39 | "dune" 40 | "build" 41 | "-p" 42 | name 43 | "-j" 44 | jobs 45 | "@install" 46 | "@doc" {with-doc} 47 | ] 48 | ] 49 | url { 50 | src: "https://github.com/ahrefs/atd/releases/download/2.2.1/atd-2.2.1.tbz" 51 | checksum: [ 52 | "sha256=db6b4c1a6293b214a7b7a3da435e681abd1b16b55d5aa246b93d26736d3a559e" 53 | "sha512=0c7f1985cc4d87ddd541bb2f7085b72f81aaef69468653319a4a52e6cd6c9318511229784a12cdb413ae500e7a5b8195759e0d8d49946a9b00f62e8dda07e8a2" 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /esy.lock/opam/biniou.1.2.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | build: [ 3 | ["dune" "subst"] {pinned} 4 | ["dune" "build" "-p" name "-j" jobs] 5 | ["dune" "runtest" "-p" name "-j" jobs] {with-test} 6 | ["dune" "build" "-p" name "@doc"] {with-doc} 7 | ] 8 | maintainer: ["martin@mjambon.com"] 9 | authors: ["Martin Jambon"] 10 | bug-reports: "https://github.com/mjambon/biniou/issues" 11 | homepage: "https://github.com/mjambon/biniou" 12 | doc: "https://mjambon.github.io/biniou/" 13 | license: "BSD-3-Clause" 14 | dev-repo: "git+https://github.com/mjambon/biniou.git" 15 | synopsis: 16 | "Binary data format designed for speed, safety, ease of use and backward compatibility as protocols evolve" 17 | description: """ 18 | 19 | Biniou (pronounced "be new") is a binary data format designed for speed, safety, 20 | ease of use and backward compatibility as protocols evolve. Biniou is vastly 21 | equivalent to JSON in terms of functionality but allows implementations several 22 | times faster (4 times faster than yojson), with 25-35% space savings. 23 | 24 | Biniou data can be decoded into human-readable form without knowledge of type 25 | definitions except for field and variant names which are represented by 31-bit 26 | hashes. A program named bdump is provided for routine visualization of biniou 27 | data files. 28 | 29 | The program atdgen is used to derive OCaml-Biniou serializers and deserializers 30 | from type definitions. 31 | 32 | Biniou format specification: mjambon.github.io/atdgen-doc/biniou-format.txt""" 33 | depends: [ 34 | "easy-format" 35 | "dune" {>= "1.10"} 36 | "ocaml" {>= "4.02.3"} 37 | ] 38 | url { 39 | src: 40 | "https://github.com/mjambon/biniou/releases/download/1.2.1/biniou-1.2.1.tbz" 41 | checksum: [ 42 | "sha256=35546c68b1929a8e6d27a3b39ecd17b38303a0d47e65eb9d1480c2061ea84335" 43 | "sha512=82670cc77bf3e869ee26e5fbe5a5affa45a22bc8b6c4bd7e85473912780e0111baca59b34a2c14feae3543ce6e239d7fddaeab24b686a65bfe642cdb91d27ebf" 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /ts_inspiration/___to_fix.d.ts: -------------------------------------------------------------------------------- 1 | interface Dictionary { 2 | [key: string]: T; 3 | } 4 | export let keys: keyof Dictionary; // string | number 5 | export let value: Dictionary["foo"]; // number 6 | 7 | ////////////////////////////////////////////////////////// 8 | 9 | type TypeName = T extends string 10 | ? "string" 11 | : T extends number 12 | ? "number" 13 | : T extends boolean 14 | ? "boolean" 15 | : T extends undefined 16 | ? "undefined" 17 | : T extends Function 18 | ? "function" 19 | : "object"; 20 | 21 | type T0 = TypeName; // "string" 22 | type T1 = TypeName<"a">; // "string" 23 | type T2 = TypeName; // "boolean" 24 | type T3 = TypeName<() => void>; // "function" 25 | type T4 = TypeName; // "object" 26 | 27 | ////////////////////////////////////////////////////////// 28 | 29 | interface A { 30 | x: string; 31 | y: number; 32 | z: boolean; 33 | } 34 | 35 | type Exclude = T extends U ? never : T; 36 | type stripped = Exclude; 37 | 38 | export enum StringEnum { 39 | A = "A", 40 | B = "B", 41 | } 42 | 43 | export enum NumberEnum { 44 | A, 45 | B, 46 | } 47 | 48 | ////////////////////////////////////////////////////////// 49 | 50 | type StrictNumericEnumParam< 51 | Enum extends number, 52 | Param extends Enum 53 | > = true extends ({ [key: number]: false } & { [P in Enum]: true })[Enum] 54 | ? true extends ({ [key: number]: false } & { [P in Enum]: true })[Param] 55 | ? Param 56 | : never 57 | : Enum; 58 | 59 | export enum Foo { 60 | A, 61 | B, 62 | C, 63 | } 64 | 65 | export enum Bar { 66 | D, 67 | E, 68 | F, 69 | } 70 | 71 | // typically would be written as function doFoo(value: Foo): void 72 | declare function doFoo( 73 | value: StrictNumericEnumParam 74 | ): void; 75 | 76 | declare const foo: Foo; 77 | declare const bar: Bar; 78 | declare const n: number; 79 | 80 | type x = "xxx" extends string ? true : false; 81 | -------------------------------------------------------------------------------- /esy.lock/opam/topkg.1.0.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "Daniel Bünzli " 3 | authors: ["Daniel Bünzli "] 4 | homepage: "http://erratique.ch/software/topkg" 5 | doc: "http://erratique.ch/software/topkg/doc" 6 | license: "ISC" 7 | dev-repo: "git+http://erratique.ch/repos/topkg.git" 8 | bug-reports: "https://github.com/dbuenzli/topkg/issues" 9 | tags: ["packaging" "ocamlbuild" "org:erratique"] 10 | depends: [ 11 | "ocaml" {>= "4.03.0"} 12 | "ocamlfind" {build & >= "1.6.1"} 13 | "ocamlbuild" ] 14 | build: [[ 15 | "ocaml" "pkg/pkg.ml" "build" 16 | "--pkg-name" name 17 | "--dev-pkg" "%{pinned}%" ]] 18 | synopsis: """The transitory OCaml software packager""" 19 | description: """\ 20 | 21 | Topkg is a packager for distributing OCaml software. It provides an 22 | API to describe the files a package installs in a given build 23 | configuration and to specify information about the package's 24 | distribution, creation and publication procedures. 25 | 26 | The optional topkg-care package provides the `topkg` command line tool 27 | which helps with various aspects of a package's life cycle: creating 28 | and linting a distribution, releasing it on the WWW, publish its 29 | documentation, add it to the OCaml opam repository, etc. 30 | 31 | Topkg is distributed under the ISC license and has **no** 32 | dependencies. This is what your packages will need as a *build* 33 | dependency. 34 | 35 | Topkg-care is distributed under the ISC license it depends on 36 | [fmt][fmt], [logs][logs], [bos][bos], [cmdliner][cmdliner], 37 | [webbrowser][webbrowser] and `opam-format`. 38 | 39 | [fmt]: http://erratique.ch/software/fmt 40 | [logs]: http://erratique.ch/software/logs 41 | [bos]: http://erratique.ch/software/bos 42 | [cmdliner]: http://erratique.ch/software/cmdliner 43 | [webbrowser]: http://erratique.ch/software/webbrowser 44 | """ 45 | url { 46 | archive: "http://erratique.ch/software/topkg/releases/topkg-1.0.1.tbz" 47 | checksum: "16b90e066d8972a5ef59655e7c28b3e9" 48 | } 49 | -------------------------------------------------------------------------------- /src/base/parser_token.re: -------------------------------------------------------------------------------- 1 | type t = Parser.token; 2 | 3 | let info = (t: t): Parse_info.t => 4 | switch (t) { 5 | | TYPE(ii) => ii 6 | | INTERFACE(ii) => ii 7 | | ARRAY(ii) => ii 8 | | ARRAY_SHORT(ii) => ii 9 | | ENUM(ii) => ii 10 | | EXTENDS(ii) => ii 11 | | READONLY(ii) => ii 12 | | IMPORT(ii) => ii 13 | | EXPORT(ii) => ii 14 | | DEFAULT(ii) => ii 15 | | FROM(ii) => ii 16 | | AS(ii) => ii 17 | | IN(ii) => ii 18 | | DECLARE(ii) => ii 19 | | FALSE(ii) => ii 20 | | TRUE(ii) => ii 21 | | INSTANCEOF(ii) => ii 22 | | TYPEOF(ii) => ii 23 | | KEYOF(ii) => ii 24 | | THIS(ii) => ii 25 | | VAR(ii) => ii 26 | | LET(ii) => ii 27 | | CONST(ii) => ii 28 | | FUNCTION(ii) => ii 29 | | NAMESPACE(ii) => ii 30 | | MODULE(ii) => ii 31 | | UNKNOWN(ii) => ii 32 | | PUBLIC(ii) => ii 33 | | PROTECTED(ii) => ii 34 | | PRIVATE(ii) => ii 35 | | SYMBOL(ii) => ii 36 | | NEW(ii) => ii 37 | | NEVER(ii) => ii 38 | | CLASS(ii) => ii 39 | | IMPLEMENTS(ii) => ii 40 | | CONSTRUCTOR(ii) => ii 41 | | STATIC(ii) => ii 42 | | PRIM_STRING(ii) => ii 43 | | PRIM_NUMBER(ii) => ii 44 | | PRIM_BOOLEAN(ii) => ii 45 | | PRIM_NULL(ii) => ii 46 | | PRIM_UNDEFINED(ii) => ii 47 | | PRIM_VOID(ii) => ii 48 | | PRIM_ANY(ii) => ii 49 | | EQUALS(ii) => ii 50 | | QMARK(ii) => ii 51 | | DOT(ii) => ii 52 | | AMPERSAND(ii) => ii 53 | | STAR(ii) => ii 54 | | PIPE(ii) => ii 55 | | ARROW(ii) => ii 56 | | LCURLY(ii) => ii 57 | | RCURLY(ii) => ii 58 | | LPAREN(ii) => ii 59 | | RPAREN(ii) => ii 60 | | LBRACKET(ii) => ii 61 | | RBRACKET(ii) => ii 62 | | LT(ii) => ii 63 | | GT(ii) => ii 64 | | PLUS(ii) => ii 65 | | MINUS(ii) => ii 66 | | SEMICOLON(ii) => ii 67 | | VIRTUAL_SEMICOLON(ii) => ii 68 | | COLON(ii) => ii 69 | | COMMA(ii) => ii 70 | | ELLIPSIS(ii) => ii 71 | | EOF(ii) => ii 72 | | OTHER((_, ii)) => ii 73 | | COMMENT((_, ii)) => ii 74 | | COMMENT_LINE((_, ii)) => ii 75 | | IDENT((_, ii)) => ii 76 | | STRING((_, ii, _)) => ii 77 | | NUMBER((_, ii)) => ii 78 | | TRIPLESLASH((_, ii)) => ii 79 | }; 80 | -------------------------------------------------------------------------------- /ts_inspiration/global_file_example.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~] 2 | // Project: [~THE PROJECT NAME~] 3 | // Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]> 4 | 5 | /*~ If this library is callable (e.g. can be invoked as myLib(3)), 6 | *~ include those call signatures here. 7 | *~ Otherwise, delete this section. 8 | */ 9 | declare function myLib(a: string): string; 10 | declare function myLib(a: number): number; 11 | 12 | /*~ If you want the name of this library to be a valid type name, 13 | *~ you can do so here. 14 | *~ 15 | *~ For example, this allows us to write 'var x: myLib'; 16 | *~ Be sure this actually makes sense! If it doesn't, just 17 | *~ delete this declaration and add types inside the namespace below. 18 | */ 19 | interface myLib { 20 | name: string; 21 | length: number; 22 | extras?: string[]; 23 | } 24 | 25 | /*~ If your library has properties exposed on a global variable, 26 | *~ place them here. 27 | *~ You should also place types (interfaces and type alias) here. 28 | */ 29 | declare namespace myLib { 30 | //~ We can write 'myLib.timeout = 50;' 31 | let timeout: number; 32 | 33 | //~ We can access 'myLib.version', but not change it 34 | const version: string; 35 | 36 | //~ There's some class we can create via 'let c = new myLib.Cat(42)' 37 | //~ Or reference e.g. 'function f(c: myLib.Cat) { ... } 38 | class Cat { 39 | constructor(n: number); 40 | 41 | //~ We can read 'c.age' from a 'Cat' instance 42 | readonly age: number; 43 | 44 | //~ We can invoke 'c.purr()' from a 'Cat' instance 45 | purr(): void; 46 | } 47 | 48 | //~ We can declare a variable as 49 | //~ 'var s: myLib.CatSettings = { weight: 5, name: "Maru" };' 50 | interface CatSettings { 51 | weight: number; 52 | name: string; 53 | tailLength?: number; 54 | } 55 | 56 | //~ We can write 'const v: myLib.VetID = 42;' 57 | //~ or 'const v: myLib.VetID = "bob";' 58 | type VetID = string | number; 59 | 60 | //~ We can invoke 'myLib.checkCat(c)' or 'myLib.checkCat(c, v);' 61 | function checkCat(c: Cat, s?: VetID); 62 | } 63 | -------------------------------------------------------------------------------- /src/js/example_files.re: -------------------------------------------------------------------------------- 1 | open Js_of_ocaml; 2 | 3 | module Bridge = Re_typescript_config.Bridge; 4 | let examples = Examples.examples; 5 | 6 | // ----------------------------------------------------------------------------- 7 | 8 | let register_examples = () => { 9 | let rec walk = (~path=Fs.base_path, folders_or_files) => { 10 | folders_or_files 11 | |> CCList.iter( 12 | fun 13 | | Examples.Folder(name, children) => 14 | walk(~path=Fp.append(path, name), children) 15 | | File(name, content) => { 16 | Js_of_ocaml.Sys_js.create_file( 17 | ~name=Fp.append(path, name) |> Fp.toString, 18 | ~content, 19 | ); 20 | }, 21 | ); 22 | }; 23 | walk(examples); 24 | }; 25 | 26 | module File = CCIO.File; 27 | 28 | let rec example_tree = (~exclude=[], path) => { 29 | Fs.list_of_dir(path) 30 | |> CCList.filter_map(sub_path => { 31 | let sub_path_str = sub_path |> Fp.toString; 32 | let base_name = Fp.baseName(sub_path) |> CCOpt.get_exn; 33 | if (exclude |> CCList.exists(CCEqual.string(base_name))) { 34 | None; 35 | } else { 36 | Some( 37 | File.is_directory(sub_path_str) 38 | ? Bridge.Folder((base_name, example_tree(sub_path))) 39 | : Bridge.File(base_name), 40 | ); 41 | }; 42 | }); 43 | }; 44 | 45 | let examples_list = () => 46 | Bridge.string_of_example_list( 47 | try({ 48 | let entries = Fs.list_of_dir(Fs.base_path); 49 | entries 50 | |> CCList.map(example_path => { 51 | let example_path_str = example_path |> Fp.toString; 52 | { 53 | Bridge.path: example_path_str, 54 | meta: 55 | Bridge.example_meta_of_string( 56 | Sys_js.read_file( 57 | ~name=Fp.append(example_path, "meta.json") |> Fp.toString, 58 | ), 59 | ), 60 | files: example_tree(~exclude=["meta.json"], example_path), 61 | }; 62 | }); 63 | }) { 64 | | e => 65 | Console.error(e); 66 | []; 67 | }, 68 | ); 69 | -------------------------------------------------------------------------------- /esy.lock/opam/ctypes.0.17.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | maintainer: "yallop@gmail.com" 3 | homepage: "https://github.com/ocamllabs/ocaml-ctypes" 4 | doc: "http://ocamllabs.github.io/ocaml-ctypes" 5 | dev-repo: "git+http://github.com/ocamllabs/ocaml-ctypes.git" 6 | bug-reports: "http://github.com/ocamllabs/ocaml-ctypes/issues" 7 | license: "MIT" 8 | build: [ 9 | [make "XEN=%{mirage-xen:enable}%" "libffi.config"] 10 | {ctypes-foreign:installed} 11 | ["touch" "libffi.config"] {!ctypes-foreign:installed} 12 | [make "XEN=%{mirage-xen:enable}%" "ctypes-base" "ctypes-stubs"] 13 | [make "XEN=%{mirage-xen:enable}%" "ctypes-foreign"] 14 | {ctypes-foreign:installed} 15 | [make "test"] {with-test} 16 | ] 17 | install: [ 18 | [make "install" "XEN=%{mirage-xen:enable}%"] 19 | ] 20 | depends: [ 21 | "ocaml" {>= "4.02.3"} 22 | "integers" { >= "0.3.0" } 23 | "ocamlfind" {build} 24 | "conf-pkg-config" {build} 25 | "lwt" {with-test & >= "3.2.0"} 26 | "ctypes-foreign" {with-test} 27 | "ounit" {with-test} 28 | "conf-ncurses" {with-test} 29 | ] 30 | depopts: [ 31 | "ctypes-foreign" 32 | "mirage-xen" 33 | ] 34 | tags: ["org:ocamllabs" "org:mirage"] 35 | synopsis: "Combinators for binding to C libraries without writing any C" 36 | description: """ 37 | ctypes is a library for binding to C libraries using pure OCaml. The primary 38 | aim is to make writing C extensions as straightforward as possible. 39 | 40 | The core of ctypes is a set of combinators for describing the structure of C 41 | types -- numeric types, arrays, pointers, structs, unions and functions. You 42 | can use these combinators to describe the types of the functions that you want 43 | to call, then bind directly to those functions -- all without writing or 44 | generating any C! 45 | 46 | To install the optional `ctypes.foreign` interface (which uses `libffi` to 47 | provide dynamic access to foreign libraries), you will need to also install 48 | the `ctypes-foreign` optional dependency: 49 | 50 | opam install ctypes ctypes-foreign 51 | 52 | This will make the `ctypes.foreign` ocamlfind subpackage available.""" 53 | authors: "yallop@gmail.com" 54 | url { 55 | src: "https://github.com/ocamllabs/ocaml-ctypes/archive/0.17.1.tar.gz" 56 | checksum: "md5=508ea062105518c14fd516aa2ea9db5e" 57 | } 58 | -------------------------------------------------------------------------------- /src/js/generate_examples.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const path = require("path"); 3 | 4 | var walk = function (dir, done) { 5 | var results = []; 6 | fs.readdir(dir, function (err, list) { 7 | if (err) return done(err); 8 | var pending = list.length; 9 | if (!pending) return done(null, results); 10 | list.forEach(function (file) { 11 | file = path.resolve(dir, file); 12 | fs.stat(file, function (err, stat) { 13 | if (stat && stat.isDirectory()) { 14 | walk(file, function (err, res) { 15 | results = results.concat(res); 16 | if (!--pending) done(null, results); 17 | }); 18 | } else { 19 | results.push(file); 20 | if (!--pending) done(null, results); 21 | } 22 | }); 23 | }); 24 | }); 25 | }; 26 | 27 | async function get_example_files(path) { 28 | return new Promise((resolve, reject) => { 29 | walk(path, (_, b) => { 30 | resolve(b); 31 | }); 32 | }); 33 | } 34 | 35 | async function app() { 36 | const base_path = `${__dirname}/examples`; 37 | const examples = fs.readdirSync(base_path); 38 | 39 | let examples_rendered = await Promise.all( 40 | examples.map(async (example_name) => { 41 | const example_path = path.join(base_path, example_name); 42 | const subs = await get_example_files(example_path); 43 | return [ 44 | example_name, 45 | await Promise.all( 46 | subs.map((sub) => [ 47 | sub.replace(`${example_path}/`, ""), 48 | fs.readFileSync(sub), 49 | ]) 50 | ), 51 | ]; 52 | }) 53 | ); 54 | examples_rendered = examples_rendered 55 | .map( 56 | ([name, files]) => ` 57 | Folder( 58 | "${name}", 59 | [ 60 | ${files 61 | .map( 62 | ([name, content]) => ` 63 | File( 64 | "${name}", 65 | {|${content}|}, 66 | ) 67 | ` 68 | ) 69 | .join(",\n")} 70 | ] 71 | ) 72 | ` 73 | ) 74 | .join(",\n"); 75 | 76 | const src = ` 77 | type tree = 78 | | Folder(string, list(tree)) 79 | | File(string, string); 80 | let examples = [ 81 | ${examples_rendered} 82 | ]; 83 | `; 84 | 85 | fs.writeFileSync("examples.re", src); 86 | } 87 | 88 | app(); 89 | -------------------------------------------------------------------------------- /src_js/ExamplePanel.re: -------------------------------------------------------------------------------- 1 | module Async = { 2 | [@react.component] 3 | let make = () => { 4 | let (visible, setVisible) = Recoil.useRecoilState(State.examples_open); 5 | let examples = Recoil.useRecoilValue(State.example_list); 6 | let setSelectedExample = Recoil.useSetRecoilState(State.selected_example); 7 | let setSelectedFile = Recoil.useSetRecoilState(State.selected_file); 8 | let selected = Recoil.useRecoilValue(State.selected_example); 9 | React.useEffect1( 10 | () => { 11 | switch (examples->Belt.Array.get(0)) { 12 | | None => () 13 | | Some(example) => 14 | setSelectedExample(_ => Some(example.path)); 15 | setSelectedFile(_ => 16 | Some( 17 | Fp.absoluteExn(example.path) 18 | ->Fp.append(example.meta.entry) 19 | ->Fp.toString, 20 | ) 21 | ); 22 | }; 23 | None; 24 | }, 25 | [|examples->Belt.Array.length|], 26 | ); 27 | 28 | SemanticUi.( 29 | setVisible(_ => false)}> 35 | 36 | {examples 37 | ->Belt.Array.map(example => 38 | { 43 | setSelectedExample(_ => Some(example.path)); 44 | setSelectedFile(_ => 45 | Some( 46 | Fp.absoluteExn(example.path) 47 | ->Fp.append(example.meta.entry) 48 | ->Fp.toString, 49 | ) 50 | ); 51 | }}> 52 | 53 | {example.meta.name}->React.string 54 | 55 | ) 56 | ->React.array} 57 | 58 | 59 | ); 60 | }; 61 | }; 62 | 63 | [@react.component] 64 | let make = () => { 65 | React.string}> 66 | 67 | ; 68 | }; -------------------------------------------------------------------------------- /esy.lock/opam/atdgen.2.2.1/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: 3 | "Generates efficient JSON serializers, deserializers and validators" 4 | description: """ 5 | Atdgen is a command-line program that takes as input type definitions in the ATD 6 | syntax and produces OCaml code suitable for data serialization and 7 | deserialization. 8 | Two data formats are currently supported, these are biniou and JSON. 9 | Atdgen-biniou and Atdgen-json will refer to Atdgen used in one context or the 10 | other. 11 | Atdgen was designed with efficiency and durability in mind. Software authors are 12 | encouraged to use Atdgen directly and to write tools that may reuse part of 13 | Atdgen’s source code.""" 14 | maintainer: ["Rudi Grinberg "] 15 | authors: [ 16 | "Martin Jambon " 17 | "David Sheets " 18 | "Rudi Grinberg " 19 | "Ivan Jager " 20 | "Jeff Meister " 21 | "Carmelo Piccione " 22 | "Raman Varabets " 23 | "Mathieu Baudet " 24 | "Rauan Mayemir " 25 | "Louis Roché " 26 | "Brendan Long " 27 | "Christophe Troestler " 28 | "Vincent Bernardoff " 29 | "haoyang " 30 | ] 31 | license: "MIT" 32 | homepage: "https://github.com/ahrefs/atd" 33 | bug-reports: "https://github.com/ahrefs/atd/issues" 34 | depends: [ 35 | "ocaml" {>= "4.02"} 36 | "dune" {>= "2.0"} 37 | "atd" {>= "2.0.0"} 38 | "atdgen-runtime" {>= "2.0.0"} 39 | "atdgen-codec-runtime" {with-test} 40 | "biniou" {>= "1.0.6"} 41 | "yojson" {>= "1.7.0"} 42 | ] 43 | dev-repo: "git+https://github.com/ahrefs/atd.git" 44 | build: [ 45 | ["dune" "subst"] {pinned} 46 | [ 47 | "dune" 48 | "build" 49 | "-p" 50 | name 51 | "-j" 52 | jobs 53 | "@install" 54 | "@doc" {with-doc} 55 | ] 56 | ] 57 | url { 58 | src: "https://github.com/ahrefs/atd/releases/download/2.2.1/atd-2.2.1.tbz" 59 | checksum: [ 60 | "sha256=db6b4c1a6293b214a7b7a3da435e681abd1b16b55d5aa246b93d26736d3a559e" 61 | "sha512=0c7f1985cc4d87ddd541bb2f7085b72f81aaef69468653319a4a52e6cd6c9318511229784a12cdb413ae500e7a5b8195759e0d8d49946a9b00f62e8dda07e8a2" 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /esy.lock/opam/dune.2.5.0/opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "Fast, portable, and opinionated build system" 3 | description: """ 4 | 5 | dune is a build system that was designed to simplify the release of 6 | Jane Street packages. It reads metadata from "dune" files following a 7 | very simple s-expression syntax. 8 | 9 | dune is fast, has very low-overhead, and supports parallel builds on 10 | all platforms. It has no system dependencies; all you need to build 11 | dune or packages using dune is OCaml. You don't need make or bash 12 | as long as the packages themselves don't use bash explicitly. 13 | 14 | dune supports multi-package development by simply dropping multiple 15 | repositories into the same directory. 16 | 17 | It also supports multi-context builds, such as building against 18 | several opam roots/switches simultaneously. This helps maintaining 19 | packages across several versions of OCaml and gives cross-compilation 20 | for free. 21 | """ 22 | maintainer: ["Jane Street Group, LLC "] 23 | authors: ["Jane Street Group, LLC "] 24 | license: "MIT" 25 | homepage: "https://github.com/ocaml/dune" 26 | doc: "https://dune.readthedocs.io/" 27 | bug-reports: "https://github.com/ocaml/dune/issues" 28 | conflicts: [ 29 | "dune-configurator" {< "2.3.0"} 30 | "odoc" {< "1.3.0"} 31 | "dune-release" {< "1.3.0"} 32 | "jbuilder" {= "transition"} 33 | ] 34 | dev-repo: "git+https://github.com/ocaml/dune.git" 35 | build: [ 36 | # opam 2 sets OPAM_SWITCH_PREFIX, so we don't need a hardcoded path 37 | ["ocaml" "configure.ml" "--libdir" lib] {opam-version < "2"} 38 | ["ocaml" "bootstrap.ml" "-j" jobs] 39 | ["./dune.exe" "build" "-p" name "--profile" "dune-bootstrap" "-j" jobs] 40 | ] 41 | depends: [ 42 | # Please keep the lower bound in sync with .travis.yml, dune-project 43 | # and min_ocaml_version in bootstrap.ml 44 | ("ocaml" {>= "4.07"} | ("ocaml" {< "4.07~~"} & "ocamlfind-secondary")) 45 | "base-unix" 46 | "base-threads" 47 | ] 48 | url { 49 | src: "https://github.com/ocaml/dune/releases/download/2.5.0/dune-2.5.0.tbz" 50 | checksum: [ 51 | "sha256=9cc1661b9b173dd183867edcf8ee28a9ce79079a7d00316b719bdcba1d78d7da" 52 | "sha512=fa29986243b73caa6ca01acbc55cfba5e454e069e737f53c32bee5abc7e3c4679fecdec232d34af63954287bebf0fb1cabe4a95c56147f457d82d1a72dd44223" 53 | ] 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # re-typescript 2 | 3 | An opinionated attempt at finally solving typescript interop for `ReasonML` / `OCaml`. 4 | 5 | ## Why 6 | 7 | I am maintaining a package of automatically generated bindings for `Material UI`. Generating these bindings is becoming more and more frustrating, as the complexity of the original package grows and tools that wish to cover everything begin to break down. this leads to more and more types missing on each cycle and precious time spent on recovering them by adjusting the type extraction process. Right now the generator uses a library which converts `typescript` into a `json-schema` which then get's analyzed & parsed into reason code. I believe that these tools want to cover too many use cases in order to be effective. So I'm setting out to simplify this process and maybe provide an effective way of generalizing type mapping between `reason` and `typescript`. 8 | 9 | Quite ambitious. We'll see. 10 | 11 | ## Idea 12 | 13 | `re-typescript` implements it's own lexer / parser to analyse typescript declaration files specifically. It purposefully does **not** want to get into tracking inferred types through `*.ts` files. It only extracts cleanly defined types as best as it can. 14 | 15 | I am not sure about how to handle unparseable code yet. I believe a _best approximation_ appraoch will be best, where it will gracefully end the traversal by just injecting an abstract type of some sort, instead of failing or fully omitting a type. 16 | 17 | `re-typescript` first derives a primitive AST from the tokenization process. It then decodes that AST by way of resolving references / dependencies. Finally it directly generates an ocaml AST, which allows for easy printing of both `reason` & `ocaml`. I'm composing the ast by using `ocaml-migrate-parsetree`, which will later allow for an easy use inside of a potential `PPX`. 18 | 19 | This tool will be opinionated about a few things. Typescripts dynamic nature makes this unavoidable. I am not yet sure how the native mode will generate it's types exactly (esp. regarding unions / mixed enums). Bucklescript has great features for handling these things, like the `@unboxed` attribute, as well as `@bs.string` for externals and `bs.as` in records. 20 | 21 | ## Playground 22 | 23 | I will update the playground from time to time. It's not great yet, I just wanted a visual representation for now. You can see the current progress here: 24 | [re-typescript](https://jsiebern.github.io/re-typescript/) 25 | 26 | ## Roadmap 27 | 28 | See projects section: [re-typescript projects](https://github.com/jsiebern/re-typescript/projects) 29 | --------------------------------------------------------------------------------