Skip to content

Commit

Permalink
fix(semantic): add interfaces and functions to `SymbolFlags::ClassExc…
Browse files Browse the repository at this point in the history
…ludes` (#6057)

This brings ClassExcludes into alignment with TypeScript.
  • Loading branch information
DonIsaac committed Sep 27, 2024
1 parent 93d509d commit 933a743
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions crates/oxc_semantic/tests/integration/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,18 @@ fn test_module_like_declarations() {
"A symbol should not be created for global augmentation declarations."
);
}

#[test]
fn test_class_merging() {
// classes can be merged with interfaces, resulting in a single symbol
SemanticTester::ts(
"
class Foo {}
interface Foo {}
",
)
.has_root_symbol("Foo")
.contains_flags(SymbolFlags::Class)
.contains_flags(SymbolFlags::Interface)
.test();
}
6 changes: 4 additions & 2 deletions crates/oxc_syntax/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ bitflags! {
const Ambient = 1 << 19;

const Enum = Self::ConstEnum.bits() | Self::RegularEnum.bits();

const Variable = Self::FunctionScopedVariable.bits() | Self::BlockScopedVariable.bits();

const BlockScoped = Self::BlockScopedVariable.bits() | Self::Enum.bits() | Self::Class.bits();

const Value = Self::Variable.bits() | Self::Class.bits() | Self::Enum.bits() | Self::EnumMember.bits() | Self::ValueModule.bits();
const Type = Self::Class.bits() | Self::Interface.bits() | Self::Enum.bits() | Self::EnumMember.bits() | Self::TypeLiteral.bits() | Self::TypeParameter.bits() | Self::TypeAlias.bits();

Expand All @@ -113,7 +115,7 @@ bitflags! {
/// they can not merge with anything in the value space
const BlockScopedVariableExcludes = Self::Value.bits();

const ClassExcludes = (Self::Value.bits() | Self::TypeAlias.bits()) & !Self::ValueModule.bits() ;
const ClassExcludes = (Self::Value.bits() | Self::TypeAlias.bits()) & !(Self::ValueModule.bits() | Self::Interface.bits() | Self::Function.bits());
const ImportBindingExcludes = Self::Import.bits() | Self::TypeImport.bits();
// Type specific excludes
const TypeAliasExcludes = Self::Type.bits();
Expand Down

0 comments on commit 933a743

Please sign in to comment.