Skip to content

Commit

Permalink
Merge branch 'master' into feature/database-support
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlin1228 committed Oct 11, 2024
2 parents efd3b65 + 99d2cf5 commit 735ee2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
31 changes: 18 additions & 13 deletions crates/dt_route/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::bail;
use dt_parser::{
anonymous_default_export::SYMBOL_NAME_FOR_ANONYMOUS_DEFAULT_EXPORT, types::SymbolDependency,
};
Expand Down Expand Up @@ -129,7 +130,7 @@ impl RouteVisitor {
}
}

fn get_route_path(&self, route_object: &Expr) -> String {
fn get_route_path(&self, route_object: &Expr) -> anyhow::Result<String> {
match route_object {
Expr::Object(object_lit) => {
for prop in object_lit.props.iter() {
Expand All @@ -140,10 +141,10 @@ impl RouteVisitor {
if ident_name.sym == "path" {
match &**value {
Expr::Lit(lit) => match lit {
Lit::Str(s) => return s.value.to_string(),
_ => panic!("path value is literal but not string literal for {}", self.module_path)
Lit::Str(s) => return Ok(s.value.to_string()),
_ => bail!("path value is literal but not string literal for {}", self.module_path)
},
_ => panic!(
_ => bail!(
"failed to transform value to string for {}",
self.module_path
),
Expand All @@ -158,9 +159,9 @@ impl RouteVisitor {
}
}
}
_ => panic!("invalid route object for {}", self.module_path),
_ => bail!("invalid route object for {}", self.module_path),
}
panic!(
bail!(
"failed to find the path in the route object for {}",
self.module_path
);
Expand All @@ -187,13 +188,17 @@ impl Visit for RouteVisitor {
match prop {
PropOrSpread::Prop(prop) => match &**prop {
Prop::KeyValue(KeyValueProp { value, .. }) => {
let route_path = self.get_route_path(&**value);
self.current_route_path = Some(Route {
path: route_path,
depend_on: HashSet::new(),
});
value.visit_children_with(self);
self.routes.push(self.current_route_path.take().unwrap());
match self.get_route_path(&**value) {
Ok(route_path) => {
self.current_route_path = Some(Route {
path: route_path,
depend_on: HashSet::new(),
});
value.visit_children_with(self);
self.routes.push(self.current_route_path.take().unwrap());
}
Err(_) => (),
}
}
_ => (),
},
Expand Down
7 changes: 7 additions & 0 deletions crates/dt_tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ impl<'graph> DependencyTracker<'graph> {
}

pub fn trace(&mut self, module_symbol: ModuleSymbol) -> anyhow::Result<Vec<Vec<ModuleSymbol>>> {
// Treat routeNmaes specially since they cause a lot of circular dependencies in
// some of our codebases. One assumption of this tool is "no circular dependency"
// , so let's workaround here for now.
if module_symbol.1.to_string() == "routeNames" {
return Ok(vec![]);
}

// early return if cached
if let Some(cached) = self.cache.get(&module_symbol) {
return Ok(cached.clone());
Expand Down

0 comments on commit 735ee2c

Please sign in to comment.