Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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: 20 additions & 2 deletions src/js_parser/p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5405,7 +5405,10 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
self.stmts_can_be_removed_if_unused_without_dce_check(stmts)
}

fn stmts_can_be_removed_if_unused_without_dce_check(&mut self, stmts: &[Stmt]) -> bool {
pub(crate) fn stmts_can_be_removed_if_unused_without_dce_check(
&mut self,
stmts: &[Stmt],
) -> bool {
for stmt in stmts {
match &stmt.data {
// These never have side effects
Expand Down Expand Up @@ -5737,7 +5740,7 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
self.expr_can_be_removed_if_unused_without_dce_check(expr)
}

fn expr_can_be_removed_if_unused_without_dce_check(&mut self, expr: &Expr) -> bool {
pub(crate) fn expr_can_be_removed_if_unused_without_dce_check(&mut self, expr: &Expr) -> bool {
if !self.stack_check.is_safe_to_recurse() || self.reported_stack_overflow.get() {
self.report_stack_overflow(expr.loc);
return false;
Expand Down Expand Up @@ -8746,6 +8749,10 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
symbols: &'s [Symbol],
part_index: u32,
}
// `X.y = v` parts belong to `X`; claimed once the map is complete.
let claim_member_assignments =
self.options.features.dead_code_elimination && self.options.tree_shaking;
let mut member_assignments = BumpVec::new_in(arena);
for (part_index, part) in parts.iter_mut().enumerate() {
let mut ctx = Ctx {
top_level: &mut top_level_symbols_to_parts,
Expand All @@ -8772,7 +8779,18 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
.push(ctx.part_index);
},
);
if claim_member_assignments
&& let Some(candidate) =
self.member_assignment_candidate(part, part_index as u32)
{
member_assignments.push(candidate);
}
}
self.claim_member_assignments(
parts.as_mut_slice(),
&mut top_level_symbols_to_parts,
&member_assignments,
);

// Pulling in the exports of this module always pulls in the export part
top_level_symbols_to_parts
Expand Down
1 change: 1 addition & 0 deletions src/js_parser/scan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod scan_imports;
pub(crate) mod scan_member_assignments;
pub mod scan_side_effects;
pub(crate) mod scan_symbols;
Loading
Loading