Skip to content

Commit e5e83ca

Browse files
committed
fixup
1 parent ea2a08b commit e5e83ca

15 files changed

+45
-264
lines changed

crates/tree_shaker/src/consumable/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod impls;
33
mod lazy;
44
mod once;
55

6-
use crate::{analyzer::Analyzer, entity::Entity};
6+
use crate::analyzer::Analyzer;
77
pub use collector::*;
88
pub use lazy::*;
99
pub use once::*;

crates/tree_shaker/src/entity/arguments.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ use super::{
22
consumed_object, Entity, EnumeratedProperties, IteratedElements, ObjectPrototype, TypeofResult,
33
ValueTrait,
44
};
5-
use crate::{
6-
analyzer::Analyzer,
7-
consumable::{Consumable, ConsumableTrait},
8-
use_consumed_flag,
9-
};
5+
use crate::{analyzer::Analyzer, consumable::Consumable, use_consumed_flag};
106
use std::cell::Cell;
117

128
#[derive(Debug, Default)]
@@ -15,17 +11,15 @@ pub struct ArgumentsEntity<'a> {
1511
pub arguments: Vec<(bool, Entity<'a>)>,
1612
}
1713

18-
impl<'a> ConsumableTrait<'a> for ArgumentsEntity<'a> {
19-
fn consume(&self, analyzer: &mut Analyzer<'a>) {
14+
impl<'a> ValueTrait<'a> for ArgumentsEntity<'a> {
15+
fn consume(&'a self, analyzer: &mut Analyzer<'a>) {
2016
use_consumed_flag!(self);
2117

2218
for (_, entity) in &self.arguments {
2319
entity.consume(analyzer);
2420
}
2521
}
26-
}
2722

