Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(turbopack): Skip tree shaking on next/dynamic instead of ESM import() #71145

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions turbopack/crates/turbopack-ecmascript/src/tree_shake/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,18 @@ pub fn should_skip_tree_shaking(m: &Program) -> bool {
match item {
// Skip turbopack helpers.
ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
with, specifiers, ..
src,
with,
specifiers,
..
})) => {
// We detect imports from next/dynamic in various places.
// See collect_next_dynamic_imports. We need to preserve the import of
// `next/dynamic`.
if src.value == "next/dynamic" {
return true;
}

if let Some(with) = with.as_deref().and_then(|v| v.as_import_with()) {
for item in with.values.iter() {
if item.key.sym == *TURBOPACK_HELPER {
Expand Down Expand Up @@ -490,16 +500,6 @@ impl Visit for ShouldSkip {
n.visit_children_with(self);
}

fn visit_callee(&mut self, n: &Callee) {
// TOOD(PACK-3231): Tree shaking work with dynamic imports
if matches!(n, Callee::Import(..)) {
self.skip = true;
return;
}

n.visit_children_with(self);
}

fn visit_expr(&mut self, n: &Expr) {
if self.skip {
return;
Expand Down
Loading