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): remove Ambient symbol flag #8486

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 1 addition & 5 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,11 @@ impl NoUnusedVars {
}

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