chore: current_scope always panics

This commit is contained in:
Jonathan Kelley committed 2022-02-03 00:35:10 -05:00
1 parent f7b3228ab2
commit 1913ccd61f
1 file changed
+6 -8
+6 -8
View File
@@ -208,9 +208,7 @@ impl<'b> DiffState<'b> {
{ {
self.mutations.create_element(tag_name, *namespace, real_id); self.mutations.create_element(tag_name, *namespace, real_id);
let cur_scope_id = self let cur_scope_id = self.current_scope();
.current_scope()
.expect("diffing should always have a scope");
for listener in listeners.iter() { for listener in listeners.iter() {
listener.mounted_node.set(Some(real_id)); listener.mounted_node.set(Some(real_id));
@@ -235,7 +233,7 @@ impl<'b> DiffState<'b> {
} }
fn create_component_node(&mut self, vcomponent: &'b VComponent<'b>) -> usize { fn create_component_node(&mut self, vcomponent: &'b VComponent<'b>) -> usize {
let parent_idx = self.current_scope().unwrap(); let parent_idx = self.current_scope();
// the component might already exist - if it does, we need to reuse it // the component might already exist - if it does, we need to reuse it
// this makes figure out when to drop the component more complicated // this makes figure out when to drop the component more complicated
@@ -401,7 +399,8 @@ impl<'b> DiffState<'b> {
// We also need to make sure that all listeners are properly attached to the parent scope (fix_listener) // We also need to make sure that all listeners are properly attached to the parent scope (fix_listener)
// //
// TODO: take a more efficient path than this // TODO: take a more efficient path than this
if let Some(cur_scope_id) = self.current_scope() { let cur_scope_id = self.current_scope();
if old.listeners.len() == new.listeners.len() { if old.listeners.len() == new.listeners.len() {
for (old_l, new_l) in old.listeners.iter().zip(new.listeners.iter()) { for (old_l, new_l) in old.listeners.iter().zip(new.listeners.iter()) {
if old_l.event != new_l.event { if old_l.event != new_l.event {
@@ -421,7 +420,6 @@ impl<'b> DiffState<'b> {
self.mutations.new_event_listener(listener, cur_scope_id); self.mutations.new_event_listener(listener, cur_scope_id);
} }
} }
}
match (old.children.len(), new.children.len()) { match (old.children.len(), new.children.len()) {
(0, 0) => {} (0, 0) => {}
@@ -1057,8 +1055,8 @@ impl<'b> DiffState<'b> {
self.mutations.insert_before(first, created as u32); self.mutations.insert_before(first, created as u32);
} }
fn current_scope(&self) -> Option<ScopeId> { fn current_scope(&self) -> ScopeId {
self.scope_stack.last().copied() self.scope_stack.last().copied().expect("no current scope")
} }
fn enter_scope(&mut self, scope: ScopeId) { fn enter_scope(&mut self, scope: ScopeId) {