Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Dec 19, 2020
1 parent e2c5b94 commit 60b747f
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions bundler/src/bundler/modules/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Modules {
});

let mut new = vec![];
let mut graph = StmtDepGraph::default();

new.extend(self.prepended.drain(..));
let mut module_starts = vec![];
Expand All @@ -70,7 +71,16 @@ impl Modules {
same_module_ranges.push(start..end);
}

new.extend(module.body)
// for (inner_idx, item) in module.body.into_iter().enumerate() {
// let idx = new.len();
// if inner_idx != 0 && inner_idx + 1 != inner_len && !new.is_empty() {
// graph.add_edge(idx - 1, idx, Required::Always);
// }

// new.push(item);
// }

new.extend(module.body);
}
let free = new.len()..(new.len() + self.injected.len());
if cfg!(debug_assertions) {
Expand All @@ -82,7 +92,6 @@ impl Modules {
}
new.extend(self.injected.drain(..));

let mut graph = StmtDepGraph::default();
let mut declared_by = HashMap::<Id, Vec<usize>>::default();
let mut uninitialized_ids = HashMap::<Id, usize>::new();

Expand Down Expand Up @@ -222,7 +231,7 @@ struct Sorter<'a> {

impl Sorter<'_> {
// This removes dependencies to other node.
fn emit(&mut self, idx: usize) {
fn emit(&mut self, idx: usize, emit_dependants: bool) {
if !self.orders.contains(&idx) {
eprintln!("Emit: `{}`", idx);

Expand All @@ -231,30 +240,24 @@ impl Sorter<'_> {
let ids: Vec<Id> = find_ids(&var.decls);
eprintln!("Declare: `{:?}`", ids);
}
_ => {}
}

if self._new.len() > idx + 1 {
match &self._new[idx + 1] {
ModuleItem::Stmt(Stmt::Expr(stmt)) => match &*stmt.expr {
Expr::Await(..) => {
dbg!(&self._new[idx]);
}
_ => {}
},
_ => {}
ModuleItem::Stmt(Stmt::Decl(Decl::Class(cls))) => {
eprintln!("Declare: `{:?}`", Id::from(&cls.ident));
}
ModuleItem::Stmt(Stmt::Decl(Decl::Fn(f))) => {
eprintln!("Declare: `{:?}`", Id::from(&f.ident));
}
_ => {}
}

self.orders.push(idx);
self.graph.remove_node(idx);

if emit_dependants {
self.emit_free_items();
}
}
}

fn emit_with_deps(&mut self, idx: usize) {
self.emit(idx);
self.emit_free_items();
}
/// Inject dependency-less free statements.
fn emit_free_items(&mut self) {
self.emit_items(self.free.clone())
Expand All @@ -280,7 +283,7 @@ impl Sorter<'_> {
}

did_work = true;
self.emit(i);
self.emit(i, false);
}

if !did_work {
Expand Down Expand Up @@ -389,9 +392,8 @@ impl Sorter<'_> {
eprintln!("Skipping `{}`", idx);
continue;
}
dejavu.insert(idx);

{
if !dejavu.insert(idx) {
let deps = self
.graph
.neighbors_directed(idx, Incoming)
Expand Down Expand Up @@ -423,7 +425,7 @@ impl Sorter<'_> {
if !delayed.contains(&idx) {
dbg!(idx);
// Free statements, like injected vars.
self.emit_with_deps(idx);
self.emit(idx, true);
}
return;
}
Expand All @@ -443,7 +445,7 @@ impl Sorter<'_> {
}
}

self.emit_with_deps(idx);
self.emit(idx, true);

let next_idx = idx + 1;

Expand Down

0 comments on commit 60b747f

Please sign in to comment.