From f898578d80d3e2a54080c1c046c45f9eaa2435c3 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Wed, 22 May 2024 17:59:41 -0300 Subject: [PATCH 1/7] Insert newline at end of generated files (#321) --- ts-rs/src/export.rs | 1 + ts-rs/tests/integration/docs.rs | 27 ++++++++++++++-------- ts-rs/tests/integration/export_manually.rs | 10 ++++---- ts-rs/tests/integration/imports.rs | 12 +++++----- ts-rs/tests/integration/issue_168.rs | 4 ++-- ts-rs/tests/integration/issue_232.rs | 4 ++-- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 504341876..cfcee0405 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -152,6 +152,7 @@ pub(crate) fn export_to_string() -> Result(&mut buffer, default_out_dir())?; generate_decl::(&mut buffer); + buffer.push('\n'); Ok(buffer) } diff --git a/ts-rs/tests/integration/docs.rs b/ts-rs/tests/integration/docs.rs index d989fa011..5fec1b923 100644 --- a/ts-rs/tests/integration/docs.rs +++ b/ts-rs/tests/integration/docs.rs @@ -132,7 +132,8 @@ fn export_a() { " *\n", " * Testing\n", " */\n", - "name: string, };" + "name: string, };", + "\n", ) }; @@ -179,6 +180,7 @@ fn export_b() { " * Testing\n", " */\n", "name: string, };", + "\n", ) }; @@ -200,7 +202,7 @@ fn export_c() { " *\n", " * Testing\n", " */\n", - "export type C = Record;\n" + "export type C = Record;\n", ) } else { concat!( @@ -211,7 +213,8 @@ fn export_c() { " *\n", " * Testing\n", " */\n", - "export type C = Record;" + "export type C = Record;", + "\n", ) }; @@ -233,7 +236,7 @@ fn export_d() { " *\n", " * Testing\n", " */\n", - "export type D = null;\n" + "export type D = null;\n", ) } else { concat!( @@ -244,7 +247,8 @@ fn export_d() { " *\n", " * Testing\n", " */\n", - "export type D = null;" + "export type D = null;", + "\n", ) }; let actual_content = fs::read_to_string(D::default_output_path().unwrap()).unwrap(); @@ -265,7 +269,7 @@ fn export_e() { " *\n", " * Testing\n", " */\n", - "export type E = never;\n" + "export type E = never;\n", ) } else { concat!( @@ -276,7 +280,8 @@ fn export_e() { " *\n", " * Testing\n", " */\n", - "export type E = never;" + "export type E = never;", + "\n", ) }; @@ -307,7 +312,7 @@ fn export_f() { " */\n", " variant_field: number;\n", " };\n", - "};\n" + "};\n", ) } else { concat!( @@ -324,7 +329,8 @@ fn export_f() { " *\n", " * Testing\n", " */\n", - "variant_field: number, } };" + "variant_field: number, } };", + "\n", ) }; @@ -356,7 +362,7 @@ fn export_g() { " */\n", " variant_field: number;\n", " };\n", - " });\n" + " });\n", ) } else { concat!( @@ -373,6 +379,7 @@ fn export_g() { " * Testing\n", " */\n", "variant_field: number, } });", + "\n", ) }; diff --git a/ts-rs/tests/integration/export_manually.rs b/ts-rs/tests/integration/export_manually.rs index cdf111879..f575fed64 100644 --- a/ts-rs/tests/integration/export_manually.rs +++ b/ts-rs/tests/integration/export_manually.rs @@ -27,12 +27,13 @@ fn export_manually() { let expected_content = if cfg!(feature = "format") { concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", - "export type User = { name: string; age: number; active: boolean };\n" + "export type User = { name: string; age: number; active: boolean };\n", ) } else { concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", - "\nexport type User = { name: string, age: number, active: boolean, };" + "\nexport type User = { name: string, age: number, active: boolean, };", + "\n", ) }; @@ -48,12 +49,13 @@ fn export_manually_dir() { let expected_content = if cfg!(feature = "format") { concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n", - "export type UserDir = { name: string; age: number; active: boolean };\n" + "export type UserDir = { name: string; age: number; active: boolean };\n", ) } else { concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", - "\nexport type UserDir = { name: string, age: number, active: boolean, };" + "\nexport type UserDir = { name: string, age: number, active: boolean, };", + "\n", ) }; diff --git a/ts-rs/tests/integration/imports.rs b/ts-rs/tests/integration/imports.rs index 85eca7c0c..bd7e5f818 100644 --- a/ts-rs/tests/integration/imports.rs +++ b/ts-rs/tests/integration/imports.rs @@ -36,8 +36,7 @@ fn test_def() { "\n", "export type TestEnum = { \"C\": { value: TestTypeB } } | {\n", " \"A1\": { value: TestTypeA };\n", - "} | { \"A2\": { value: TestTypeA } };\n" - + "} | { \"A2\": { value: TestTypeA } };\n", ), (true, false) => concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", @@ -46,22 +45,23 @@ fn test_def() { "\n", "export type TestEnum = { \"C\": { value: TestTypeB } } | {\n", " \"A1\": { value: TestTypeA };\n", - "} | { \"A2\": { value: TestTypeA } };\n" - + "} | { \"A2\": { value: TestTypeA } };\n", ), (false, true) => concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", "import type { TestTypeA } from \"./ts_rs_test_type_a.js\";\n", "import type { TestTypeB } from \"./ts_rs_test_type_b.js\";\n", "\n", - "export type TestEnum = { \"C\": { value: TestTypeB, } } | { \"A1\": { value: TestTypeA, } } | { \"A2\": { value: TestTypeA, } };" + "export type TestEnum = { \"C\": { value: TestTypeB, } } | { \"A1\": { value: TestTypeA, } } | { \"A2\": { value: TestTypeA, } };", + "\n", ), (false, false) => concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", "import type { TestTypeA } from \"./ts_rs_test_type_a\";\n", "import type { TestTypeB } from \"./ts_rs_test_type_b\";\n", "\n", - "export type TestEnum = { \"C\": { value: TestTypeB, } } | { \"A1\": { value: TestTypeA, } } | { \"A2\": { value: TestTypeA, } };" + "export type TestEnum = { \"C\": { value: TestTypeB, } } | { \"A1\": { value: TestTypeA, } } | { \"A2\": { value: TestTypeA, } };", + "\n", ), }; diff --git a/ts-rs/tests/integration/issue_168.rs b/ts-rs/tests/integration/issue_168.rs index d4f687e94..a82a580d8 100644 --- a/ts-rs/tests/integration/issue_168.rs +++ b/ts-rs/tests/integration/issue_168.rs @@ -38,13 +38,13 @@ fn issue_168() { FooInlined::export_to_string().unwrap(), "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\ \n\ - export type FooInlined = { map: { [key: number]: { map: { [key: number]: { map: { [key: number]: string }, } }, } }, };" + export type FooInlined = { map: { [key: number]: { map: { [key: number]: { map: { [key: number]: string }, } }, } }, };\n" ); assert_eq!( Foo::export_to_string().unwrap(), "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\ import type { Bar } from \"./Bar\";\n\ \n\ - export type Foo = { map: { [key: number]: Bar }, };" + export type Foo = { map: { [key: number]: Bar }, };\n" ); } diff --git a/ts-rs/tests/integration/issue_232.rs b/ts-rs/tests/integration/issue_232.rs index 234c9b5c0..5cb6f6844 100644 --- a/ts-rs/tests/integration/issue_232.rs +++ b/ts-rs/tests/integration/issue_232.rs @@ -53,7 +53,7 @@ fn issue_232() { export type StateInlined = { \ a: { Ok : { name: string, inner: Enum, } } | { Err : string }, \ b: { Ok : { name: string, inner: Enum, } } | { Err : string }, \ - };" + };\n" ); assert_eq!( State::export_to_string().unwrap(), @@ -63,6 +63,6 @@ fn issue_232() { export type State = { \ a: { Ok : EnumWithName } | { Err : string }, \ b: { Ok : EnumWithName } | { Err : string }, \ - };" + };\n" ); } From be0349d5fb07a8ccab713887a61e90e3bc773c7a Mon Sep 17 00:00:00 2001 From: escritorio-gustavo <131818645+escritorio-gustavo@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:08:19 -0300 Subject: [PATCH 2/7] bug: Fix issue with absolute paths (#323) --- .github/workflows/test.yml | 19 +++++++++++++++++++ ts-rs/src/export/path.rs | 8 +------- ts-rs/tests/integration/issue_317.rs | 2 +- ts-rs/tests/integration/main.rs | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e27ed4b7a..2590ffd54 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -126,6 +126,25 @@ jobs: tsc output/**/*.ts --noEmit --noUnusedLocals --strict rm -rf output + test-absolute-export-env: + name: Test ts-rs with absolute TS_RS_EXPORT_DIR + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + steps: + - uses: actions/checkout@v4 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + - uses: Swatinem/rust-cache@v2 + - name: Test + working-directory: ts-rs + run: | + TS_RS_EXPORT_DIR=$(pwd)/output cargo test --no-default-features + shopt -s globstar + tsc output/**/*.ts --noEmit --noUnusedLocals --strict + rm -rf output + test-no-features: name: Test ts-rs with --no-default-features runs-on: ubuntu-latest diff --git a/ts-rs/src/export/path.rs b/ts-rs/src/export/path.rs index be704834a..fdfc0b148 100644 --- a/ts-rs/src/export/path.rs +++ b/ts-rs/src/export/path.rs @@ -4,13 +4,7 @@ use super::ExportError as E; const ERROR_MESSAGE: &str = r#"The path provided with `#[ts(export_to = "..")]` is not valid"#; pub fn absolute>(path: T) -> Result { - let path = path.as_ref(); - - if path.is_absolute() { - return Ok(path.to_owned()); - } - - let path = std::env::current_dir()?.join(path); + let path = std::env::current_dir()?.join(path.as_ref()); let mut out = Vec::new(); for comp in path.components() { diff --git a/ts-rs/tests/integration/issue_317.rs b/ts-rs/tests/integration/issue_317.rs index bc286baab..fed7f8869 100644 --- a/ts-rs/tests/integration/issue_317.rs +++ b/ts-rs/tests/integration/issue_317.rs @@ -8,7 +8,7 @@ struct VariantId(u32); #[ts(export_to = "issue_317/")] struct VariantOverview { id: u32, - name: String + name: String, } #[derive(TS)] diff --git a/ts-rs/tests/integration/main.rs b/ts-rs/tests/integration/main.rs index 6eeef9f8b..cb5ca38fe 100644 --- a/ts-rs/tests/integration/main.rs +++ b/ts-rs/tests/integration/main.rs @@ -23,6 +23,7 @@ mod infer_as; mod issue_168; mod issue_232; mod issue_308; +mod issue_317; mod issue_70; mod issue_80; mod leading_colon; @@ -59,4 +60,3 @@ mod union_with_data; mod union_with_internal_tag; mod unit; mod r#unsized; -mod issue_317; From 743e715f8e15601ba1aa2113d9c6c26d0fd9b9bd Mon Sep 17 00:00:00 2001 From: Moritz Bischof Date: Thu, 20 Jun 2024 18:54:28 +0200 Subject: [PATCH 3/7] prepare release for 9.0.0 --- CHANGELOG.md | 2 ++ Cargo.lock | 4 ++-- README.md | 2 +- macros/Cargo.toml | 2 +- ts-rs/Cargo.toml | 4 ++-- ts-rs/src/lib.rs | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bc7f5eda..e6add4878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ - Fix `#[ts(rename_all_fields = "...")]` on enums containing tuple or unit variants ([#287](https://github.com/Aleph-Alpha/ts-rs/pull/287)) - Fix "overflow evaluating the requirement" and "reached the recursion limit" errors in some cases ([#293](https://github.com/Aleph-Alpha/ts-rs/pull/293)) - Fix ambiguity causing "multiple applicable items in scope" errors in some cases ([#309](https://github.com/Aleph-Alpha/ts-rs/pull/309)) +- Fix issues with absolute `TS_RS_EXPORT_DIR` paths ([#323](https://github.com/Aleph-Alpha/ts-rs/pull/323)) +- Add newlines to the end of exported files ([#321](https://github.com/Aleph-Alpha/ts-rs/pull/321)) # 8.1.0 diff --git a/Cargo.lock b/Cargo.lock index c8a0eae63..27813d314 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1182,7 +1182,7 @@ dependencies = [ [[package]] name = "ts-rs" -version = "8.1.0" +version = "9.0.0" dependencies = [ "bigdecimal", "bson", @@ -1203,7 +1203,7 @@ dependencies = [ [[package]] name = "ts-rs-macros" -version = "8.1.0" +version = "9.0.0" dependencies = [ "proc-macro2", "quote", diff --git a/README.md b/README.md index 6d019aee3..de1d47695 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ We recommend doing this in your tests. ### Get started ```toml [dependencies] -ts-rs = "8.1" +ts-rs = "9.0" ``` ```rust diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 7373256de..2565661c8 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ts-rs-macros" -version = "8.1.0" +version = "9.0.0" authors = ["Moritz Bischof "] edition = "2021" description = "derive macro for ts-rs" diff --git a/ts-rs/Cargo.toml b/ts-rs/Cargo.toml index ae3eba835..516684493 100644 --- a/ts-rs/Cargo.toml +++ b/ts-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ts-rs" -version = "8.1.0" +version = "9.0.0" authors = ["Moritz Bischof "] edition = "2021" license = "MIT" @@ -42,7 +42,7 @@ chrono = { version = "0.4", features = ["serde"] } [dependencies] heapless = { version = ">= 0.7, < 0.9", optional = true } -ts-rs-macros = { version = "=8.1.0", path = "../macros" } +ts-rs-macros = { version = "=9.0.0", path = "../macros" } dprint-plugin-typescript = { version = "0.90", optional = true } chrono = { version = "0.4", optional = true } bigdecimal = { version = ">= 0.0.13, < 0.5", features = [ diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index a422c5942..58ff6e007 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -40,7 +40,7 @@ //! ## Get started //! ```toml //! [dependencies] -//! ts-rs = "8.1" +//! ts-rs = "9.0" //! ``` //! //! ```rust From c9615f6601a3400ef2c48c31167c4c69ed136026 Mon Sep 17 00:00:00 2001 From: Moritz Bischof Date: Thu, 20 Jun 2024 18:56:58 +0200 Subject: [PATCH 4/7] update lockfile --- Cargo.lock | 448 +++++++++++++++++++++++++---------------------------- 1 file changed, 212 insertions(+), 236 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27813d314..5e6c248ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.7" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom", @@ -27,18 +27,18 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-tzdata" @@ -57,36 +57,27 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "ast_node" -version = "0.9.6" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3e3e06ec6ac7d893a0db7127d91063ad7d9da8988f8a1a256f03729e6eec026" +checksum = "2ab31376d309dd3bfc9cfb3c11c93ce0e0741bbe0354b20e7f8c60b044730b79" dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.48", -] - -[[package]] -name = "atomic-polyfill" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" -dependencies = [ - "critical-section", + "syn 2.0.66", ] [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "base64" @@ -105,10 +96,12 @@ dependencies = [ [[package]] name = "bigdecimal" -version = "0.3.1" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" +checksum = "51d712318a27c7150326677b321a5fa91b55f6d9034ffd67f20319e147d40cee" dependencies = [ + "autocfg", + "libm", "num-bigint", "num-integer", "num-traits", @@ -135,9 +128,9 @@ dependencies = [ [[package]] name = "bson" -version = "2.9.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce21468c1c9c154a85696bb25c20582511438edb6ad67f846ba1378ffdd80222" +checksum = "d8a88e82b9106923b5c4d6edfca9e7db958d4e98a478ec115022e81b9b38e2c8" dependencies = [ "ahash", "base64", @@ -156,9 +149,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" dependencies = [ "allocator-api2", ] @@ -171,18 +164,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -192,9 +182,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.33" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", @@ -211,12 +201,6 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" -[[package]] -name = "critical-section" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" - [[package]] name = "data-url" version = "0.3.1" @@ -225,9 +209,9 @@ checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" [[package]] name = "deno_ast" -version = "0.35.1" +version = "0.38.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c45813a2b6c658e5bc5a2f8336460f2b1c1c61a7adaf5e861df16ae3f3c76ca1" +checksum = "584547d27786a734536fde7088f8429d355569c39410427be44695c300618408" dependencies = [ "deno_media_type", "deno_terminal", @@ -241,15 +225,16 @@ dependencies = [ "swc_ecma_parser", "swc_eq_ignore_macros", "text_lines", + "thiserror", "unicode-width", "url", ] [[package]] name = "deno_media_type" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a798670c20308e5770cc0775de821424ff9e85665b602928509c8c70430b3ee0" +checksum = "a8978229b82552bf8457a0125aa20863f023619cfc21ebb007b1e571d68fd85b" dependencies = [ "data-url", "serde", @@ -277,9 +262,9 @@ dependencies = [ [[package]] name = "dprint-core" -version = "0.66.1" +version = "0.66.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317f9cd1da390ab12e1858b3a71c7d6c8e8ad633454cb0b73ce5589964d9c177" +checksum = "f3ab0dd2bedc109d25f0d21afb09b7d329f6c6fa83b095daf31d2d967e091548" dependencies = [ "anyhow", "bumpalo", @@ -302,9 +287,9 @@ dependencies = [ [[package]] name = "dprint-plugin-typescript" -version = "0.90.0" +version = "0.90.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f180a70c7fae19cf6296a70d0850748e72d5162400491cde0aa424b22fd81212" +checksum = "d7c3c339020ebbbbbe5fc049350935ee2ea2ba5a3fc01f753588639a30404cda" dependencies = [ "anyhow", "deno_ast", @@ -317,9 +302,9 @@ dependencies = [ [[package]] name = "dprint-swc-ext" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bad772f9e49af3a613fcddf1671d1e2e877e0a6d94f2b7162bfea4ac8140bee" +checksum = "019d17f2c2457c5a70a7cf4505b1a562ca8ab168c0ac0c005744efbd29fcb8fe" dependencies = [ "allocator-api2", "bumpalo", @@ -334,9 +319,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "equivalent" @@ -365,13 +350,13 @@ dependencies = [ [[package]] name = "from_variant" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a0b11eeb173ce52f84ebd943d42e58813a2ebb78a6a3ff0a243b71c5199cd7b" +checksum = "fdc9cc75639b041067353b9bce2450d6847e547276c6fbe4487d7407980e07db" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] @@ -382,9 +367,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -393,18 +378,18 @@ dependencies = [ [[package]] name = "hash32" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" dependencies = [ "byteorder", ] [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", "allocator-api2", @@ -412,14 +397,11 @@ dependencies = [ [[package]] name = "heapless" -version = "0.7.17" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" dependencies = [ - "atomic-polyfill", "hash32", - "rustc_version", - "spin", "stable_deref_trait", ] @@ -431,9 +413,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hstr" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0f5356d62012374578cd3a5c013d6586de3efbca3b53379fc1edfbb95c9db14" +checksum = "96274be293b8877e61974a607105d09c84caebe9620b47774aa8a6b942042dd4" dependencies = [ "hashbrown", "new_debug_unreachable", @@ -445,9 +427,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.59" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -478,9 +460,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.2" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", @@ -496,20 +478,20 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.67" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -522,65 +504,65 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] -name = "lock_api" -version = "0.4.11" +name = "libm" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "new_debug_unreachable" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", "serde", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -593,9 +575,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "ordered-float" -version = "3.9.2" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" +checksum = "a76df7075c7d4d01fdcb46c912dd17fba5b60c78ea480b475f2b6ab6f666584e" dependencies = [ "num-traits", ] @@ -636,7 +618,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] @@ -650,9 +632,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "powerfmt" @@ -668,9 +650,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -686,9 +668,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -731,9 +713,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -743,9 +725,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -754,9 +736,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rustc-hash" @@ -764,20 +746,11 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scoped-tls" @@ -785,23 +758,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "semver" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] @@ -817,20 +784,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "indexmap", "itoa", @@ -846,9 +813,9 @@ checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smartstring" @@ -861,15 +828,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -897,21 +855,21 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "string_enum" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b650ea2087d32854a0f20b837fc56ec987a1cb4f758c9757e1171ee9812da63" +checksum = "05e383308aebc257e7d7920224fa055c632478d92744eca77f99be8fa1545b90" dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] name = "swc_atoms" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04d9d1941a7d24fc503efa29c53f88dd61e6a15cc371947a75cca3b48d564b5b" +checksum = "bb6567e4e67485b3e7662b486f1565bdae54bd5b9d6b16b2ba1a9babb1e42125" dependencies = [ "hstr", "once_cell", @@ -921,9 +879,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.33.22" +version = "0.33.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f91d53367db183e55ecaa090c9a2b6e62ddbd1258aa2ac6c6925772eec9e2b" +checksum = "a2f9706038906e66f3919028f9f7a37f3ed552f1b85578e93f4468742e2da438" dependencies = [ "ast_node", "better_scoped_tls", @@ -946,9 +904,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.112.7" +version = "0.113.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bcd97ee367b48444f90416ea56e71d761600f816bcae9df4f99293d1fa36bd5" +checksum = "dc1690cc0c9ab60b44ac0225ba1e231ac532f7ba1d754df761c6ee607561afae" dependencies = [ "bitflags", "is-macro", @@ -964,9 +922,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.143.12" +version = "0.144.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fc7ab256f83a9491b37a510dd1cba9d81bb306faf3cff1dacdbc897fa4869f" +checksum = "0499e69683ae5d67a20ff0279b94bc90f29df7922a46331b54d5dd367bf89570" dependencies = [ "either", "new_debug_unreachable", @@ -992,25 +950,25 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] name = "swc_macros_common" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50176cfc1cbc8bb22f41c6fe9d1ec53fbe057001219b5954961b8ad0f336fce9" +checksum = "91745f3561057493d2da768437c427c0e979dff7396507ae02f16c981c4a8466" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] name = "swc_visit" -version = "0.5.10" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f5b3e8d1269a7cb95358fed3412645d9c15aa0eb1f4ca003a25a38ef2f30f1b" +checksum = "043d11fe683dcb934583ead49405c0896a5af5face522e4682c16971ef7871b9" dependencies = [ "either", "swc_visit_macros", @@ -1018,15 +976,15 @@ dependencies = [ [[package]] name = "swc_visit_macros" -version = "0.5.11" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33fc817055fe127b4285dc85058596768bfde7537ae37da82c67815557f03e33" +checksum = "4ae9ef18ff8daffa999f729db056d2821cd2f790f3a11e46422d19f46bb193e7" dependencies = [ "Inflector", "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] @@ -1042,9 +1000,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -1077,32 +1035,33 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] name = "time" -version = "0.3.31" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "num-conv", "powerfmt", "serde", "time-core", @@ -1117,10 +1076,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] @@ -1158,7 +1118,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", ] [[package]] @@ -1172,9 +1132,9 @@ dependencies = [ [[package]] name = "triomphe" -version = "0.1.11" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" +checksum = "e6631e42e10b40c0690bf92f404ebcfe6e1fdb480391d15f17cc8e96eeed5369" dependencies = [ "serde", "stable_deref_trait", @@ -1207,7 +1167,7 @@ version = "9.0.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", "termcolor", ] @@ -1225,9 +1185,9 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-id-start" -version = "1.1.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f73150333cb58412db36f2aca8f2875b013049705cc77b94ded70a1ab1f5da" +checksum = "02aebfa694eccbbbffdd92922c7de136b9fe764396d2f10e21bce1681477cfc1" [[package]] name = "unicode-ident" @@ -1237,24 +1197,24 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -1264,9 +1224,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ "getrandom", "serde", @@ -1286,9 +1246,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1296,24 +1256,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1321,22 +1281,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.90" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "winapi" @@ -1356,11 +1316,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys", ] [[package]] @@ -1379,14 +1339,24 @@ dependencies = [ ] [[package]] -name = "windows-targets" +name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", + "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", @@ -1395,45 +1365,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "wyz" @@ -1446,20 +1422,20 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.66", ] From c7c8ff329d565de8bad27c8918ea12cfd762c569 Mon Sep 17 00:00:00 2001 From: Moritz Bischof Date: Thu, 20 Jun 2024 18:58:50 +0200 Subject: [PATCH 5/7] Release v9.0.0 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6add4878..dd15eeb4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # master +### Breaking +### Features +### Fixes + +# 9.0.0 ### Breaking From af15ff92d7f5ffe97dec6818c10b90d883bde5d7 Mon Sep 17 00:00:00 2001 From: NyxCode Date: Fri, 28 Jun 2024 02:07:52 +0200 Subject: [PATCH 6/7] Allow for flattening of generic parameters (#336) --- CHANGELOG.md | 5 ++ Cargo.lock | 78 ++++++++++----------- macros/Cargo.toml | 2 +- macros/src/lib.rs | 2 +- ts-rs/Cargo.toml | 4 +- ts-rs/tests/integration/generics_flatten.rs | 49 +++++++++++++ ts-rs/tests/integration/main.rs | 1 + 7 files changed, 98 insertions(+), 43 deletions(-) create mode 100644 ts-rs/tests/integration/generics_flatten.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index dd15eeb4e..07ba3267c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ ### Features ### Fixes +# 9.0.1 +### Fixes +- Allow using `#[ts(flatten)]` on fields using generic parameters ([#336](https://github.com/Aleph-Alpha/ts-rs/pull/336)) + + # 9.0.0 ### Breaking diff --git a/Cargo.lock b/Cargo.lock index 5e6c248ad..3cb30379b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,7 +70,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitvec" @@ -170,9 +170,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.99" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" +checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" [[package]] name = "cfg-if" @@ -319,9 +319,9 @@ dependencies = [ [[package]] name = "either" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "equivalent" @@ -356,7 +356,7 @@ checksum = "fdc9cc75639b041067353b9bce2450d6847e547276c6fbe4487d7407980e07db" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -478,7 +478,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -498,9 +498,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" @@ -534,9 +534,9 @@ checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" [[package]] name = "num-bigint" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", @@ -618,7 +618,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -650,9 +650,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -775,9 +775,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.14" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" dependencies = [ "serde", ] @@ -790,14 +790,14 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" dependencies = [ "indexmap", "itoa", @@ -862,7 +862,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -950,7 +950,7 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -961,7 +961,7 @@ checksum = "91745f3561057493d2da768437c427c0e979dff7396507ae02f16c981c4a8466" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -984,7 +984,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1000,9 +1000,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.66" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -1050,7 +1050,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1086,9 +1086,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" dependencies = [ "tinyvec_macros", ] @@ -1118,7 +1118,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1142,7 +1142,7 @@ dependencies = [ [[package]] name = "ts-rs" -version = "9.0.0" +version = "9.0.1" dependencies = [ "bigdecimal", "bson", @@ -1163,11 +1163,11 @@ dependencies = [ [[package]] name = "ts-rs-macros" -version = "9.0.0" +version = "9.0.1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "termcolor", ] @@ -1224,9 +1224,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.8.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439" dependencies = [ "getrandom", "serde", @@ -1265,7 +1265,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "wasm-bindgen-shared", ] @@ -1287,7 +1287,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1437,5 +1437,5 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 2565661c8..bbab8dc1d 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ts-rs-macros" -version = "9.0.0" +version = "9.0.1" authors = ["Moritz Bischof "] edition = "2021" description = "derive macro for ts-rs" diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 845d2af37..4be1ce536 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -158,7 +158,7 @@ impl DerivedTS { type WithoutGenerics = #generics; fn name() -> String { stringify!(#generics).to_owned() } fn inline() -> String { panic!("{} cannot be inlined", #name) } - fn inline_flattened() -> String { panic!("{} cannot be flattened", #name) } + fn inline_flattened() -> String { stringify!(#generics).to_owned() } fn decl() -> String { panic!("{} cannot be declared", #name) } fn decl_concrete() -> String { panic!("{} cannot be declared", #name) } } diff --git a/ts-rs/Cargo.toml b/ts-rs/Cargo.toml index 516684493..ff6ed588c 100644 --- a/ts-rs/Cargo.toml +++ b/ts-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ts-rs" -version = "9.0.0" +version = "9.0.1" authors = ["Moritz Bischof "] edition = "2021" license = "MIT" @@ -42,7 +42,7 @@ chrono = { version = "0.4", features = ["serde"] } [dependencies] heapless = { version = ">= 0.7, < 0.9", optional = true } -ts-rs-macros = { version = "=9.0.0", path = "../macros" } +ts-rs-macros = { version = "=9.0.1", path = "../macros" } dprint-plugin-typescript = { version = "0.90", optional = true } chrono = { version = "0.4", optional = true } bigdecimal = { version = ">= 0.0.13, < 0.5", features = [ diff --git a/ts-rs/tests/integration/generics_flatten.rs b/ts-rs/tests/integration/generics_flatten.rs new file mode 100644 index 000000000..85bd61a75 --- /dev/null +++ b/ts-rs/tests/integration/generics_flatten.rs @@ -0,0 +1,49 @@ +use ts_rs_macros::TS; + +// https://github.com/Aleph-Alpha/ts-rs/issues/335 +#[derive(TS)] +#[ts(export, export_to = "generics/flatten/")] +struct Item { + id: String, + #[ts(flatten)] + inner: D, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/flatten/")] +struct TwoParameters { + id: String, + #[ts(flatten)] + a: A, + #[ts(flatten)] + b: B, + ab: (A, B), +} + +#[derive(TS)] +#[ts(export, export_to = "generics/flatten/")] +enum Enum { + A { + #[ts(flatten)] + a: A, + }, + B { + #[ts(flatten)] + b: B, + }, + AB(A, B), +} + +#[test] +fn flattened_generic_parameters() { + use ts_rs::TS; + + #[derive(TS)] + struct Inner { + x: i32, + } + + assert_eq!(Item::<()>::decl(), "type Item = { id: string, } & D;"); + assert_eq!(TwoParameters::<(), ()>::decl(), "type TwoParameters = { id: string, ab: [A, B], } & A & B;"); + assert_eq!(Enum::<(), ()>::decl(), "type Enum = { \"A\": A } | { \"B\": B } | { \"AB\": [A, B] };"); +} diff --git a/ts-rs/tests/integration/main.rs b/ts-rs/tests/integration/main.rs index cb5ca38fe..59ba72888 100644 --- a/ts-rs/tests/integration/main.rs +++ b/ts-rs/tests/integration/main.rs @@ -15,6 +15,7 @@ mod flatten; mod generic_fields; mod generic_without_import; mod generics; +mod generics_flatten; mod hashmap; mod hashset; mod imports; From 68f2f2252a95fe540bd901afebb81cf5429db034 Mon Sep 17 00:00:00 2001 From: Gustavo Shigueo Date: Fri, 5 Jul 2024 14:47:18 -0300 Subject: [PATCH 7/7] Change `HashMap` to export mapped types (#339) --- ts-rs/src/lib.rs | 4 +- ts-rs/tests/integration/generics.rs | 856 ++++++++++---------- ts-rs/tests/integration/hashmap.rs | 144 ++-- ts-rs/tests/integration/indexmap.rs | 40 +- ts-rs/tests/integration/issue_168.rs | 4 +- ts-rs/tests/integration/issue_338.rs | 37 + ts-rs/tests/integration/issue_70.rs | 154 ++-- ts-rs/tests/integration/lifetimes.rs | 72 +- ts-rs/tests/integration/main.rs | 1 + ts-rs/tests/integration/self_referential.rs | 376 ++++----- ts-rs/tests/integration/serde_json.rs | 130 +-- 11 files changed, 928 insertions(+), 890 deletions(-) create mode 100644 ts-rs/tests/integration/issue_338.rs diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index 58ff6e007..efa128aca 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -896,11 +896,11 @@ impl TS for HashMap { } fn name() -> String { - format!("{{ [key: {}]: {} }}", K::name(), V::name()) + format!("{{ [key in {}]?: {} }}", K::name(), V::name()) } fn inline() -> String { - format!("{{ [key: {}]: {} }}", K::inline(), V::inline()) + format!("{{ [key in {}]?: {} }}", K::inline(), V::inline()) } fn visit_dependencies(v: &mut impl TypeVisitor) diff --git a/ts-rs/tests/integration/generics.rs b/ts-rs/tests/integration/generics.rs index fdf4ec2d1..4140672af 100644 --- a/ts-rs/tests/integration/generics.rs +++ b/ts-rs/tests/integration/generics.rs @@ -1,428 +1,428 @@ -#![allow(clippy::box_collection, clippy::enum_variant_names, dead_code)] -#![allow(dead_code)] - -use std::{ - collections::{BTreeMap, HashSet}, - fmt::Debug, - rc::Rc, -}; - -use ts_rs::TS; - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct Generic -where - T: TS, -{ - value: T, - values: Vec, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct GenericAutoBound { - value: T, - values: Vec, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct GenericAutoBound2 -where - T: PartialEq, -{ - value: T, - values: Vec, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct Container { - foo: Generic, - bar: Box>>, - baz: Box>>>, -} - -macro_rules! declare { - ($(#[$meta:meta])* $name:ident { $($fident:ident: $t:ty),+ $(,)? }) => { - $(#[$meta])* - struct $name { - $(pub $fident: $t),+ - } - } -} - -declare! { - #[derive(TS)] - #[ts(export, export_to = "generics/")] - TypeGroup { - foo: Vec, - } -} - -#[test] -fn test() { - assert_eq!( - TypeGroup::decl(), - "type TypeGroup = { foo: Array, };", - ); - - assert_eq!( - Generic::<()>::decl(), - "type Generic = { value: T, values: Array, };" - ); - - assert_eq!( - GenericAutoBound::<()>::decl(), - "type GenericAutoBound = { value: T, values: Array, };" - ); - - assert_eq!( - GenericAutoBound2::<()>::decl(), - "type GenericAutoBound2 = { value: T, values: Array, };" - ); - - assert_eq!( - Container::decl(), - "type Container = { foo: Generic, bar: Array>, baz: { [key: string]: Generic }, };" - ); -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -enum GenericEnum { - A(A), - B(B, B, B), - C(Vec), - D(Vec>>), - E { a: A, b: B, c: C }, - X(Vec), - Y(i32), - Z(Vec>), -} - -#[test] -fn generic_enum() { - assert_eq!( - GenericEnum::<(), (), ()>::decl(), - r#"type GenericEnum = { "A": A } | { "B": [B, B, B] } | { "C": Array } | { "D": Array>> } | { "E": { a: A, b: B, c: C, } } | { "X": Array } | { "Y": number } | { "Z": Array> };"# - ) -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct NewType(Vec>); - -#[test] -fn generic_newtype() { - assert_eq!( - NewType::<()>::decl(), - r#"type NewType = Array>;"# - ); -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct Tuple(T, Vec, Vec>); - -#[test] -fn generic_tuple() { - assert_eq!( - Tuple::<()>::decl(), - r#"type Tuple = [T, Array, Array>];"# - ); -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct Struct { - a: T, - b: (T, T), - c: (T, (T, T)), - d: [T; 3], - e: [(T, T); 3], - f: Vec, - g: Vec>, - h: Vec<[(T, T); 3]>, -} - -#[test] -fn generic_struct() { - assert_eq!( - Struct::<()>::decl(), - "type Struct = { a: T, b: [T, T], c: [T, [T, T]], d: [T, T, T], e: [[T, T], [T, T], [T, T]], f: Array, g: Array>, h: Array<[[T, T], [T, T], [T, T]]>, };" - ) -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct GenericInline { - t: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct ContainerInline { - g: GenericInline, - #[ts(inline)] - gi: GenericInline, - #[ts(flatten)] - t: GenericInline>, -} - -#[test] -fn inline() { - assert_eq!( - GenericInline::<()>::decl(), - "type GenericInline = { t: T, };" - ); - assert_eq!( - ContainerInline::decl(), - "type ContainerInline = { g: GenericInline, gi: { t: string, }, t: Array, };" - ); -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct GenericWithBounds { - t: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct ContainerWithBounds { - g: GenericWithBounds, - - #[ts(inline)] - gi: GenericWithBounds, - - #[ts(flatten)] - t: GenericWithBounds, -} - -#[test] -fn inline_with_bounds() { - assert_eq!( - GenericWithBounds::<&'static str>::decl(), - "type GenericWithBounds = { t: T, };" - ); - assert_eq!( - ContainerWithBounds::decl(), - "type ContainerWithBounds = { g: GenericWithBounds, gi: { t: string, }, t: number, };" - ); -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct GenericWithDefault { - t: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct ContainerWithDefault { - g: GenericWithDefault, - - #[ts(inline)] - gi: GenericWithDefault, - - #[ts(flatten)] - t: GenericWithDefault, -} - -#[test] -fn inline_with_default() { - assert_eq!( - GenericWithDefault::<()>::decl(), - "type GenericWithDefault = { t: T, };" - ); - assert_eq!( - ContainerWithDefault::decl(), - "type ContainerWithDefault = { g: GenericWithDefault, gi: { t: string, }, t: number, };" - ); -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct ADefault { - t: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct BDefault>> { - u: U, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct YDefault { - a1: ADefault, - a2: ADefault, -} - -#[test] -fn default() { - assert_eq!( - ADefault::<()>::decl(), - "type ADefault = { t: T, };" - ); - - assert_eq!( - BDefault::<()>::decl(), - "type BDefault | null> = { u: U, };" - ); - assert!(BDefault::<()>::dependencies() - .iter() - .any(|dep| dep.ts_name == "ADefault")); - - assert_eq!( - YDefault::decl(), - "type YDefault = { a1: ADefault, a2: ADefault, };" - ) -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct ATraitBounds { - t: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct BTraitBounds(T); - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -enum CTraitBounds { - A { t: T }, - B(T), - C, - D(T, K), -} - -// Types with const generics can't be exported -#[derive(TS)] -struct DTraitBounds { - t: [T; N], -} - -#[test] -fn trait_bounds() { - assert_eq!( - ATraitBounds::::decl(), - "type ATraitBounds = { t: T, };" - ); - - assert_eq!( - BTraitBounds::<&'static str>::decl(), - "type BTraitBounds = T;" - ); - - assert_eq!( - CTraitBounds::<&'static str, i32>::decl(), - r#"type CTraitBounds = { "A": { t: T, } } | { "B": T } | "C" | { "D": [T, K] };"# - ); - - let ty = format!( - "type DTraitBounds = {{ t: [{}], }};", - "T, ".repeat(41).trim_end_matches(", ") - ); - assert_eq!(DTraitBounds::<&str, 41>::decl(), ty) -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct T0 { - t0: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct P0 { - p0: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct T1 { - t0: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct P1 { - p0: T, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct Parent { - a: T1>, - b: T1>>>, - c: T1>, -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct GenericParent { - a_t: T1>, - b_t: T1>>>, - c_t: T1>, - a_null: T1>, - b_null: T1>>>, - c_null: T1>, -} - -#[test] -fn deeply_nested() { - assert_eq!( - Parent::inline(), - "{ a: T1>, b: T1>>>, c: T1>, }" - ); - assert_eq!( - GenericParent::<()>::decl(), - "type GenericParent = { \ - a_t: T1>, \ - b_t: T1>>>, \ - c_t: T1>, \ - a_null: T1>, \ - b_null: T1>>>, \ - c_null: T1>, \ - };" - ); -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct SomeType(String); - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -enum MyEnum { - VariantA(A), - VariantB(B), -} - -#[derive(TS)] -#[ts(export, export_to = "generics/")] -struct ParentEnum { - e: MyEnum, - #[ts(inline)] - e1: MyEnum, -} - -#[test] -fn inline_generic_enum() { - // This fails! - // The #[ts(inline)] seems to inline recursively, so not only the definition of `MyEnum`, but - // also the definition of `SomeType`. - assert_eq!( - ParentEnum::decl(), - "type ParentEnum = { \ - e: MyEnum, \ - e1: { \"VariantA\": number } | { \"VariantB\": SomeType }, \ - };" - ); -} +#![allow(clippy::box_collection, clippy::enum_variant_names, dead_code)] +#![allow(dead_code)] + +use std::{ + collections::{BTreeMap, HashSet}, + fmt::Debug, + rc::Rc, +}; + +use ts_rs::TS; + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct Generic +where + T: TS, +{ + value: T, + values: Vec, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct GenericAutoBound { + value: T, + values: Vec, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct GenericAutoBound2 +where + T: PartialEq, +{ + value: T, + values: Vec, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct Container { + foo: Generic, + bar: Box>>, + baz: Box>>>, +} + +macro_rules! declare { + ($(#[$meta:meta])* $name:ident { $($fident:ident: $t:ty),+ $(,)? }) => { + $(#[$meta])* + struct $name { + $(pub $fident: $t),+ + } + } +} + +declare! { + #[derive(TS)] + #[ts(export, export_to = "generics/")] + TypeGroup { + foo: Vec, + } +} + +#[test] +fn test() { + assert_eq!( + TypeGroup::decl(), + "type TypeGroup = { foo: Array, };", + ); + + assert_eq!( + Generic::<()>::decl(), + "type Generic = { value: T, values: Array, };" + ); + + assert_eq!( + GenericAutoBound::<()>::decl(), + "type GenericAutoBound = { value: T, values: Array, };" + ); + + assert_eq!( + GenericAutoBound2::<()>::decl(), + "type GenericAutoBound2 = { value: T, values: Array, };" + ); + + assert_eq!( + Container::decl(), + "type Container = { foo: Generic, bar: Array>, baz: { [key in string]?: Generic }, };" + ); +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +enum GenericEnum { + A(A), + B(B, B, B), + C(Vec), + D(Vec>>), + E { a: A, b: B, c: C }, + X(Vec), + Y(i32), + Z(Vec>), +} + +#[test] +fn generic_enum() { + assert_eq!( + GenericEnum::<(), (), ()>::decl(), + r#"type GenericEnum = { "A": A } | { "B": [B, B, B] } | { "C": Array } | { "D": Array>> } | { "E": { a: A, b: B, c: C, } } | { "X": Array } | { "Y": number } | { "Z": Array> };"# + ) +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct NewType(Vec>); + +#[test] +fn generic_newtype() { + assert_eq!( + NewType::<()>::decl(), + r#"type NewType = Array>;"# + ); +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct Tuple(T, Vec, Vec>); + +#[test] +fn generic_tuple() { + assert_eq!( + Tuple::<()>::decl(), + r#"type Tuple = [T, Array, Array>];"# + ); +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct Struct { + a: T, + b: (T, T), + c: (T, (T, T)), + d: [T; 3], + e: [(T, T); 3], + f: Vec, + g: Vec>, + h: Vec<[(T, T); 3]>, +} + +#[test] +fn generic_struct() { + assert_eq!( + Struct::<()>::decl(), + "type Struct = { a: T, b: [T, T], c: [T, [T, T]], d: [T, T, T], e: [[T, T], [T, T], [T, T]], f: Array, g: Array>, h: Array<[[T, T], [T, T], [T, T]]>, };" + ) +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct GenericInline { + t: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct ContainerInline { + g: GenericInline, + #[ts(inline)] + gi: GenericInline, + #[ts(flatten)] + t: GenericInline>, +} + +#[test] +fn inline() { + assert_eq!( + GenericInline::<()>::decl(), + "type GenericInline = { t: T, };" + ); + assert_eq!( + ContainerInline::decl(), + "type ContainerInline = { g: GenericInline, gi: { t: string, }, t: Array, };" + ); +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct GenericWithBounds { + t: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct ContainerWithBounds { + g: GenericWithBounds, + + #[ts(inline)] + gi: GenericWithBounds, + + #[ts(flatten)] + t: GenericWithBounds, +} + +#[test] +fn inline_with_bounds() { + assert_eq!( + GenericWithBounds::<&'static str>::decl(), + "type GenericWithBounds = { t: T, };" + ); + assert_eq!( + ContainerWithBounds::decl(), + "type ContainerWithBounds = { g: GenericWithBounds, gi: { t: string, }, t: number, };" + ); +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct GenericWithDefault { + t: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct ContainerWithDefault { + g: GenericWithDefault, + + #[ts(inline)] + gi: GenericWithDefault, + + #[ts(flatten)] + t: GenericWithDefault, +} + +#[test] +fn inline_with_default() { + assert_eq!( + GenericWithDefault::<()>::decl(), + "type GenericWithDefault = { t: T, };" + ); + assert_eq!( + ContainerWithDefault::decl(), + "type ContainerWithDefault = { g: GenericWithDefault, gi: { t: string, }, t: number, };" + ); +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct ADefault { + t: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct BDefault>> { + u: U, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct YDefault { + a1: ADefault, + a2: ADefault, +} + +#[test] +fn default() { + assert_eq!( + ADefault::<()>::decl(), + "type ADefault = { t: T, };" + ); + + assert_eq!( + BDefault::<()>::decl(), + "type BDefault | null> = { u: U, };" + ); + assert!(BDefault::<()>::dependencies() + .iter() + .any(|dep| dep.ts_name == "ADefault")); + + assert_eq!( + YDefault::decl(), + "type YDefault = { a1: ADefault, a2: ADefault, };" + ) +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct ATraitBounds { + t: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct BTraitBounds(T); + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +enum CTraitBounds { + A { t: T }, + B(T), + C, + D(T, K), +} + +// Types with const generics can't be exported +#[derive(TS)] +struct DTraitBounds { + t: [T; N], +} + +#[test] +fn trait_bounds() { + assert_eq!( + ATraitBounds::::decl(), + "type ATraitBounds = { t: T, };" + ); + + assert_eq!( + BTraitBounds::<&'static str>::decl(), + "type BTraitBounds = T;" + ); + + assert_eq!( + CTraitBounds::<&'static str, i32>::decl(), + r#"type CTraitBounds = { "A": { t: T, } } | { "B": T } | "C" | { "D": [T, K] };"# + ); + + let ty = format!( + "type DTraitBounds = {{ t: [{}], }};", + "T, ".repeat(41).trim_end_matches(", ") + ); + assert_eq!(DTraitBounds::<&str, 41>::decl(), ty) +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct T0 { + t0: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct P0 { + p0: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct T1 { + t0: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct P1 { + p0: T, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct Parent { + a: T1>, + b: T1>>>, + c: T1>, +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct GenericParent { + a_t: T1>, + b_t: T1>>>, + c_t: T1>, + a_null: T1>, + b_null: T1>>>, + c_null: T1>, +} + +#[test] +fn deeply_nested() { + assert_eq!( + Parent::inline(), + "{ a: T1>, b: T1>>>, c: T1>, }" + ); + assert_eq!( + GenericParent::<()>::decl(), + "type GenericParent = { \ + a_t: T1>, \ + b_t: T1>>>, \ + c_t: T1>, \ + a_null: T1>, \ + b_null: T1>>>, \ + c_null: T1>, \ + };" + ); +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct SomeType(String); + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +enum MyEnum { + VariantA(A), + VariantB(B), +} + +#[derive(TS)] +#[ts(export, export_to = "generics/")] +struct ParentEnum { + e: MyEnum, + #[ts(inline)] + e1: MyEnum, +} + +#[test] +fn inline_generic_enum() { + // This fails! + // The #[ts(inline)] seems to inline recursively, so not only the definition of `MyEnum`, but + // also the definition of `SomeType`. + assert_eq!( + ParentEnum::decl(), + "type ParentEnum = { \ + e: MyEnum, \ + e1: { \"VariantA\": number } | { \"VariantB\": SomeType }, \ + };" + ); +} diff --git a/ts-rs/tests/integration/hashmap.rs b/ts-rs/tests/integration/hashmap.rs index e6070b03a..6d662f192 100644 --- a/ts-rs/tests/integration/hashmap.rs +++ b/ts-rs/tests/integration/hashmap.rs @@ -1,72 +1,72 @@ -#![allow(dead_code)] - -use std::collections::{BTreeMap, HashMap, HashSet}; - -use ts_rs::TS; - -#[derive(TS)] -#[ts(export, export_to = "hashmap/")] -struct Hashes { - map: HashMap, - set: HashSet, -} - -#[test] -fn hashmap() { - assert_eq!( - Hashes::decl(), - "type Hashes = { map: { [key: string]: string }, set: Array, };" - ) -} - -struct CustomHasher {} - -type CustomHashMap = HashMap; -type CustomHashSet = HashSet; - -#[derive(TS)] -#[ts(export, export_to = "hashmap/")] -struct HashesHasher { - map: CustomHashMap, - set: CustomHashSet, -} - -#[test] -fn hashmap_with_custom_hasher() { - assert_eq!( - HashesHasher::decl(), - "type HashesHasher = { map: { [key: string]: string }, set: Array, };" - ) -} - -#[derive(TS, Eq, PartialEq, Hash)] -#[ts(export, export_to = "hashmap/")] -struct CustomKey(String); - -#[derive(TS)] -#[ts(export, export_to = "hashmap/")] -struct CustomValue; - -#[derive(TS)] -#[ts(export, export_to = "hashmap/")] -struct HashMapWithCustomTypes { - map: HashMap, -} - -#[derive(TS)] -#[ts(export, export_to = "hashmap/")] -struct BTreeMapWithCustomTypes { - map: BTreeMap, -} - -#[test] -fn with_custom_types() { - assert_eq!( - HashMapWithCustomTypes::inline(), - BTreeMapWithCustomTypes::inline() - ); - assert_eq!( - HashMapWithCustomTypes::decl(), - "type HashMapWithCustomTypes = { map: { [key: CustomKey]: CustomValue }, };" - ); -} +#![allow(dead_code)] + +use std::collections::{BTreeMap, HashMap, HashSet}; + +use ts_rs::TS; + +#[derive(TS)] +#[ts(export, export_to = "hashmap/")] +struct Hashes { + map: HashMap, + set: HashSet, +} + +#[test] +fn hashmap() { + assert_eq!( + Hashes::decl(), + "type Hashes = { map: { [key in string]?: string }, set: Array, };" + ) +} + +struct CustomHasher {} + +type CustomHashMap = HashMap; +type CustomHashSet = HashSet; + +#[derive(TS)] +#[ts(export, export_to = "hashmap/")] +struct HashesHasher { + map: CustomHashMap, + set: CustomHashSet, +} + +#[test] +fn hashmap_with_custom_hasher() { + assert_eq!( + HashesHasher::decl(), + "type HashesHasher = { map: { [key in string]?: string }, set: Array, };" + ) +} + +#[derive(TS, Eq, PartialEq, Hash)] +#[ts(export, export_to = "hashmap/")] +struct CustomKey(String); + +#[derive(TS)] +#[ts(export, export_to = "hashmap/")] +struct CustomValue; + +#[derive(TS)] +#[ts(export, export_to = "hashmap/")] +struct HashMapWithCustomTypes { + map: HashMap, +} + +#[derive(TS)] +#[ts(export, export_to = "hashmap/")] +struct BTreeMapWithCustomTypes { + map: BTreeMap, +} + +#[test] +fn with_custom_types() { + assert_eq!( + HashMapWithCustomTypes::inline(), + BTreeMapWithCustomTypes::inline() + ); + assert_eq!( + HashMapWithCustomTypes::decl(), + "type HashMapWithCustomTypes = { map: { [key in CustomKey]?: CustomValue }, };" + ); +} diff --git a/ts-rs/tests/integration/indexmap.rs b/ts-rs/tests/integration/indexmap.rs index 9af682a7b..cb5f88e8b 100644 --- a/ts-rs/tests/integration/indexmap.rs +++ b/ts-rs/tests/integration/indexmap.rs @@ -1,20 +1,20 @@ -#![allow(dead_code)] -#![cfg(feature = "indexmap-impl")] - -use indexmap::{IndexMap, IndexSet}; -use ts_rs::TS; - -#[derive(TS)] -#[ts(export, export_to = "indexmap/")] -struct Indexes { - map: IndexMap, - set: IndexSet, -} - -#[test] -fn indexmap() { - assert_eq!( - Indexes::decl(), - "type Indexes = { map: { [key: string]: string }, set: Array, };" - ) -} +#![allow(dead_code)] +#![cfg(feature = "indexmap-impl")] + +use indexmap::{IndexMap, IndexSet}; +use ts_rs::TS; + +#[derive(TS)] +#[ts(export, export_to = "indexmap/")] +struct Indexes { + map: IndexMap, + set: IndexSet, +} + +#[test] +fn indexmap() { + assert_eq!( + Indexes::decl(), + "type Indexes = { map: { [key in string]?: string }, set: Array, };" + ) +} diff --git a/ts-rs/tests/integration/issue_168.rs b/ts-rs/tests/integration/issue_168.rs index a82a580d8..732ba9bea 100644 --- a/ts-rs/tests/integration/issue_168.rs +++ b/ts-rs/tests/integration/issue_168.rs @@ -38,13 +38,13 @@ fn issue_168() { FooInlined::export_to_string().unwrap(), "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\ \n\ - export type FooInlined = { map: { [key: number]: { map: { [key: number]: { map: { [key: number]: string }, } }, } }, };\n" + export type FooInlined = { map: { [key in number]?: { map: { [key in number]?: { map: { [key in number]?: string }, } }, } }, };\n" ); assert_eq!( Foo::export_to_string().unwrap(), "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\ import type { Bar } from \"./Bar\";\n\ \n\ - export type Foo = { map: { [key: number]: Bar }, };\n" + export type Foo = { map: { [key in number]?: Bar }, };\n" ); } diff --git a/ts-rs/tests/integration/issue_338.rs b/ts-rs/tests/integration/issue_338.rs new file mode 100644 index 000000000..c50c94c75 --- /dev/null +++ b/ts-rs/tests/integration/issue_338.rs @@ -0,0 +1,37 @@ +use std::collections::HashMap; +use ts_rs::TS; + +#[derive(TS)] +#[ts(export, export_to = "issue_338/")] +pub struct MyType { + pub my_field_0: bool, + pub my_field_1: HashMap, +} + +#[derive(TS)] +#[ts(export, export_to = "issue_338/")] +pub enum MyEnum { + Variant0, + Variant1, + Variant2, + Variant3, +} + +#[derive(TS)] +#[ts(export, export_to = "issue_338/")] +pub struct MyStruct { + pub my_field_0: bool, + pub my_field_1: u32, + pub my_field_2: Option, + pub my_field_3: Option, + pub my_field_4: Option, + pub my_field_5: String, +} + +#[test] +fn test() { + assert_eq!( + MyType::inline(), + "{ my_field_0: boolean, my_field_1: { [key in MyEnum]?: MyStruct }, }" + ); +} diff --git a/ts-rs/tests/integration/issue_70.rs b/ts-rs/tests/integration/issue_70.rs index 4db0ee847..4078b9586 100644 --- a/ts-rs/tests/integration/issue_70.rs +++ b/ts-rs/tests/integration/issue_70.rs @@ -1,77 +1,77 @@ -#![allow(unused)] - -use std::collections::HashMap; - -use ts_rs::TS; - -type TypeAlias = HashMap; - -#[derive(TS)] -#[ts(export, export_to = "issue_70/")] -enum Enum { - A(TypeAlias), - B(HashMap), -} - -#[derive(TS)] -#[ts(export, export_to = "issue_70/")] -struct Struct { - a: TypeAlias, - b: HashMap, -} - -#[test] -fn issue_70() { - assert_eq!( - Enum::decl(), - "type Enum = { \"A\": { [key: string]: string } } | { \"B\": { [key: string]: string } };" - ); - assert_eq!( - Struct::decl(), - "type Struct = { a: { [key: string]: string }, b: { [key: string]: string }, };" - ); -} - -#[derive(TS)] -#[ts(export, export_to = "issue_70/")] -struct GenericType { - foo: T, - bar: U, -} - -type GenericAlias = GenericType<(A, String), Vec<(B, i32)>>; - -#[derive(TS)] -#[ts(export, export_to = "issue_70/")] -struct Container { - a: GenericAlias, Vec>, - b: GenericAlias, -} - -#[derive(TS)] -#[ts(export, export_to = "issue_70/")] -struct GenericContainer { - a: GenericAlias, - b: GenericAlias, - c: GenericAlias>, -} - -#[test] -fn generic() { - assert_eq!( - Container::decl(), - "type Container = { \ - a: GenericType<[Array, string], Array<[Array, number]>>, \ - b: GenericType<[string, string], Array<[string, number]>>, \ - };" - ); - - assert_eq!( - GenericContainer::<(), ()>::decl(), - "type GenericContainer = { \ - a: GenericType<[string, string], Array<[string, number]>>, \ - b: GenericType<[A, string], Array<[B, number]>>, \ - c: GenericType<[A, string], Array<[GenericType<[A, string], Array<[B, number]>>, number]>>, \ - };" - ); -} +#![allow(unused)] + +use std::collections::HashMap; + +use ts_rs::TS; + +type TypeAlias = HashMap; + +#[derive(TS)] +#[ts(export, export_to = "issue_70/")] +enum Enum { + A(TypeAlias), + B(HashMap), +} + +#[derive(TS)] +#[ts(export, export_to = "issue_70/")] +struct Struct { + a: TypeAlias, + b: HashMap, +} + +#[test] +fn issue_70() { + assert_eq!( + Enum::decl(), + "type Enum = { \"A\": { [key in string]?: string } } | { \"B\": { [key in string]?: string } };" + ); + assert_eq!( + Struct::decl(), + "type Struct = { a: { [key in string]?: string }, b: { [key in string]?: string }, };" + ); +} + +#[derive(TS)] +#[ts(export, export_to = "issue_70/")] +struct GenericType { + foo: T, + bar: U, +} + +type GenericAlias = GenericType<(A, String), Vec<(B, i32)>>; + +#[derive(TS)] +#[ts(export, export_to = "issue_70/")] +struct Container { + a: GenericAlias, Vec>, + b: GenericAlias, +} + +#[derive(TS)] +#[ts(export, export_to = "issue_70/")] +struct GenericContainer { + a: GenericAlias, + b: GenericAlias, + c: GenericAlias>, +} + +#[test] +fn generic() { + assert_eq!( + Container::decl(), + "type Container = { \ + a: GenericType<[Array, string], Array<[Array, number]>>, \ + b: GenericType<[string, string], Array<[string, number]>>, \ + };" + ); + + assert_eq!( + GenericContainer::<(), ()>::decl(), + "type GenericContainer = { \ + a: GenericType<[string, string], Array<[string, number]>>, \ + b: GenericType<[A, string], Array<[B, number]>>, \ + c: GenericType<[A, string], Array<[GenericType<[A, string], Array<[B, number]>>, number]>>, \ + };" + ); +} diff --git a/ts-rs/tests/integration/lifetimes.rs b/ts-rs/tests/integration/lifetimes.rs index 93f0cee9f..41ec73a26 100644 --- a/ts-rs/tests/integration/lifetimes.rs +++ b/ts-rs/tests/integration/lifetimes.rs @@ -1,36 +1,36 @@ -#![allow(dead_code)] - -use ts_rs::TS; - -#[derive(TS)] -#[ts(export, export_to = "lifetimes/")] -struct S<'a> { - s: &'a str, -} - -#[derive(TS)] -#[ts(export, export_to = "lifetimes/")] -struct B<'a, T: 'a> { - a: &'a T, -} - -#[derive(TS)] -#[ts(export, export_to = "lifetimes/")] -struct A<'a> { - a: &'a &'a &'a Vec, //Multiple References - b: &'a Vec>, //Nesting - c: &'a std::collections::HashMap, //Multiple type args -} - -#[test] -fn contains_borrow() { - assert_eq!(S::decl(), "type S = { s: string, };") -} - -#[test] -fn contains_borrow_type_args() { - assert_eq!( - A::decl(), - "type A = { a: Array, b: Array>, c: { [key: string]: boolean }, };" - ); -} +#![allow(dead_code)] + +use ts_rs::TS; + +#[derive(TS)] +#[ts(export, export_to = "lifetimes/")] +struct S<'a> { + s: &'a str, +} + +#[derive(TS)] +#[ts(export, export_to = "lifetimes/")] +struct B<'a, T: 'a> { + a: &'a T, +} + +#[derive(TS)] +#[ts(export, export_to = "lifetimes/")] +struct A<'a> { + a: &'a &'a &'a Vec, //Multiple References + b: &'a Vec>, //Nesting + c: &'a std::collections::HashMap, //Multiple type args +} + +#[test] +fn contains_borrow() { + assert_eq!(S::decl(), "type S = { s: string, };") +} + +#[test] +fn contains_borrow_type_args() { + assert_eq!( + A::decl(), + "type A = { a: Array, b: Array>, c: { [key in string]?: boolean }, };" + ); +} diff --git a/ts-rs/tests/integration/main.rs b/ts-rs/tests/integration/main.rs index 59ba72888..b905527f7 100644 --- a/ts-rs/tests/integration/main.rs +++ b/ts-rs/tests/integration/main.rs @@ -25,6 +25,7 @@ mod issue_168; mod issue_232; mod issue_308; mod issue_317; +mod issue_338; mod issue_70; mod issue_80; mod leading_colon; diff --git a/ts-rs/tests/integration/self_referential.rs b/ts-rs/tests/integration/self_referential.rs index 067f00766..0df808b56 100644 --- a/ts-rs/tests/integration/self_referential.rs +++ b/ts-rs/tests/integration/self_referential.rs @@ -1,188 +1,188 @@ -#![allow(dead_code)] -use std::{collections::HashMap, sync::Arc}; - -#[cfg(feature = "serde-compat")] -use serde::Serialize; -use ts_rs::TS; - -#[derive(TS)] -#[ts(export, export_to = "self_referential/")] -struct HasT { - t: &'static T<'static>, -} - -#[derive(TS)] -#[ts(export, export_to = "self_referential/")] -struct T<'a> { - t_box: Box>, - self_box: Box, - - t_ref: &'a T<'a>, - self_ref: &'a Self, - - t_arc: Arc>, - self_arc: Arc, - - #[ts(inline)] - has_t: HasT, -} - -#[test] -fn named() { - assert_eq!( - T::decl(), - "type T = { \ - t_box: T, \ - self_box: T, \ - t_ref: T, \ - self_ref: T, \ - t_arc: T, \ - self_arc: T, \ - has_t: { t: T, }, \ - };" - ); -} - -#[derive(TS)] -#[ts(export, export_to = "self_referential/", rename = "E")] -enum ExternallyTagged { - A(Box), - B(&'static ExternallyTagged), - C(Box), - D(&'static Self), - E( - Box, - Box, - &'static ExternallyTagged, - &'static Self, - ), - F { - a: Box, - b: &'static ExternallyTagged, - c: HashMap, - d: Option>, - #[ts(optional = nullable)] - e: Option>, - #[ts(optional)] - f: Option>, - }, - - G( - Vec, - [&'static ExternallyTagged; 1024], - HashMap, - ), -} - -#[test] -fn enum_externally_tagged() { - assert_eq!( - ExternallyTagged::decl(), - "type E = { \"A\": E } | \ - { \"B\": E } | \ - { \"C\": E } | \ - { \"D\": E } | \ - { \"E\": [E, E, E, E] } | \ - { \"F\": { a: E, b: E, c: { [key: string]: E }, d: E | null, e?: E | null, f?: E, } } | \ - { \"G\": [Array, Array, { [key: string]: E }] };" - ); -} - -#[derive(TS)] -#[cfg_attr(feature = "serde-compat", derive(Serialize))] -#[ts(rename = "I")] -#[cfg_attr(feature = "serde-compat", serde(tag = "tag"))] -#[cfg_attr(not(feature = "serde-compat"), ts(tag = "tag"))] -enum InternallyTagged { - A(Box), - B(&'static InternallyTagged), - C(Box), - D(&'static Self), - E(Vec), - F { - a: Box, - b: &'static InternallyTagged, - c: HashMap, - d: Option<&'static InternallyTagged>, - #[ts(optional = nullable)] - e: Option<&'static InternallyTagged>, - #[ts(optional)] - f: Option<&'static InternallyTagged>, - }, -} - -// NOTE: The generated type is actually not valid TS here, since the indirections rust enforces for recursive types -// gets lost during the translation to TypeScript (e.g "Box" => "T"). -#[test] -fn enum_internally_tagged() { - assert_eq!( - InternallyTagged::decl(), - "type I = { \"tag\": \"A\" } & I | \ - { \"tag\": \"B\" } & I | \ - { \"tag\": \"C\" } & I | \ - { \"tag\": \"D\" } & I | \ - { \"tag\": \"E\" } & Array | \ - { \"tag\": \"F\", a: I, b: I, c: { [key: I]: I }, d: I | null, e?: I | null, f?: I, };" - ); -} - -#[derive(TS)] -#[cfg_attr(feature = "serde-compat", derive(Serialize))] -#[ts(export, export_to = "self_referential/", rename = "A")] -#[cfg_attr(feature = "serde-compat", serde(tag = "tag", content = "content"))] -#[cfg_attr(not(feature = "serde-compat"), ts(tag = "tag", content = "content"))] -enum AdjacentlyTagged { - A(Box), - B(&'static AdjacentlyTagged), - C(Box), - D(&'static Self), - E(Vec), - F { - a: Box, - b: &'static AdjacentlyTagged, - c: HashMap, - d: Option<&'static AdjacentlyTagged>, - #[ts(optional = nullable)] - e: Option<&'static AdjacentlyTagged>, - #[ts(optional)] - f: Option<&'static AdjacentlyTagged>, - }, - G( - Vec, - [&'static AdjacentlyTagged; 4], - HashMap, - ), -} - -// NOTE: The generated type is actually not valid TS here, since the indirections rust enforces for recursive types -// gets lost during the translation to TypeScript (e.g "Box" => "T"). -#[test] -fn enum_adjacently_tagged() { - assert_eq!( - AdjacentlyTagged::decl(), - "type A = { \"tag\": \"A\", \"content\": A } | \ - { \"tag\": \"B\", \"content\": A } | \ - { \"tag\": \"C\", \"content\": A } | \ - { \"tag\": \"D\", \"content\": A } | \ - { \"tag\": \"E\", \"content\": Array } | \ - { \ - \"tag\": \"F\", \ - \"content\": { \ - a: A, \ - b: A, \ - c: { [key: string]: A }, \ - d: A | null, \ - e?: A | null, \ - f?: A, \ - } \ - } | \ - { \ - \"tag\": \"G\", \ - \"content\": [\ - Array, \ - [A, A, A, A], \ - { [key: string]: A }\ - ] \ - };" - ); -} +#![allow(dead_code)] +use std::{collections::HashMap, sync::Arc}; + +#[cfg(feature = "serde-compat")] +use serde::Serialize; +use ts_rs::TS; + +#[derive(TS)] +#[ts(export, export_to = "self_referential/")] +struct HasT { + t: &'static T<'static>, +} + +#[derive(TS)] +#[ts(export, export_to = "self_referential/")] +struct T<'a> { + t_box: Box>, + self_box: Box, + + t_ref: &'a T<'a>, + self_ref: &'a Self, + + t_arc: Arc>, + self_arc: Arc, + + #[ts(inline)] + has_t: HasT, +} + +#[test] +fn named() { + assert_eq!( + T::decl(), + "type T = { \ + t_box: T, \ + self_box: T, \ + t_ref: T, \ + self_ref: T, \ + t_arc: T, \ + self_arc: T, \ + has_t: { t: T, }, \ + };" + ); +} + +#[derive(TS)] +#[ts(export, export_to = "self_referential/", rename = "E")] +enum ExternallyTagged { + A(Box), + B(&'static ExternallyTagged), + C(Box), + D(&'static Self), + E( + Box, + Box, + &'static ExternallyTagged, + &'static Self, + ), + F { + a: Box, + b: &'static ExternallyTagged, + c: HashMap, + d: Option>, + #[ts(optional = nullable)] + e: Option>, + #[ts(optional)] + f: Option>, + }, + + G( + Vec, + [&'static ExternallyTagged; 1024], + HashMap, + ), +} + +#[test] +fn enum_externally_tagged() { + assert_eq!( + ExternallyTagged::decl(), + "type E = { \"A\": E } | \ + { \"B\": E } | \ + { \"C\": E } | \ + { \"D\": E } | \ + { \"E\": [E, E, E, E] } | \ + { \"F\": { a: E, b: E, c: { [key in string]?: E }, d: E | null, e?: E | null, f?: E, } } | \ + { \"G\": [Array, Array, { [key in string]?: E }] };" + ); +} + +#[derive(TS)] +#[cfg_attr(feature = "serde-compat", derive(Serialize))] +#[ts(rename = "I")] +#[cfg_attr(feature = "serde-compat", serde(tag = "tag"))] +#[cfg_attr(not(feature = "serde-compat"), ts(tag = "tag"))] +enum InternallyTagged { + A(Box), + B(&'static InternallyTagged), + C(Box), + D(&'static Self), + E(Vec), + F { + a: Box, + b: &'static InternallyTagged, + c: HashMap, + d: Option<&'static InternallyTagged>, + #[ts(optional = nullable)] + e: Option<&'static InternallyTagged>, + #[ts(optional)] + f: Option<&'static InternallyTagged>, + }, +} + +// NOTE: The generated type is actually not valid TS here, since the indirections rust enforces for recursive types +// gets lost during the translation to TypeScript (e.g "Box" => "T"). +#[test] +fn enum_internally_tagged() { + assert_eq!( + InternallyTagged::decl(), + "type I = { \"tag\": \"A\" } & I | \ + { \"tag\": \"B\" } & I | \ + { \"tag\": \"C\" } & I | \ + { \"tag\": \"D\" } & I | \ + { \"tag\": \"E\" } & Array | \ + { \"tag\": \"F\", a: I, b: I, c: { [key in I]?: I }, d: I | null, e?: I | null, f?: I, };" + ); +} + +#[derive(TS)] +#[cfg_attr(feature = "serde-compat", derive(Serialize))] +#[ts(export, export_to = "self_referential/", rename = "A")] +#[cfg_attr(feature = "serde-compat", serde(tag = "tag", content = "content"))] +#[cfg_attr(not(feature = "serde-compat"), ts(tag = "tag", content = "content"))] +enum AdjacentlyTagged { + A(Box), + B(&'static AdjacentlyTagged), + C(Box), + D(&'static Self), + E(Vec), + F { + a: Box, + b: &'static AdjacentlyTagged, + c: HashMap, + d: Option<&'static AdjacentlyTagged>, + #[ts(optional = nullable)] + e: Option<&'static AdjacentlyTagged>, + #[ts(optional)] + f: Option<&'static AdjacentlyTagged>, + }, + G( + Vec, + [&'static AdjacentlyTagged; 4], + HashMap, + ), +} + +// NOTE: The generated type is actually not valid TS here, since the indirections rust enforces for recursive types +// gets lost during the translation to TypeScript (e.g "Box" => "T"). +#[test] +fn enum_adjacently_tagged() { + assert_eq!( + AdjacentlyTagged::decl(), + "type A = { \"tag\": \"A\", \"content\": A } | \ + { \"tag\": \"B\", \"content\": A } | \ + { \"tag\": \"C\", \"content\": A } | \ + { \"tag\": \"D\", \"content\": A } | \ + { \"tag\": \"E\", \"content\": Array } | \ + { \ + \"tag\": \"F\", \ + \"content\": { \ + a: A, \ + b: A, \ + c: { [key in string]?: A }, \ + d: A | null, \ + e?: A | null, \ + f?: A, \ + } \ + } | \ + { \ + \"tag\": \"G\", \ + \"content\": [\ + Array, \ + [A, A, A, A], \ + { [key in string]?: A }\ + ] \ + };" + ); +} diff --git a/ts-rs/tests/integration/serde_json.rs b/ts-rs/tests/integration/serde_json.rs index 29e32c786..fc0a113b5 100644 --- a/ts-rs/tests/integration/serde_json.rs +++ b/ts-rs/tests/integration/serde_json.rs @@ -1,65 +1,65 @@ -#![cfg(feature = "serde_json")] -#![allow(unused)] - -use ts_rs::TS; - -#[derive(TS)] -#[ts(export, export_to = "serde_json_impl/")] -struct UsingSerdeJson { - num: serde_json::Number, - map1: serde_json::Map, - map2: serde_json::Map, - map3: serde_json::Map>, - map4: serde_json::Map, - map5: serde_json::Map, - any: serde_json::Value, -} - -#[test] -fn using_serde_json() { - assert_eq!(serde_json::Number::inline(), "number"); - assert_eq!( - serde_json::Map::::inline(), - "{ [key: string]: number }" - ); - assert_eq!( - serde_json::Value::decl(), - "type JsonValue = number | string | Array | { [key: string]: JsonValue };", - ); - - assert_eq!( - UsingSerdeJson::decl(), - "type UsingSerdeJson = { \ - num: number, \ - map1: { [key: string]: number }, \ - map2: { [key: string]: UsingSerdeJson }, \ - map3: { [key: string]: { [key: string]: number } }, \ - map4: { [key: string]: number }, \ - map5: { [key: string]: JsonValue }, \ - any: JsonValue, \ - };" - ) -} - -#[derive(TS)] -#[ts(export, export_to = "serde_json_impl/")] -struct InlinedValue { - #[ts(inline)] - any: serde_json::Value, -} - -#[test] -fn inlined_value() { - assert_eq!( - InlinedValue::decl(), - "type InlinedValue = { \ - any: number | string | Array | { [key: string]: JsonValue }, \ - };" - ); -} - -#[derive(TS)] -#[ts(export, export_to = "serde_json_impl/")] -struct Simple { - json: serde_json::Value, -} +#![cfg(feature = "serde_json")] +#![allow(unused)] + +use ts_rs::TS; + +#[derive(TS)] +#[ts(export, export_to = "serde_json_impl/")] +struct UsingSerdeJson { + num: serde_json::Number, + map1: serde_json::Map, + map2: serde_json::Map, + map3: serde_json::Map>, + map4: serde_json::Map, + map5: serde_json::Map, + any: serde_json::Value, +} + +#[test] +fn using_serde_json() { + assert_eq!(serde_json::Number::inline(), "number"); + assert_eq!( + serde_json::Map::::inline(), + "{ [key in string]?: number }" + ); + assert_eq!( + serde_json::Value::decl(), + "type JsonValue = number | string | Array | { [key in string]?: JsonValue };", + ); + + assert_eq!( + UsingSerdeJson::decl(), + "type UsingSerdeJson = { \ + num: number, \ + map1: { [key in string]?: number }, \ + map2: { [key in string]?: UsingSerdeJson }, \ + map3: { [key in string]?: { [key in string]?: number } }, \ + map4: { [key in string]?: number }, \ + map5: { [key in string]?: JsonValue }, \ + any: JsonValue, \ + };" + ) +} + +#[derive(TS)] +#[ts(export, export_to = "serde_json_impl/")] +struct InlinedValue { + #[ts(inline)] + any: serde_json::Value, +} + +#[test] +fn inlined_value() { + assert_eq!( + InlinedValue::decl(), + "type InlinedValue = { \ + any: number | string | Array | { [key in string]?: JsonValue }, \ + };" + ); +} + +#[derive(TS)] +#[ts(export, export_to = "serde_json_impl/")] +struct Simple { + json: serde_json::Value, +}