Skip to content

Commit

Permalink
feat: remove special tree shaking logic for entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed Feb 24, 2024
1 parent 03c0da4 commit ba046e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 5 additions & 2 deletions crates/rolldown/src/bundler/stages/link_stage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,17 @@ impl Action {
}
}

pub fn init_entry_point_stmt_info(module: &mut NormalModule, linking_info: &mut LinkingMetadata) {
pub fn init_entry_point_stmt_info(module: &mut NormalModule, meta: &mut LinkingMetadata) {
let mut referenced_symbols = vec![];
if matches!(module.exports_kind, ExportsKind::CommonJs) {
// If a commonjs module becomes an entry point while targeting esm, we need to at least add a `export default require_foo();`
// statement as some kind of syntax sugar. So users won't need to manually create a proxy file with `export default require('./foo.cjs')` in it.
referenced_symbols.push(linking_info.wrapper_ref.unwrap());
referenced_symbols.push(meta.wrapper_ref.unwrap());
}

// Make sure all exports are included
referenced_symbols.extend(meta.canonical_exports().map(|(_, export)| export.symbol_ref));

let stmt_info = StmtInfo {
stmt_idx: None,
declared_symbols: vec![],
Expand Down
5 changes: 0 additions & 5 deletions crates/rolldown/src/bundler/stages/link_stage/tree_shaking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ impl LinkStage<'_> {
};

include_module(context, module);

let linking_info = &self.metas[module.id];
linking_info.canonical_exports().for_each(|(_, resolved_export)| {
include_symbol(context, resolved_export.symbol_ref);
});
});

self.modules.iter_mut().par_bridge().for_each(|module| {
Expand Down

0 comments on commit ba046e6

Please sign in to comment.