Skip to content

Commit 47417bb

Browse files
authored
Merge pull request #215 from Yoric/entropy-window
Fix: Generated AST library pops interfaces even in case of error
2 parents cbee020 + c29824b commit 47417bb

File tree

1 file changed

+13
-7
lines changed
  • crates/binjs_generate_library/src

1 file changed

+13
-7
lines changed

crates/binjs_generate_library/src/lib.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl<'a, W> Serialization<W, &'a {name}> for Serializer<W> where W: TokenWriter
603603
.map(|case| {
604604
format!(
605605
" {name}::{constructor}(box ref value) => {{
606-
// Path will be updated in by the serializer for this tagged tuple.
606+
// Path will be updated by the serializer for this tagged tuple.
607607
(self as &mut Serialization<W, &'a {constructor}>).serialize(value, path)
608608
}}",
609609
name = name,
@@ -1078,8 +1078,12 @@ impl<'a, W> Serialization<W, &'a {name}> for Serializer<W> where W: TokenWriter
10781078
10791079
self.writer.enter_tagged_tuple_at(&interface_name, &field_names, path)?;
10801080
path.enter_interface(interface_name.clone());
1081+
let result = loop {{ // Fake loop, used only to be able to `break` early.
10811082
{fields}
1083+
break Ok(());
1084+
}};
10821085
path.exit_interface(interface_name.clone());
1086+
result?;
10831087
self.writer.exit_tagged_tuple_at(&interface_name, &field_names, path)?;
10841088
10851089
Ok(())
@@ -1101,12 +1105,14 @@ impl<'a, W> Serialization<W, &'a {name}> for Serializer<W> where W: TokenWriter
11011105
.enumerate()
11021106
.map(|(index, field)| format!(
11031107
"
1104-
let field_name = FieldName::from_str(\"{field_name}\");
1105-
let path_item = ({index}, field_name.clone()); // String is shared
1106-
path.enter_field(path_item.clone());
1107-
let result = (self as &mut Serialization<W, &'a _>).serialize(&value.{rust_field_name}, path);
1108-
path.exit_field(path_item);
1109-
result?;",
1108+
let field_name = FieldName::from_str(\"{field_name}\");
1109+
let path_item = ({index}, field_name.clone()); // String is shared
1110+
path.enter_field(path_item.clone());
1111+
let result = (self as &mut Serialization<W, &'a _>).serialize(&value.{rust_field_name}, path);
1112+
path.exit_field(path_item);
1113+
if let Err(err) = result {{
1114+
break Err(err); // Break with error
1115+
}}",
11101116
index = index,
11111117
field_name = field.name().to_str(),
11121118
rust_field_name = field.name().to_rust_identifier_case()))

0 commit comments

Comments
 (0)