Skip to content

Commit

Permalink
feat(transformer): add methods to BoundIdentifier (#4897)
Browse files Browse the repository at this point in the history
`BoundIdentifier` helper previously only had methods to create a
read-only `IdentifierReference`. Add methods to also create write-only
or read-write `IdentifierReference`s.
  • Loading branch information
overlookmotel authored Aug 14, 2024
1 parent 97e38cd commit 1e6d0fe
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion crates/oxc_transformer/src/helpers/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,49 @@ impl<'a> BoundIdentifier<'a> {
span: Span,
ctx: &mut TraverseCtx<'a>,
) -> IdentifierReference<'a> {
ctx.create_bound_reference_id(span, self.name.clone(), self.symbol_id, ReferenceFlag::Read)
self.create_spanned_reference(span, ReferenceFlag::Read, ctx)
}

/// Create `IdentifierReference` referencing this binding, which is written to, with dummy `Span`
pub fn create_write_reference(&self, ctx: &mut TraverseCtx<'a>) -> IdentifierReference<'a> {
self.create_spanned_write_reference(SPAN, ctx)
}

/// Create `IdentifierReference` referencing this binding, which is written to, with specified `Span`
pub fn create_spanned_write_reference(
&self,
span: Span,
ctx: &mut TraverseCtx<'a>,
) -> IdentifierReference<'a> {
self.create_spanned_reference(span, ReferenceFlag::Write, ctx)
}

/// Create `IdentifierReference` referencing this binding, which is read from + written to,
/// with dummy `Span`
pub fn create_read_write_reference(
&self,
ctx: &mut TraverseCtx<'a>,
) -> IdentifierReference<'a> {
self.create_spanned_read_write_reference(SPAN, ctx)
}

/// Create `IdentifierReference` referencing this binding, which is read from + written to,
/// with specified `Span`
pub fn create_spanned_read_write_reference(
&self,
span: Span,
ctx: &mut TraverseCtx<'a>,
) -> IdentifierReference<'a> {
self.create_spanned_reference(span, ReferenceFlag::Read | ReferenceFlag::Write, ctx)
}

/// Create `IdentifierReference` referencing this binding, with specified `Span` and `ReferenceFlag`
pub fn create_spanned_reference(
&self,
span: Span,
flag: ReferenceFlag,
ctx: &mut TraverseCtx<'a>,
) -> IdentifierReference<'a> {
ctx.create_bound_reference_id(span, self.name.clone(), self.symbol_id, flag)
}
}

0 comments on commit 1e6d0fe

Please sign in to comment.