; // 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 | ;
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 |
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 |
--------------------------------------------------------------------------------