Skip to content

Commit

Permalink
feat(transformer): remove some types after transform
Browse files Browse the repository at this point in the history
part of #7460
  • Loading branch information
Boshen committed Dec 23, 2024
1 parent 8b54d89 commit 780fc93
Show file tree
Hide file tree
Showing 8 changed files with 2,365 additions and 11,394 deletions.
19 changes: 18 additions & 1 deletion crates/oxc_semantic/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use oxc_syntax::{
node::NodeId,
reference::ReferenceId,
scope::{ScopeFlags, ScopeId},
symbol::SymbolId,
symbol::{SymbolFlags, SymbolId},
};

use crate::SymbolTable;

pub(crate) type Bindings<'a> = hashbrown::HashMap<&'a str, SymbolId, FxBuildHasher, &'a Allocator>;
pub type UnresolvedReferences<'a> =
hashbrown::HashMap<&'a str, ArenaVec<'a, ReferenceId>, FxBuildHasher, &'a Allocator>;
Expand Down Expand Up @@ -462,4 +464,19 @@ impl ScopeTree {
});
}
}

pub fn delete_typescript_bindings(&mut self, symbol_table: &SymbolTable) {
self.cell.with_dependent_mut(|_allocator, inner| {
for bindings in &mut inner.bindings {
bindings.retain(|_name, symbol_id| {
let flags = symbol_table.get_flags(*symbol_id);
!flags.intersects(
SymbolFlags::TypeAlias
| SymbolFlags::Interface
| SymbolFlags::TypeParameter,
)
});
}
});
}
}
1 change: 1 addition & 0 deletions crates/oxc_transformer/src/typescript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl<'a, 'ctx> Traverse<'a> for TypeScript<'a, 'ctx> {
fn exit_program(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
self.annotations.exit_program(program, ctx);
self.module.exit_program(program, ctx);
ctx.scoping.delete_typescript_bindings();
}

fn enter_arrow_function_expression(
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ impl TraverseScoping {
.map(CompactStr::from)
.collect()
}

pub fn delete_typescript_bindings(&mut self) {
self.scopes.delete_typescript_bindings(&self.symbols);
}
}

/// Create base for UID name based on provided `name`.
Expand Down
Loading

0 comments on commit 780fc93

Please sign in to comment.