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

feat(transformer): remove typescript symbols after transform #8069

Merged
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
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
Loading