Skip to content

Commit d0631e3

Browse files
committed
fix
1 parent eca5c62 commit d0631e3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

crates/tree_shaker/src/entity/factory.rs

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl<'a> EntityFactory<'a> {
154154
consumable,
155155
consumed: Cell::new(false),
156156
consumed_as_prototype: Cell::new(false),
157+
pending_clear: Cell::new(false),
157158
cf_scope: CfScopeId::new(0),
158159
object_id,
159160
string_keyed: Default::default(),

crates/tree_shaker/src/entity/object/mod.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub struct ObjectEntity<'a> {
5151
pub consumable: bool,
5252
pub consumed: Cell<bool>,
5353
pub consumed_as_prototype: Cell<bool>,
54+
pub pending_clear: Cell<bool>,
5455
// deps: RefCell<ConsumableCollector<'a>>,
5556
/// Where the object is created
5657
pub cf_scope: CfScopeId,
@@ -79,8 +80,13 @@ impl<'a> EntityTrait<'a> for ObjectEntity<'a> {
7980

8081
self.consume_as_prototype(analyzer);
8182

82-
self.string_keyed.take();
83-
self.unknown_keyed.take();
83+
// FIXME: Need a better way to do this
84+
if let Ok(mut string_keyed) = self.string_keyed.try_borrow_mut() {
85+
string_keyed.clear();
86+
self.unknown_keyed.take();
87+
} else {
88+
self.pending_clear.set(true);
89+
}
8490

8591
analyzer.mark_object_consumed(self.cf_scope, self.object_id);
8692
}
@@ -247,14 +253,19 @@ impl<'a> ObjectEntity<'a> {
247253
return;
248254
}
249255

256+
self.disable_mangling(analyzer);
257+
250258
self.prototype.get().consume(analyzer);
251259

252260
for property in self.string_keyed.borrow().values() {
253261
property.consume(analyzer);
254262
}
255263
self.unknown_keyed.borrow().consume(analyzer);
256264

257-
self.disable_mangling(analyzer);
265+
if self.pending_clear.replace(false) {
266+
self.string_keyed.borrow_mut().clear();
267+
self.unknown_keyed.take();
268+
}
258269
}
259270

260271
pub fn is_mangable(&self) -> bool {
@@ -301,6 +312,7 @@ impl<'a> Analyzer<'a> {
301312
consumable: true,
302313
consumed: Cell::new(false),
303314
consumed_as_prototype: Cell::new(false),
315+
pending_clear: Cell::new(false),
304316
// deps: Default::default(),
305317
cf_scope: self.scoping.cf.current_id(),
306318
object_id: self.scoping.alloc_object_id(),

0 commit comments

Comments
 (0)