Skip to content

Commit

Permalink
refactor(semantic): remove Ambient symbol flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuiRuTian committed Jan 14, 2025
1 parent 4ac2e99 commit 462811d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
7 changes: 3 additions & 4 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,13 @@ impl NoUnusedVars {

fn should_skip_symbol(symbol: &Symbol<'_, '_>) -> bool {
const AMBIENT_NAMESPACE_FLAGS: SymbolFlags =
SymbolFlags::NameSpaceModule.union(SymbolFlags::Ambient);
SymbolFlags::NameSpaceModule;

let flags = symbol.flags();

// 1. ignore enum members. Only enums get checked
// 2. ignore all ambient TS declarations, e.g. `declare class Foo {}`
if flags.intersects(SymbolFlags::EnumMember.union(SymbolFlags::Ambient))
// ambient namespaces
|| flags == AMBIENT_NAMESPACE_FLAGS
if flags.intersects(SymbolFlags::EnumMember)
|| (symbol.is_in_ts() && symbol.is_in_declare_global())
{
return true;
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,10 @@ impl<'a> Binder<'a> for TSModuleDeclaration<'a> {

// At declaration time a module has no value declaration it is only when a value declaration
// is made inside a the scope of a module that the symbol is modified
let ambient = if self.declare { SymbolFlags::Ambient } else { SymbolFlags::None };
let symbol_id = builder.declare_symbol(
self.id.span(),
self.id.name().as_str(),
SymbolFlags::NameSpaceModule | ambient,
SymbolFlags::NameSpaceModule,
SymbolFlags::None,
);

Expand Down
4 changes: 0 additions & 4 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,10 +2110,6 @@ impl<'a> SemanticBuilder<'a> {
continue;
};

// Ambient modules cannot be value modules
if self.symbols.get_flags(symbol_id).intersects(SymbolFlags::Ambient) {
continue;
}
self.symbols.union_flag(symbol_id, SymbolFlags::ValueModule);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/oxc_semantic/tests/main.rs
assertion_line: 147
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/ts-module/import.ts
snapshot_kind: text
---
[
{
Expand All @@ -27,7 +27,7 @@ snapshot_kind: text
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(NameSpaceModule | Ambient)",
"flags": "SymbolFlags(NameSpaceModule)",
"id": 0,
"name": "foo",
"node": "TSModuleDeclaration(foo)",
Expand Down
6 changes: 2 additions & 4 deletions crates/oxc_syntax/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ bitflags! {
const ConstEnum = 1 << 11;
const EnumMember = 1 << 12;
const TypeParameter = 1 << 13;
const NameSpaceModule = 1 << 14;
const ValueModule = 1 << 15;
// In a dts file or there is a declare flag
const Ambient = 1 << 16;
const NameSpaceModule = 1 << 14; // Uninstantiated module
const ValueModule = 1 << 15; // Instantiated module

const Enum = Self::ConstEnum.bits() | Self::RegularEnum.bits();
const Variable = Self::FunctionScopedVariable.bits() | Self::BlockScopedVariable.bits();
Expand Down

0 comments on commit 462811d

Please sign in to comment.