Skip to content

Commit

Permalink
feat: init export fn
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Nov 6, 2023
1 parent 2d0bbc3 commit 39f9b80
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions crates/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub struct ExternalGlobals {
dependency: HashMap<String, ModuleInfo>,
dependency_with_alias: HashMap<String, String>,
import_references: HashMap<String, String>,
imports_vec: Vec<usize>,
removes_vec: Vec<usize>,
}

impl ExternalGlobals {
pub fn init(optins: Options) -> Self {
Self {
dependency: optins.dependency,
dependency_with_alias: optins.dependency_with_alias,
imports_vec: Default::default(),
removes_vec: Default::default(),
import_references: Default::default(),
}
}
Expand All @@ -36,7 +36,7 @@ impl ExternalGlobals {
match self.dependency_with_alias.get(val) {
Some(aliase) => {
if let Some(global_name) = self.dependency.get(aliase).map(|dep| &dep.global) {
self.imports_vec.push(index);
self.removes_vec.push(index);
import_decl.specifiers.iter().for_each(|spec| match spec {
ImportSpecifier::Named(s) => {
// swc imoorted type is null
Expand Down Expand Up @@ -67,20 +67,33 @@ impl ExternalGlobals {
None => {}
}
}
fn rewrite_export_named_decl(&mut self, export_decl: &NamedExport, index: usize) {
let scan_with_source = |i: i32| -> i32 { i + 1 };
let scan_without_source = |i: i32| -> i32 { i + 1 };

}
fn rewrite_export_all_decl(&mut self, export_decl: &ExportAll, index: usize) {}
}

impl VisitMut for ExternalGlobals {
fn visit_mut_module(&mut self, n: &mut Module) {
for (index, item) in n.body.iter().enumerate() {
if let ModuleItem::ModuleDecl(decl) = item {
if let ModuleDecl::Import(import_decl) = decl {
self.scan_import_decl(import_decl, index);
match decl {
ModuleDecl::Import(import_decl) => self.scan_import_decl(import_decl, index),
ModuleDecl::ExportDefaultDecl(_) => {}
ModuleDecl::ExportNamed(export_decl) => {
self.rewrite_export_named_decl(export_decl, index)
}
ModuleDecl::ExportAll(export_decl) => {
self.rewrite_export_all_decl(export_decl, index)
}
_ => {}
}
}
}
self.imports_vec.iter().for_each(|i| {
let s = *i;
n.body.remove(s);
self.removes_vec.iter().rev().for_each(|i| {
n.body.remove(*i);
});
}
}

0 comments on commit 39f9b80

Please sign in to comment.