From d914b14275eb1bda923bedcccc3bedeaf1bbc59d Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:16:27 +0000 Subject: [PATCH] refactor(semantic): reusing the same reference (#4529) A minor improvement --- crates/oxc_semantic/src/builder.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 5fb8865f972f4..5b0337ca308c5 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -438,25 +438,25 @@ impl<'a> SemanticBuilder<'a> { || flag.is_value() && symbol_flag.can_be_referenced_by_value() || flag.is_ts_type_query() && symbol_flag.is_import() { + let reference = &mut self.symbols.references[*id]; // 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() { - *self.symbols.references[*id].flag_mut() -= ReferenceFlag::Type; + *reference.flag_mut() -= ReferenceFlag::Type; } else { // If the symbol is a type symbol and reference flag is not type-only, remove the value flag. - *self.symbols.references[*id].flag_mut() -= ReferenceFlag::Value; + *reference.flag_mut() -= ReferenceFlag::Value; } // import type { T } from './mod'; type A = typeof T // ^ can reference type-only import // If symbol is type-import, we need to replace the ReferenceFlag::Value with ReferenceFlag::Type if flag.is_ts_type_query() && symbol_flag.is_type_import() { - let reference_flag = self.symbols.references[*id].flag_mut(); - *reference_flag -= ReferenceFlag::Value; - *reference_flag |= ReferenceFlag::Type; + *reference.flag_mut() -= ReferenceFlag::Value; + *reference.flag_mut() |= ReferenceFlag::Type; } - self.symbols.references[*id].set_symbol_id(symbol_id); + reference.set_symbol_id(symbol_id); resolved_references.push(*id); false } else {