Skip to content

Commit

Permalink
feat(transformer): remove type and interface 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 15e9a3a
Show file tree
Hide file tree
Showing 6 changed files with 2,100 additions and 5,670 deletions.
15 changes: 14 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,15 @@ 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)
});
}
});
}
}
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 15e9a3a

Please sign in to comment.