Skip to content

Commit

Permalink
refactor(ast): rename IdentifierReference::new_with_reference_id (#…
Browse files Browse the repository at this point in the history
…5157)

The old name `new_read` no longer makes sense as it doesn't set a read-only flag any more, since `flags` field was removed from `IdentifierReference`.
  • Loading branch information
overlookmotel committed Aug 24, 2024
1 parent 22d57f9 commit 960e1d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,17 @@ impl<'a> Hash for IdentifierReference<'a> {
}

impl<'a> IdentifierReference<'a> {
#[inline]
pub fn new(span: Span, name: Atom<'a>) -> Self {
Self { span, name, reference_id: Cell::default() }
}

pub fn new_read(span: Span, name: Atom<'a>, reference_id: Option<ReferenceId>) -> Self {
#[inline]
pub fn new_with_reference_id(
span: Span,
name: Atom<'a>,
reference_id: Option<ReferenceId>,
) -> Self {
Self { span, name, reference_id: Cell::new(reference_id) }
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/react/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ fn get_read_identifier_reference<'a>(
) -> IdentifierReference<'a> {
let reference_id =
ctx.create_reference_in_current_scope(name.to_compact_str(), ReferenceFlags::Read);
IdentifierReference::new_read(span, name, Some(reference_id))
IdentifierReference::new_with_reference_id(span, name, Some(reference_id))
}

fn create_static_member_expression<'a>(
Expand Down
6 changes: 5 additions & 1 deletion crates/oxc_transformer/src/typescript/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,11 @@ impl<'a> Assignment<'a> {
// Creates `this.name = name`
fn create_this_property_assignment(&self, ctx: &mut TraverseCtx<'a>) -> Statement<'a> {
let reference_id = ctx.create_bound_reference(self.symbol_id, ReferenceFlags::Read);
let id = IdentifierReference::new_read(self.span, self.name.clone(), Some(reference_id));
let id = IdentifierReference::new_with_reference_id(
self.span,
self.name.clone(),
Some(reference_id),
);

ctx.ast.statement_expression(
SPAN,
Expand Down

0 comments on commit 960e1d5

Please sign in to comment.