Skip to content

Commit

Permalink
refactor(syntax): turn the AstNodeId::dummy into a constant field. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Jul 16, 2024
1 parent 96af459 commit fc0b17d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_cfg/tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn labeled_statement_with_multiple_loops_continue_and_break() {
cfg.ctx(None).default().allow_break().allow_continue();
cfg.ctx(None).mark_break(c2).mark_continue(c2).resolve_with_upper_label();

cfg.append_break(AstNodeId::dummy(), A);
cfg.append_break(AstNodeId::DUMMY, A);

// labeled block end
cfg.ctx(A).mark_break(labeled).resolve();
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a> SemanticBuilder<'a> {
/// # Panics
pub fn build(mut self, program: &Program<'a>) -> SemanticBuilderReturn<'a> {
if self.source_type.is_typescript_definition() {
let scope_id = self.scope.add_scope(None, AstNodeId::dummy(), ScopeFlags::Top);
let scope_id = self.scope.add_scope(None, AstNodeId::DUMMY, ScopeFlags::Top);
program.scope_id.set(Some(scope_id));
} else {
self.visit_program(program);
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<'a> SemanticBuilder<'a> {
#[inline]
fn record_ast_nodes(&mut self) {
if self.cfg.is_some() {
self.ast_node_records.push(AstNodeId::dummy());
self.ast_node_records.push(AstNodeId::DUMMY);
}
}

Expand All @@ -273,7 +273,7 @@ impl<'a> SemanticBuilder<'a> {
// <https://github.com/oxc-project/oxc/pull/4273>
if self.cfg.is_some() {
if let Some(record) = self.ast_node_records.last_mut() {
if *record == AstNodeId::dummy() {
if *record == AstNodeId::DUMMY {
*record = self.current_node_id;
}
}
Expand Down
5 changes: 1 addition & 4 deletions crates/oxc_syntax/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ define_index_type! {
}

impl AstNodeId {
#[inline]
pub fn dummy() -> Self {
Self::new(0)
}
pub const DUMMY: Self = AstNodeId::from_raw_unchecked(0);
}

#[cfg(feature = "serialize")]
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl TraverseScoping {
/// `flags` provided are amended to inherit from parent scope's flags.
pub fn create_scope_child_of_current(&mut self, flags: ScopeFlags) -> ScopeId {
let flags = self.scopes.get_new_scope_flags(flags, self.current_scope_id);
self.scopes.add_scope(Some(self.current_scope_id), AstNodeId::dummy(), flags)
self.scopes.add_scope(Some(self.current_scope_id), AstNodeId::DUMMY, flags)
}

/// Insert a scope into scope tree below a statement.
Expand Down Expand Up @@ -268,7 +268,7 @@ impl TraverseScoping {
flag: ReferenceFlag,
) -> ReferenceId {
let reference =
Reference::new_with_symbol_id(SPAN, name, AstNodeId::dummy(), symbol_id, flag);
Reference::new_with_symbol_id(SPAN, name, AstNodeId::DUMMY, symbol_id, flag);
let reference_id = self.symbols.create_reference(reference);
self.symbols.resolved_references[symbol_id].push(reference_id);
reference_id
Expand Down Expand Up @@ -297,7 +297,7 @@ impl TraverseScoping {
name: CompactStr,
flag: ReferenceFlag,
) -> ReferenceId {
let reference = Reference::new(SPAN, name.clone(), AstNodeId::dummy(), flag);
let reference = Reference::new(SPAN, name.clone(), AstNodeId::DUMMY, flag);
let reference_id = self.symbols.create_reference(reference);
self.scopes.add_root_unresolved_reference(name, reference_id);
reference_id
Expand Down

0 comments on commit fc0b17d

Please sign in to comment.