Skip to content

Commit dfd5bb3

Browse files
authored
refactor(turbopack): Cleanup code for tree shaking (#70385)
### What? Minor refactorings extracted from other PRs. ### Why? To make WIP small
1 parent 4fdfca9 commit dfd5bb3

File tree

1 file changed

+5
-53
lines changed
  • turbopack/crates/turbopack-ecmascript/src/tree_shake

1 file changed

+5
-53
lines changed

turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use turbopack_core::{
1111

1212
use super::{
1313
chunk_item::EcmascriptModulePartChunkItem, get_part_id, part_of_module, split, split_module,
14-
Key, PartId, SplitResult,
14+
PartId, SplitResult,
1515
};
1616
use crate::{
1717
chunk::{EcmascriptChunkPlaceable, EcmascriptExports},
@@ -145,64 +145,16 @@ impl Module for EcmascriptModulePartAsset {
145145

146146
let analyze = analyze(self.full_module, self.part).await?;
147147

148-
let (deps, entrypoints) = match &*split_data {
149-
SplitResult::Ok {
150-
deps, entrypoints, ..
151-
} => (deps, entrypoints),
148+
let deps = match &*split_data {
149+
SplitResult::Ok { deps, .. } => deps,
152150
SplitResult::Failed { .. } => return Ok(analyze.references),
153151
};
154152

155153
// Facade depends on evaluation and re-exports
156-
if matches!(&*self.part.await?, ModulePart::Facade) {
157-
let mut references = vec![];
158-
159-
let reference = Vc::upcast(SingleModuleReference::new(
160-
Vc::upcast(EcmascriptModulePartAsset::new(
161-
self.full_module,
162-
ModulePart::evaluation(),
163-
)),
164-
Vc::cell("ecmascript module evaluation".into()),
165-
));
166-
167-
references.push(reference);
168-
169-
let reference = Vc::upcast(SingleModuleReference::new(
170-
Vc::upcast(EcmascriptModulePartAsset::new(
171-
self.full_module,
172-
ModulePart::exports(),
173-
)),
174-
Vc::cell("ecmascript reexports".into()),
175-
));
176-
177-
references.push(reference);
178-
179-
references.extend(analyze.references.await?.iter().cloned());
180-
181-
return Ok(Vc::cell(references));
154+
if matches!(&*self.part.await?, ModulePart::Facade | ModulePart::Exports) {
155+
return Ok(analyze.references);
182156
}
183157

184-
// ModulePart::Exports contains all reexports and a reexport of the Locals
185-
if matches!(&*self.part.await?, ModulePart::Exports) {
186-
let mut references = vec![];
187-
188-
for key in entrypoints.keys() {
189-
if let Key::Export(e) = key {
190-
let reference = Vc::upcast(SingleModuleReference::new(
191-
Vc::upcast(EcmascriptModulePartAsset::new(
192-
self.full_module,
193-
ModulePart::export(e.clone()),
194-
)),
195-
Vc::cell(format!("ecmascript export '{e}'").into()),
196-
));
197-
198-
references.push(reference);
199-
}
200-
}
201-
202-
references.extend(analyze.references.await?.iter().cloned());
203-
204-
return Ok(Vc::cell(references));
205-
}
206158
let deps = {
207159
let part_id = get_part_id(&split_data, self.part)
208160
.await

0 commit comments

Comments
 (0)