Skip to content

Commit b4f689c

Browse files
committed
object_tree: Make implementation DRYer
Extract common code applying default property values into a function.
1 parent 3784830 commit b4f689c

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

internal/compiler/object_tree.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -749,15 +749,7 @@ impl Element {
749749
diag,
750750
);
751751

752-
if let Type::Builtin(builtin_base) = &r.base_type {
753-
for (prop, info) in &builtin_base.properties {
754-
if let Some(expr) = &info.default_value {
755-
r.bindings
756-
.entry(prop.clone())
757-
.or_insert_with(|| RefCell::new(expr.clone().into()));
758-
}
759-
}
760-
}
752+
apply_default_type_properties(&mut r);
761753

762754
for sig_decl in node.CallbackDeclaration() {
763755
let name =
@@ -1233,6 +1225,21 @@ impl Element {
12331225
}
12341226
}
12351227

1228+
/// Apply default property values defined in `builtins.60` to the element.
1229+
fn apply_default_type_properties(element: &mut Element) {
1230+
// Apply default property values on top:
1231+
if let Type::Builtin(builtin_base) = &element.base_type {
1232+
for (prop, info) in &builtin_base.properties {
1233+
if let Some(expr) = &info.default_value {
1234+
element
1235+
.bindings
1236+
.entry(prop.clone())
1237+
.or_insert_with(|| RefCell::new(expr.clone().into()));
1238+
}
1239+
}
1240+
}
1241+
}
1242+
12361243
/// Create a Type for this node
12371244
pub fn type_from_node(
12381245
node: syntax_nodes::Type,
@@ -1302,6 +1309,9 @@ fn animation_element_from_node(
13021309
}),
13031310
diag,
13041311
);
1312+
1313+
apply_default_type_properties(&mut anim_element);
1314+
13051315
Some(Rc::new(RefCell::new(anim_element)))
13061316
}
13071317
}

0 commit comments

Comments
 (0)