diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 0781d7c6..d2f4b216 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -206,17 +206,25 @@ fn merge(original_contents: String, new_contents: String) -> String { let new_decl = new_decl.trim_matches('\n'); - let new_decl_start = new_decl.find(DECLARATION_START).unwrap() + DECLARATION_START.len(); - let new_decl_end = new_decl_start + new_decl[new_decl_start..].find(' ').unwrap(); - let new_decl_name = &new_decl[new_decl_start..new_decl_end]; + let new_decl_name = new_decl + .split(DECLARATION_START) + .nth(1) + .unwrap() + .split_whitespace() + .next() + .unwrap(); let original_decls = original_decls.split("\n\n").map(|x| x.trim_matches('\n')); let mut inserted = false; for decl in original_decls { - let decl_start = decl.find(DECLARATION_START).unwrap() + DECLARATION_START.len(); - let decl_end = decl_start + decl[decl_start..].find(' ').unwrap(); - let decl_name = &decl[decl_start..decl_end]; + let decl_name = decl + .split(DECLARATION_START) + .nth(1) + .unwrap() + .split_whitespace() + .next() + .unwrap(); if inserted || decl_name < new_decl_name { buffer.push('\n'); diff --git a/ts-rs/tests/integration/same_file_export.rs b/ts-rs/tests/integration/same_file_export.rs index 48ba0a31..3a9eaeec 100644 --- a/ts-rs/tests/integration/same_file_export.rs +++ b/ts-rs/tests/integration/same_file_export.rs @@ -13,40 +13,21 @@ struct DepB { } #[derive(TS)] -#[ts(export_to = "same_file_export/types.ts")] +#[ts(export, export_to = "same_file_export/types.ts")] struct A { foo: DepA, } #[derive(TS)] -#[ts(export_to = "same_file_export/types.ts")] +#[ts(export, export_to = "same_file_export/types.ts")] struct B { foo: DepB, } #[derive(TS)] -#[ts(export_to = "same_file_export/types.ts")] +#[ts(export, export_to = "same_file_export/types.ts")] struct C { foo: DepA, bar: DepB, biz: B, } - -#[test] -fn all_types_exported() { - A::export_all().unwrap(); - B::export_all().unwrap(); - C::export_all().unwrap(); - - let contents = std::fs::read_to_string(&A::default_output_path().unwrap()).unwrap(); - - if cfg!(feature = "format") { - assert!(contents.contains("export type A = { foo: DepA }")); - assert!(contents.contains("export type B = { foo: DepB }")); - assert!(contents.contains("export type C = { foo: DepA; bar: DepB; biz: B }")); - } else { - assert!(contents.contains(&A::decl())); - assert!(contents.contains(&B::decl())); - assert!(contents.contains(&C::decl())); - } -}