Skip to content

Commit

Permalink
refactor(semantic): reusing the same reference (#4529)
Browse files Browse the repository at this point in the history
A minor improvement
  • Loading branch information
Dunqing committed Jul 29, 2024
1 parent c6a11be commit d914b14
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d914b14

Please sign in to comment.