-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transformer/typescript): correct elide imports/exports statements
- Loading branch information
Showing
5 changed files
with
176 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use oxc_ast::ast::{ExportNamedDeclaration, IdentifierReference}; | ||
use oxc_span::Atom; | ||
use rustc_hash::FxHashSet; | ||
|
||
/// Collects identifier references | ||
/// Indicates whether the BindingIdentifier is referenced or used in the ExportNamedDeclaration | ||
#[derive(Debug)] | ||
pub struct TypeScriptReferenceCollector<'a> { | ||
names: FxHashSet<Atom<'a>>, | ||
} | ||
|
||
impl<'a> TypeScriptReferenceCollector<'a> { | ||
pub fn new() -> Self { | ||
Self { names: FxHashSet::default() } | ||
} | ||
|
||
pub fn has_reference(&self, name: &Atom) -> bool { | ||
self.names.contains(name) | ||
} | ||
|
||
pub fn visit_identifier_reference(&mut self, ident: &IdentifierReference<'a>) { | ||
self.names.insert(ident.name.clone()); | ||
} | ||
|
||
pub fn visit_transform_export_named_declaration(&mut self, decl: &ExportNamedDeclaration<'a>) { | ||
if decl.export_kind.is_type() { | ||
return; | ||
} | ||
|
||
for specifier in &decl.specifiers { | ||
if specifier.export_kind.is_value() { | ||
self.names.insert(specifier.local.name().clone()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.