Skip to content

Commit

Permalink
refactor(linter, mangler, parser, semantic, transformer, traverse, wa…
Browse files Browse the repository at this point in the history
…sm): rename various `flag` vars to `flags` (#5028)

Part of #4991.
  • Loading branch information
overlookmotel committed Aug 21, 2024
1 parent 3b7de18 commit ca70cc7
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 72 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl Rule for NoDuplicateHead {
return;
}

let flag = symbols.get_flag(symbol_id);
if !flag.is_import() {
let flags = symbols.get_flag(symbol_id);
if !flags.is_import() {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_mangler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ impl Mangler {
) -> Vec<SlotFrequency> {
let mut frequencies = vec![SlotFrequency::default(); total_number_of_slots];
for (symbol_id, slot) in slots.iter_enumerated() {
let symbol_flag = symbol_table.get_flag(symbol_id);
let symbol_flags = symbol_table.get_flag(symbol_id);
// omit renaming `export { x }`
if !symbol_flag.is_variable() || symbol_flag.is_export() {
if !symbol_flags.is_variable() || symbol_flags.is_export() {
continue;
}
let index = *slot;
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_parser/src/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ impl<'a> ParserImpl<'a> {
let mut modifiers = self.ast.vec();
while self.at_modifier() {
let span = self.start_span();
let modifier_flag = self.cur_kind().into();
let modifier_flags = self.cur_kind().into();
let kind = self.cur_kind();
self.bump_any();
let modifier = self.modifier(kind, self.end_span(span))?;
self.check_for_duplicate_modifiers(flags, &modifier);
flags.set(modifier_flag, true);
flags.set(modifier_flags, true);
modifiers.push(modifier);
}
Ok(Modifiers::new(modifiers, flags))
Expand Down
10 changes: 5 additions & 5 deletions crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> {

// Collect all scopes where variable hoisting can occur
for scope_id in builder.scope.ancestors(target_scope_id) {
let flag = builder.scope.get_flags(scope_id);
if flag.is_var() {
let flags = builder.scope.get_flags(scope_id);
if flags.is_var() {
target_scope_id = scope_id;
break;
}
Expand Down Expand Up @@ -181,10 +181,10 @@ impl<'a> Binder<'a> for Function<'a> {
if let Some(AstKind::ObjectProperty(prop)) =
builder.nodes.parent_kind(builder.current_node_id)
{
let flag = builder.scope.get_flags_mut(current_scope_id);
let flags = builder.scope.get_flags_mut(current_scope_id);
match prop.kind {
PropertyKind::Get => *flag |= ScopeFlags::GetAccessor,
PropertyKind::Set => *flag |= ScopeFlags::SetAccessor,
PropertyKind::Get => *flags |= ScopeFlags::GetAccessor,
PropertyKind::Set => *flags |= ScopeFlags::SetAccessor,
PropertyKind::Init => {}
};
}
Expand Down
22 changes: 11 additions & 11 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ impl<'a> SemanticBuilder<'a> {
self.current_scope_flags().is_strict_mode()
}

pub(crate) fn set_function_node_flag(&mut self, flag: NodeFlags) {
pub(crate) fn set_function_node_flag(&mut self, flags: NodeFlags) {
if let Some(current_function) = self.function_stack.last() {
*self.nodes.get_node_mut(*current_function).flags_mut() |= flag;
*self.nodes.get_node_mut(*current_function).flags_mut() |= flags;
}
}

Expand Down Expand Up @@ -464,20 +464,20 @@ impl<'a> SemanticBuilder<'a> {
// If unresolved, transfer it to parent scope's unresolved references.
let bindings = self.scope.get_bindings(self.current_scope_id);
if let Some(symbol_id) = bindings.get(name.as_str()).copied() {
let symbol_flag = self.symbols.get_flag(symbol_id);
let symbol_flags = self.symbols.get_flag(symbol_id);

let resolved_references = &mut self.symbols.resolved_references[symbol_id];

references.retain(|&reference_id| {
let reference = &mut self.symbols.references[reference_id];
let flag = reference.flags();
if flag.is_type() && symbol_flag.can_be_referenced_by_type()
|| flag.is_value() && symbol_flag.can_be_referenced_by_value()
|| flag.is_ts_type_query() && symbol_flag.is_import()
let flags = reference.flags();
if flags.is_type() && symbol_flags.can_be_referenced_by_type()
|| flags.is_value() && symbol_flags.can_be_referenced_by_value()
|| flags.is_ts_type_query() && symbol_flags.is_import()
{
// The non type-only ExportSpecifier can reference a type/value symbol,
// If the symbol is a value symbol and reference flag is not type-only, remove the type flag.
if symbol_flag.is_value() && !flag.is_type_only() {
if symbol_flags.is_value() && !flags.is_type_only() {
*reference.flags_mut() -= ReferenceFlags::Type;
} else {
// If the symbol is a type symbol and reference flag is not type-only, remove the value flag.
Expand All @@ -487,7 +487,7 @@ impl<'a> SemanticBuilder<'a> {
// import type { T } from './mod'; type A = typeof T
// ^ can reference type-only import
// If symbol is type-import, we need to replace the ReferenceFlags::Value with ReferenceFlags::Type
if flag.is_ts_type_query() && symbol_flag.is_type_import() {
if flags.is_ts_type_query() && symbol_flags.is_type_import() {
*reference.flags_mut() -= ReferenceFlags::Value;
*reference.flags_mut() |= ReferenceFlags::Type;
}
Expand Down Expand Up @@ -2004,8 +2004,8 @@ impl<'a> SemanticBuilder<'a> {
}

fn reference_identifier(&mut self, ident: &IdentifierReference<'a>) {
let flag = self.resolve_reference_usages();
let reference = Reference::new(self.current_node_id, flag);
let flags = self.resolve_reference_usages();
let reference = Reference::new(self.current_node_id, flags);
let reference_id = self.declare_reference(ident.name.clone(), reference);
ident.reference_id.set(Some(reference_id));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_semantic/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ impl SymbolTable {
&mut self,
span: Span,
name: CompactStr,
flag: SymbolFlags,
flags: SymbolFlags,
scope_id: ScopeId,
node_id: AstNodeId,
) -> SymbolId {
self.spans.push(span);
self.names.push(name);
self.flags.push(flag);
self.flags.push(flags);
self.scope_ids.push(scope_id);
self.declarations.push(node_id);
self.resolved_references.push(vec![]);
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_semantic/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ fn get_scope_snapshot(semantic: &Semantic, scopes: impl Iterator<Item = ScopeId>
if index != 0 {
result.push(',');
}
let flag = semantic.scopes().get_flags(scope_id);
let flags = semantic.scopes().get_flags(scope_id);
result.push('{');
if let Some(child_ids) = semantic.scopes().get_child_ids(scope_id) {
result.push_str("\"children\":");
result.push_str(&get_scope_snapshot(semantic, child_ids.iter().copied()));
result.push(',');
}
result.push_str(format!("\"flag\": \"{flag:?}\",").as_str());
result.push_str(format!("\"flag\": \"{flags:?}\",").as_str());
result.push_str(format!("\"id\": {},", scope_id.index()).as_str());
result.push_str(
format!(
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_transformer/src/es2016/exponentiation_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl<'a> ExponentiationOperator<'a> {
) -> IdentifierReference<'a> {
let reference = ctx.symbols().get_reference(ident.reference_id.get().unwrap());
let symbol_id = reference.symbol_id();
let flag = reference.flags();
ctx.create_reference_id(ident.span, ident.name.clone(), symbol_id, flag)
let flags = reference.flags();
ctx.create_reference_id(ident.span, ident.name.clone(), symbol_id, flags)
}

fn clone_expression(expr: &Expression<'a>, ctx: &mut TraverseCtx<'a>) -> Expression<'a> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ impl<'a> LogicalAssignmentOperators<'a> {
) -> IdentifierReference<'a> {
let reference = ctx.symbols().get_reference(ident.reference_id.get().unwrap());
let symbol_id = reference.symbol_id();
let flag = reference.flags();
ctx.create_reference_id(ident.span, ident.name.clone(), symbol_id, flag)
let flags = reference.flags();
ctx.create_reference_id(ident.span, ident.name.clone(), symbol_id, flags)
}

pub fn maybe_generate_memoised(
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_transformer/src/helpers/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ impl<'a> BoundIdentifier<'a> {
pub fn create_spanned_reference(
&self,
span: Span,
flag: ReferenceFlags,
flags: ReferenceFlags,
ctx: &mut TraverseCtx<'a>,
) -> IdentifierReference<'a> {
ctx.create_bound_reference_id(span, self.name.clone(), self.symbol_id, flag)
ctx.create_bound_reference_id(span, self.name.clone(), self.symbol_id, flags)
}
}
32 changes: 16 additions & 16 deletions crates/oxc_traverse/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ impl<'a> TraverseCtx<'a> {
pub fn create_bound_reference(
&mut self,
symbol_id: SymbolId,
flag: ReferenceFlags,
flags: ReferenceFlags,
) -> ReferenceId {
self.scoping.create_bound_reference(symbol_id, flag)
self.scoping.create_bound_reference(symbol_id, flags)
}

/// Create an `IdentifierReference` bound to a `SymbolId`.
Expand All @@ -333,9 +333,9 @@ impl<'a> TraverseCtx<'a> {
span: Span,
name: Atom<'a>,
symbol_id: SymbolId,
flag: ReferenceFlags,
flags: ReferenceFlags,
) -> IdentifierReference<'a> {
self.scoping.create_bound_reference_id(span, name, symbol_id, flag)
self.scoping.create_bound_reference_id(span, name, symbol_id, flags)
}

/// Create an unbound reference.
Expand All @@ -344,9 +344,9 @@ impl<'a> TraverseCtx<'a> {
pub fn create_unbound_reference(
&mut self,
name: CompactStr,
flag: ReferenceFlags,
flags: ReferenceFlags,
) -> ReferenceId {
self.scoping.create_unbound_reference(name, flag)
self.scoping.create_unbound_reference(name, flags)
}

/// Create an unbound `IdentifierReference`.
Expand All @@ -356,9 +356,9 @@ impl<'a> TraverseCtx<'a> {
&mut self,
span: Span,
name: Atom<'a>,
flag: ReferenceFlags,
flags: ReferenceFlags,
) -> IdentifierReference<'a> {
self.scoping.create_unbound_reference_id(span, name, flag)
self.scoping.create_unbound_reference_id(span, name, flags)
}

/// Create a reference optionally bound to a `SymbolId`.
Expand All @@ -371,9 +371,9 @@ impl<'a> TraverseCtx<'a> {
&mut self,
name: CompactStr,
symbol_id: Option<SymbolId>,
flag: ReferenceFlags,
flags: ReferenceFlags,
) -> ReferenceId {
self.scoping.create_reference(name, symbol_id, flag)
self.scoping.create_reference(name, symbol_id, flags)
}

/// Create an `IdentifierReference` optionally bound to a `SymbolId`.
Expand All @@ -387,9 +387,9 @@ impl<'a> TraverseCtx<'a> {
span: Span,
name: Atom<'a>,
symbol_id: Option<SymbolId>,
flag: ReferenceFlags,
flags: ReferenceFlags,
) -> IdentifierReference<'a> {
self.scoping.create_reference_id(span, name, symbol_id, flag)
self.scoping.create_reference_id(span, name, symbol_id, flags)
}

/// Create reference in current scope, looking up binding for `name`,
Expand All @@ -398,9 +398,9 @@ impl<'a> TraverseCtx<'a> {
pub fn create_reference_in_current_scope(
&mut self,
name: CompactStr,
flag: ReferenceFlags,
flags: ReferenceFlags,
) -> ReferenceId {
self.scoping.create_reference_in_current_scope(name, flag)
self.scoping.create_reference_in_current_scope(name, flags)
}

/// Clone `IdentifierReference` based on the original reference's `SymbolId` and name.
Expand All @@ -413,9 +413,9 @@ impl<'a> TraverseCtx<'a> {
pub fn clone_identifier_reference(
&mut self,
ident: &IdentifierReference<'a>,
flag: ReferenceFlags,
flags: ReferenceFlags,
) -> IdentifierReference<'a> {
self.scoping.clone_identifier_reference(ident, flag)
self.scoping.clone_identifier_reference(ident, flags)
}
}

Expand Down
Loading

0 comments on commit ca70cc7

Please sign in to comment.