diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 983a1e14c..58b74e717 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/CHANGELOG.md b/CHANGELOG.md index 1bc7f5eda..07ba3267c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,14 @@ # master +### Breaking +### 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 @@ -22,6 +32,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 5310ff96e..74d91808f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,9 +29,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[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", @@ -42,18 +42,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" @@ -72,47 +72,48 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys", @@ -120,36 +121,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.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3e3e06ec6ac7d893a0db7127d91063ad7d9da8988f8a1a256f03729e6eec026" +checksum = "f9184f2b369b3e8625712493c89b785881f27eedc6cde480a81883cef78868b2" 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.72", ] [[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 = "backtrace" @@ -183,10 +175,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", @@ -195,9 +189,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" @@ -213,9 +207,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", @@ -234,9 +228,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", ] @@ -249,9 +243,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" [[package]] name = "cargo-ts" @@ -263,9 +257,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.94" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" [[package]] name = "cfg-if" @@ -275,9 +269,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", @@ -290,9 +284,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.4" +version = "4.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "8f6b81fb3c84f5563d509c59b5a48d935f689e993afa90fe39047f05adef9142" dependencies = [ "clap_builder", "clap_derive", @@ -300,9 +294,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "5ca6706fd5224857d9ac5eb9355f6683563cc0541c7cd9d014043b57cbec78ac" dependencies = [ "anstream", "anstyle", @@ -312,21 +306,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.4" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "color-eyre" @@ -357,9 +351,9 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "core-foundation-sys" @@ -367,12 +361,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" @@ -381,9 +369,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", @@ -397,15 +385,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", @@ -433,9 +422,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", @@ -458,9 +447,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", @@ -473,9 +462,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", @@ -490,9 +479,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "equivalent" @@ -531,13 +520,13 @@ dependencies = [ [[package]] name = "from_variant" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a0b11eeb173ce52f84ebd943d42e58813a2ebb78a6a3ff0a243b71c5199cd7b" +checksum = "32016f1242eb82af5474752d00fd8ebcd9004bd69b462b1c91de833972d08ed4" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.48", + "syn 2.0.72", ] [[package]] @@ -548,9 +537,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", @@ -565,18 +554,18 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[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", @@ -584,14 +573,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", ] @@ -609,9 +595,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", @@ -623,9 +609,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", @@ -662,9 +648,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[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", @@ -680,100 +666,106 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[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", ] [[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" -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.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[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 = "miniz_oxide" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] [[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.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" 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", ] @@ -795,9 +787,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "ordered-float" -version = "3.9.2" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" +checksum = "19ff2cf528c6c03d9ed653d6c4ce1dc0582dc4af309790ad92f07c1cd551b0be" dependencies = [ "num-traits", ] @@ -844,7 +836,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] [[package]] @@ -858,9 +850,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" @@ -876,9 +868,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -894,9 +886,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", ] @@ -939,9 +931,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", @@ -951,9 +943,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", @@ -962,15 +954,15 @@ 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-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" @@ -978,20 +970,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" @@ -999,52 +982,46 @@ 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.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[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", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "indexmap", "itoa", @@ -1069,9 +1046,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" @@ -1084,15 +1061,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" @@ -1120,14 +1088,14 @@ 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.72", ] [[package]] @@ -1138,9 +1106,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[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", @@ -1150,9 +1118,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", @@ -1175,9 +1143,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", @@ -1193,9 +1161,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", @@ -1221,25 +1189,25 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] [[package]] name = "swc_macros_common" -version = "0.3.9" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50176cfc1cbc8bb22f41c6fe9d1ec53fbe057001219b5954961b8ad0f336fce9" +checksum = "f486687bfb7b5c560868f69ed2d458b880cebc9babebcb67e49f31b55c5bf847" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] [[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", @@ -1247,15 +1215,15 @@ dependencies = [ [[package]] name = "swc_visit_macros" -version = "0.5.11" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33fc817055fe127b4285dc85058596768bfde7537ae37da82c67815557f03e33" +checksum = "92807d840959f39c60ce8a774a3f83e8193c658068e6d270dbe0a05e40e90b41" dependencies = [ "Inflector", "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.48", + "syn 2.0.72", ] [[package]] @@ -1271,9 +1239,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -1306,22 +1274,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] [[package]] @@ -1336,12 +1304,13 @@ dependencies = [ [[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", @@ -1356,18 +1325,19 @@ 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", ] [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -1397,7 +1367,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] [[package]] @@ -1433,9 +1403,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", @@ -1443,7 +1413,7 @@ dependencies = [ [[package]] name = "ts-rs" -version = "8.1.0" +version = "9.0.1" dependencies = [ "bigdecimal", "bson", @@ -1464,11 +1434,11 @@ dependencies = [ [[package]] name = "ts-rs-macros" -version = "8.1.0" +version = "9.0.1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", "termcolor", ] @@ -1486,9 +1456,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" @@ -1498,24 +1468,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", @@ -1525,15 +1495,15 @@ dependencies = [ [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.7.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" dependencies = [ "getrandom", "serde", @@ -1559,9 +1529,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", @@ -1569,24 +1539,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.72", "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", @@ -1594,22 +1564,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.72", "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" @@ -1629,11 +1599,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]] @@ -1662,13 +1632,14 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", + "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", @@ -1677,45 +1648,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "wyz" @@ -1728,20 +1705,20 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.72", ] 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 9144abf4e..98fa642a3 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.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 10609e914..75360fdca 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -157,7 +157,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 47cb1c25a..150280066 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.1" authors = ["Moritz Bischof "] edition = "2021" license = "MIT" @@ -44,7 +44,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.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/src/export.rs b/ts-rs/src/export.rs index 4f2b970a7..770126a13 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -171,6 +171,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/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/src/lib.rs b/ts-rs/src/lib.rs index a422c5942..efa128aca 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 @@ -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/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/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/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/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/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/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 d4f687e94..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 }, } }, } }, };" + 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 }, };" + export type Foo = { map: { [key in 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" ); } 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/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 6eeef9f8b..b905527f7 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; @@ -23,6 +24,8 @@ mod infer_as; mod issue_168; mod issue_232; mod issue_308; +mod issue_317; +mod issue_338; mod issue_70; mod issue_80; mod leading_colon; @@ -59,4 +62,3 @@ mod union_with_data; mod union_with_internal_tag; mod unit; mod r#unsized; -mod issue_317; 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, +}