Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(semantic): reusing the same reference #4529

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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