Skip to content

Commit

Permalink
Attempt to fix duplicated NOTE
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavo-shigueo committed Jul 24, 2024
1 parent bc10807 commit 25434df
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn export_and_merge(path: PathBuf, type_name: String, generated_type: String) ->

let buffer = merge(original_contents, generated_type);

file.seek(SeekFrom::Start(NOTE.len() as u64))?;
file.seek(SeekFrom::Start(0))?;

file.write_all(buffer.as_bytes())?;
file.sync_all()?;
Expand Down Expand Up @@ -195,10 +195,12 @@ fn merge(original_contents: String, new_contents: String) -> String {
.collect::<BTreeSet<_>>();

let import_len = imports.iter().map(|&x| x.len()).sum::<usize>() + imports.len();
let capacity = import_len + original_decls.len() + new_decl.len() + 2;
let capacity = NOTE.len() + import_len + original_decls.len() + new_decl.len() + 2;

let mut buffer = String::with_capacity(capacity);

buffer.push_str(NOTE);

for import in imports {
buffer.push_str(import);
buffer.push('\n')
Expand Down

0 comments on commit 25434df

Please sign in to comment.