Skip to content

Commit

Permalink
add & use NonEmptyStack::first
Browse files Browse the repository at this point in the history
  • Loading branch information
branchseer committed Jan 25, 2025
1 parent 9729ad2 commit 154d4c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 14 additions & 0 deletions crates/oxc_data_structures/src/stack/non_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ impl<T> NonEmptyStack<T> {
Self { cursor: start, start, end }
}

/// Get reference to first value on stack.
#[inline]
pub fn first(&self) -> &T {
// SAFETY: All methods ensure `self.start` always points to a valid initialized `T`
unsafe { self.start.as_ref() }
}

/// Get mutable reference to first value on stack.
#[inline]
pub fn first_mut(&mut self) -> &mut T {
// SAFETY: All methods ensure `self.start` always points to a valid initialized `T`
unsafe { self.start.as_mut() }
}

/// Get reference to last value on stack.
#[inline]
pub fn last(&self) -> &T {
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_transformer/src/typescript/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,7 @@ impl IdentifierReferenceRename<'_, '_> {
// }
// }
// ```
//
// `NonEmptyStack` guarantees that the stack is not empty.
*self.scope_stack.first().unwrap() == symbol_scope_id
*self.scope_stack.first() == symbol_scope_id
// The resolved symbol is declared outside the enum,
// and we have checked that the name exists in previous_enum_members:
//
Expand Down

0 comments on commit 154d4c5

Please sign in to comment.