Skip to content

Commit

Permalink
fix case when both paths return
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jul 31, 2024
1 parent a61efa9 commit a638562
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
14 changes: 7 additions & 7 deletions crates/turbopack-ecmascript/src/analyzer/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1979,12 +1979,6 @@ impl<'a> Analyzer<'a> {
return;
}
match (early_return_when_true, early_return_when_false) {
(true, true) => {
self.early_return_stack.push(EarlyReturn::Always {
prev_effects: take(&mut self.effects),
start_ast_path: as_parent_path(ast_path),
});
}
(true, false) => {
self.early_return_stack.push(EarlyReturn::Conditional {
prev_effects: take(&mut self.effects),
Expand All @@ -2011,7 +2005,7 @@ impl<'a> Analyzer<'a> {
early_return_condition_value: false,
});
}
(false, false) => {
(false, false) | (true, true) => {
let kind = match (then, r#else) {
(Some(then), Some(r#else)) => ConditionalKind::IfElse { then, r#else },
(Some(then), None) => ConditionalKind::If { then },
Expand All @@ -2025,6 +2019,12 @@ impl<'a> Analyzer<'a> {
span,
in_try: is_in_try(ast_path),
});
if early_return_when_false && early_return_when_true {
self.early_return_stack.push(EarlyReturn::Always {
prev_effects: take(&mut self.effects),
start_ast_path: as_parent_path(ast_path),
});
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ class K {
}
n5();
};

o() {
if (something) {
require("./module");
return;
} else {
require("./module");
return;
}
}
}

z1();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a638562

Please sign in to comment.