Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions crates/oxc_isolated_declarations/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'a> ScopeTree<'a> {

fn add_reference(&mut self, name: Atom<'a>, flags: KindFlags) {
let scope = self.levels.last_mut().unwrap();
scope.references.insert(name, flags);
scope.references.entry(name).and_modify(|f| *f |= flags).or_insert(flags);
}

/// Resolve references in the current scope, and propagate unresolved ones.
Expand All @@ -84,7 +84,10 @@ impl<'a> ScopeTree<'a> {
});

// Merge unresolved references to the parent scope.
self.levels.last_mut().unwrap().references.extend(current_references);
let parent_scope = self.levels.last_mut().unwrap();
for (name, flags) in current_references {
parent_scope.references.entry(name).and_modify(|f| *f |= flags).or_insert(flags);
}
}
}

Expand Down
19 changes: 18 additions & 1 deletion crates/oxc_isolated_declarations/tests/fixtures/shadowed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@ type Module = () => void;
namespace Module {
export const x = 1;
}
export type ModuleType = Module;
export type ModuleType = Module;

// https://github.com/oxc-project/oxc/issues/10996
// Variable emit should not be dropped when variable is shadowed as a type name
// and the type is part of a class implements interface
export interface Thing<T> {}

const Test1 = 'test1' as const;
export type Test1 = typeof Test1;
export class Class1 {
readonly id: 'test1' = Test1;
}

const Test2 = 'test2' as const;
export type Test2 = typeof Test2;
export class Class2 implements Thing<Test2> {
readonly id: 'test2' = Test2;
}
14 changes: 14 additions & 0 deletions crates/oxc_isolated_declarations/tests/snapshots/shadowed.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@ declare namespace Module {
const x = 1;
}
export type ModuleType = Module;
// https://github.com/oxc-project/oxc/issues/10996
// Variable emit should not be dropped when variable is shadowed as a type name
// and the type is part of a class implements interface
export interface Thing<T> {}
declare const Test1: "test1";
export type Test1 = typeof Test1;
export declare class Class1 {
readonly id: "test1";
}
declare const Test2: "test2";
export type Test2 = typeof Test2;
export declare class Class2 implements Thing<Test2> {
readonly id: "test2";
}
export {};
Loading