Skip to content

Commit

Permalink
fix(semantic): reference flags not correctly resolved when after an e…
Browse files Browse the repository at this point in the history
…xport stmt
  • Loading branch information
camc314 committed Dec 26, 2024
1 parent 6b51e6d commit 8f63540
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,14 @@ fn test() {
// ",
// None,
// ),
(
"import { Bar } from './bar';
export type { Baz } from './baz';
export class Foo extends Bar {}
",
None,
),
];

let fail = vec![
Expand Down
7 changes: 6 additions & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ impl<'a> SemanticBuilder<'a> {
let symbol_flags = self.symbols.get_flags(symbol_id);
references.retain(|&reference_id| {
let reference = &mut self.symbols.references[reference_id];

let flags = reference.flags_mut();

// Determine the symbol whether can be referenced by this reference.
Expand Down Expand Up @@ -1880,6 +1879,9 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
if let Some(with_clause) = &it.with_clause {
self.visit_with_clause(with_clause);
}
if it.source.is_some() {
mem::take(&mut self.current_reference_flags);
}
self.leave_node(kind);
}

Expand Down Expand Up @@ -2117,7 +2119,9 @@ impl<'a> SemanticBuilder<'a> {
}

fn reference_identifier(&mut self, ident: &IdentifierReference<'a>) {
// println!("SemanticBuilder >> reference_identifier {} {:?} ", &ident.name, ident.span);
let flags = self.resolve_reference_usages();
// dbg!(&flags);
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 All @@ -2126,6 +2130,7 @@ impl<'a> SemanticBuilder<'a> {
/// Resolve reference flags for the current ast node.
#[inline]
fn resolve_reference_usages(&mut self) -> ReferenceFlags {
// dbg!(self.current_reference_flags.is_empty());
if self.current_reference_flags.is_empty() {
ReferenceFlags::Read
} else {
Expand Down

0 comments on commit 8f63540

Please sign in to comment.