28-
impl<'a> ValueTrait<'a> for ArgumentsEntity<'a> {
2923
fn unknown_mutate(&'a self, analyzer: &mut Analyzer<'a>, dep: Consumable<'a>) {
3024
if self.consumed.get() {
3125
return consumed_object::unknown_mutate(analyzer, dep);

crates/tree_shaker/src/entity/array.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{
44
};
55
use crate::{
66
analyzer::Analyzer,
7-
consumable::{Consumable, ConsumableCollector, ConsumableTrait},
7+
consumable::{Consumable, ConsumableCollector},
88
scope::CfScopeId,
99
use_consumed_flag,
1010
};
@@ -33,8 +33,8 @@ impl<'a> fmt::Debug for ArrayEntity<'a> {
3333
}
3434
}
3535

36-
impl<'a> ConsumableTrait<'a> for ArrayEntity<'a> {
37-
fn consume(&self, analyzer: &mut Analyzer<'a>) {
36+
impl<'a> ValueTrait<'a> for ArrayEntity<'a> {
37+
fn consume(&'a self, analyzer: &mut Analyzer<'a>) {
3838
use_consumed_flag!(self);
3939

4040
analyzer.mark_object_consumed(self.cf_scope, self.object_id);
@@ -44,9 +44,7 @@ impl<'a> ConsumableTrait<'a> for ArrayEntity<'a> {
4444
analyzer.consume(self.elements.take());
4545
analyzer.consume(self.rest.take());
4646
}
47-
}
4847

49-
impl<'a> ValueTrait<'a> for ArrayEntity<'a> {
5048
fn unknown_mutate(&'a self, analyzer: &mut Analyzer<'a>, dep: Consumable<'a>) {
5149
if self.consumed.get() {
5250
return consumed_object::unknown_mutate(analyzer, dep);

crates/tree_shaker/src/entity/builtin_fn.rs

+8-23
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ use super::{
22
consumed_object, never::NeverEntity, Entity, EntityFactory, EnumeratedProperties,
33
IteratedElements, ObjectEntity, ObjectPrototype, TypeofResult, ValueTrait,
44
};
5-
use crate::{
6-
analyzer::Analyzer,
7-
consumable::{Consumable, ConsumableTrait},
8-
};
5+
use crate::{analyzer::Analyzer, consumable::Consumable};
96
use std::fmt::Debug;
107

11-
trait BuiltinFnEntity<'a>: ConsumableTrait<'a> {
8+
trait BuiltinFnEntity<'a>: Debug {
129
#[cfg(feature = "flame")]
1310
fn name(&self) -> &'static str;
1411
fn object(&self) -> Option<&'a ObjectEntity<'a>> {
@@ -24,6 +21,12 @@ trait BuiltinFnEntity<'a>: ConsumableTrait<'a> {
2421
}
2522

2623
impl<'a, T: BuiltinFnEntity<'a>> ValueTrait<'a> for T {
24+
fn consume(&'a self, analyzer: &mut Analyzer<'a>) {
25+
if let Some(object) = self.object() {
26+
object.consume(analyzer);
27+
}
28+
}
29+
2730
fn unknown_mutate(&'a self, _analyzer: &mut Analyzer<'a>, _dep: Consumable<'a>) {
2831
// No effect
2932
}
@@ -191,16 +194,6 @@ impl<'a, F: BuiltinFnImplementation<'a> + 'a> Debug for ImplementedBuiltinFnEnti
191194
}
192195
}
193196

194-
impl<'a, F: BuiltinFnImplementation<'a> + 'a> ConsumableTrait<'a>
195-
for ImplementedBuiltinFnEntity<'a, F>
196-
{
197-
fn consume(&self, analyzer: &mut Analyzer<'a>) {
198-
if let Some(object) = self.object() {
199-
object.consume(analyzer);
200-
}
201-
}
202-
}
203-
204197
impl<'a, F: BuiltinFnImplementation<'a> + 'a> BuiltinFnEntity<'a>
205198
for ImplementedBuiltinFnEntity<'a, F>
206199
{
@@ -245,14 +238,6 @@ pub struct PureBuiltinFnEntity<'a> {
245238
return_value: fn(&EntityFactory<'a>) -> Entity<'a>,
246239
}
247240

248-
impl<'a> ConsumableTrait<'a> for PureBuiltinFnEntity<'a> {
249-
fn consume(&self, analyzer: &mut Analyzer<'a>) {
250-
if let Some(object) = self.object() {
251-
object.consume(analyzer);
252-
}
253-
}
254-
}
255-
256241
impl<'a> BuiltinFnEntity<'a> for PureBuiltinFnEntity<'a> {
257242
#[cfg(feature = "flame")]
258243
fn name(&self) -> &'static str {

crates/tree_shaker/src/entity/class.rs

-159
This file was deleted.

crates/tree_shaker/src/entity/function.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use super::{
44
};
55
use crate::{
66
analyzer::Analyzer,
7-
consumable::{Consumable, ConsumableTrait},
7+
consumable::Consumable,
88
scope::VariableScopeId,
99
utils::{CalleeInfo, CalleeNode},
1010
};
1111
use oxc::span::GetSpan;
1212
use std::{cell::Cell, rc::Rc};
1313

14-
#[derive(Debug, Clone)]
14+
#[derive(Debug)]
1515
pub struct FunctionEntity<'a> {
1616
body_consumed: Rc<Cell<bool>>,
1717
pub callee: CalleeInfo<'a>,
@@ -22,15 +22,13 @@ pub struct FunctionEntity<'a> {
2222
pub prototype: &'a ObjectEntity<'a>,
2323
}
2424

25-
impl<'a> ConsumableTrait<'a> for FunctionEntity<'a> {
26-
fn consume(&self, analyzer: &mut Analyzer<'a>) {
27-
(analyzer.allocator.alloc(self.clone())).consume_body(analyzer);
25+
impl<'a> ValueTrait<'a> for FunctionEntity<'a> {
26+
fn consume(&'a self, analyzer: &mut Analyzer<'a>) {
27+
self.consume_body(analyzer);
2828
self.statics.consume(analyzer);
2929
self.prototype.consume(analyzer);
3030
}
31-
}
3231

33-
impl<'a> ValueTrait<'a> for FunctionEntity<'a> {
3432
fn unknown_mutate(&'a self, analyzer: &mut Analyzer<'a>, dep: Consumable<'a>) {
3533
self.consume(analyzer);
3634
consumed_object::unknown_mutate(analyzer, dep);

crates/tree_shaker/src/entity/literal.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::{
55
use crate::{
66
analyzer::Analyzer,
77
builtins::BuiltinPrototype,
8-
consumable::{Consumable, ConsumableTrait},
8+
consumable::Consumable,
99
mangling::{MangleAtom, MangleConstraint},
1010
transformer::Transformer,
1111
utils::F64WithEq,
@@ -33,15 +33,13 @@ pub enum LiteralEntity<'a> {
3333
Undefined,
3434
}
3535

36-
impl<'a> ConsumableTrait<'a> for LiteralEntity<'a> {
37-
fn consume(&self, analyzer: &mut Analyzer<'a>) {
36+
impl<'a> ValueTrait<'a> for LiteralEntity<'a> {
37+
fn consume(&'a self, analyzer: &mut Analyzer<'a>) {
3838
if let LiteralEntity::String(_, Some(atom)) = self {
3939
analyzer.consume(*atom);
4040
}
4141
}
42-
}
4342

44-
impl<'a> ValueTrait<'a> for LiteralEntity<'a> {
4543
fn consume_mangable(&'a self, _analyzer: &mut Analyzer<'a>) -> bool {
4644
// No effect
4745
!matches!(self, LiteralEntity::String(_, Some(_)))

crates/tree_shaker/src/entity/logical_result.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use super::{
22
Entity, EnumeratedProperties, IteratedElements, ObjectPrototype, TypeofResult, ValueTrait,
33
};
4-
use crate::{
5-
analyzer::Analyzer,
6-
consumable::{Consumable, ConsumableTrait},
7-
};
4+
use crate::{analyzer::Analyzer, consumable::Consumable};
85

96
#[derive(Debug, Clone)]
107
pub struct LogicalResultEntity<'a> {
@@ -13,13 +10,11 @@ pub struct LogicalResultEntity<'a> {
1310
pub result: Option<bool>,
1411
}
1512

16-
impl<'a> ConsumableTrait<'a> for LogicalResultEntity<'a> {
17-
fn consume(&self, analyzer: &mut Analyzer<'a>) {
13+
impl<'a> ValueTrait<'a> for LogicalResultEntity<'a> {
14+
fn consume(&'a self, analyzer: &mut Analyzer<'a>) {
1815
self.value.consume(analyzer);
1916
}
20-
}
2117

22-
impl<'a> ValueTrait<'a> for LogicalResultEntity<'a> {
2318
fn consume_mangable(&'a self, analyzer: &mut Analyzer<'a>) -> bool {
2419
self.value.consume_mangable(analyzer)
2520
}

crates/tree_shaker/src/entity/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub type EnumeratedProperties<'a> = (Vec<(bool, Entity<'a>, Entity<'a>)>, Consum
3838
/// (vec![known_elements], rest, dep)
3939
pub type IteratedElements<'a> = (Vec<Entity<'a>>, Option<Entity<'a>>, Consumable<'a>);
4040

41-
pub trait ValueTrait<'a>: ConsumableTrait<'a> {
41+
pub trait ValueTrait<'a>: Debug {
42+
fn consume(&'a self, analyzer: &mut Analyzer<'a>);
4243
/// Returns true if the entity is completely consumed
4344
fn consume_mangable(&'a self, analyzer: &mut Analyzer<'a>) -> bool {
4445
self.consume(analyzer);

0 commit comments

Comments
 (0)