Skip to content

Commit 0b5fcb7

Browse files
committed
refactor: entity and value
1 parent 6882d82 commit 0b5fcb7

29 files changed

+380
-341
lines changed

crates/tree_shaker/src/builtins/globals/object_constructor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'a> Builtins<'a> {
2626
"defineProperty" => self.create_object_define_property_impl(),
2727
});
2828

29-
self.globals.borrow_mut().insert("Object", object);
29+
self.globals.borrow_mut().insert("Object", object.into());
3030
}
3131

3232
fn create_object_assign_impl(&self) -> Entity<'a> {
@@ -76,7 +76,7 @@ impl<'a> Builtins<'a> {
7676
}
7777
}
7878

79-
analyzer.factory.computed(array, deps)
79+
analyzer.factory.computed(array.into(), deps)
8080
})
8181
}
8282

@@ -91,7 +91,7 @@ impl<'a> Builtins<'a> {
9191
array.init_rest(value);
9292
}
9393

94-
analyzer.factory.computed(array, deps)
94+
analyzer.factory.computed(array.into(), deps)
9595
})
9696
}
9797

@@ -106,10 +106,10 @@ impl<'a> Builtins<'a> {
106106
let entry = analyzer.new_empty_array();
107107
entry.push_element(key.get_to_string(analyzer));
108108
entry.push_element(value);
109-
array.init_rest(entry);
109+
array.init_rest(entry.into());
110110
}
111111

112-
analyzer.factory.computed(array, deps)
112+
analyzer.factory.computed(array.into(), deps)
113113
})
114114
}
115115

crates/tree_shaker/src/builtins/globals/symbol_constructor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ impl<'a> Builtins<'a> {
3434
// "toString" => factory.string("__#toString__"),
3535
});
3636

37-
self.globals.borrow_mut().insert("Symbol", object);
37+
self.globals.borrow_mut().insert("Symbol", object.into());
3838
}
3939
}

crates/tree_shaker/src/builtins/import_meta.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ impl<'a> Builtins<'a> {
3131
},
3232
);
3333

34-
object
34+
object.into()
3535
}
3636
}

crates/tree_shaker/src/builtins/prototypes/function.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{object::create_object_prototype, BuiltinPrototype};
22
use crate::{
3-
entity::{Entity, EntityFactory, ObjectId},
3+
entity::{EntityFactory, ObjectId},
44
init_prototype,
55
};
66

@@ -14,11 +14,11 @@ pub fn create_function_prototype<'a>(factory: &EntityFactory<'a>) -> BuiltinProt
1414
// This can be any value
1515
let arguments_object_id = ObjectId::from_usize(0);
1616
match arg.test_is_undefined() {
17-
Some(true) => analyzer.factory.array(cf_scope, arguments_object_id),
17+
Some(true) => analyzer.factory.array(cf_scope, arguments_object_id).into(),
1818
Some(false) => arg,
1919
None => analyzer.factory.union((
2020
arg,
21-
analyzer.factory.array(cf_scope, arguments_object_id) as Entity<'a>,
21+
analyzer.factory.array(cf_scope, arguments_object_id).into(),
2222
)),
2323
}
2424
};

crates/tree_shaker/src/builtins/react/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn create_react_create_context_impl<'a>(factory: &'a EntityFactory<'a>) -> E
6060
"Consumer" => create_react_context_consumer_impl(analyzer, context_id),
6161
});
6262

63-
context
63+
context.into()
6464
})
6565
}
6666

crates/tree_shaker/src/builtins/react/create_element.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ pub fn create_react_create_element_impl<'a>(factory: &'a EntityFactory<'a>) -> E
66
let [tag, props] = args[..] else { unreachable!() };
77
let props = match props.test_nullish() {
88
Some(true) => analyzer
9-
.new_empty_object(ObjectPrototype::Builtin(&analyzer.builtins.prototypes.object), None),
9+
.new_empty_object(ObjectPrototype::Builtin(&analyzer.builtins.prototypes.object), None)
10+
.into(),
1011
Some(false) => props,
1112
None => analyzer.factory.union((
1213
props,
1314
analyzer
1415
.new_empty_object(ObjectPrototype::Builtin(&analyzer.builtins.prototypes.object), None)
15-
as Entity<'a>,
16+
.into(),
1617
)),
1718
};
1819

crates/tree_shaker/src/builtins/react/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn create_react_namespace<'a>(
5151
"useMemo" => create_react_use_memo_impl(factory),
5252
});
5353

54-
namespace
54+
namespace.into()
5555
}
5656

5757
pub fn create_react_jsx_runtime_namespace<'a>(
@@ -70,5 +70,5 @@ pub fn create_react_jsx_runtime_namespace<'a>(
7070
"jsxs" => create_react_jsxs_impl(factory),
7171
});
7272

73-
object
73+
object.into()
7474
}

crates/tree_shaker/src/entity/array.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'a> EntityTrait<'a> for ArrayEntity<'a> {
290290
if self.consumed.get() {
291291
return consumed_object::r#await(analyzer, dep);
292292
}
293-
analyzer.factory.computed(self, dep)
293+
analyzer.factory.computed(self.into(), dep)
294294
}
295295

296296
fn iterate(&'a self, analyzer: &mut Analyzer<'a>, dep: Consumable<'a>) -> IteratedElements<'a> {
@@ -342,7 +342,7 @@ impl<'a> EntityTrait<'a> for ArrayEntity<'a> {
342342
}
343343

344344
fn get_to_jsx_child(&'a self, _analyzer: &Analyzer<'a>) -> Entity<'a> {
345-
self
345+
self.into()
346346
}
347347

348348
fn test_typeof(&self) -> TypeofResult {

crates/tree_shaker/src/entity/builtin_fn.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a, T: BuiltinFnEntity<'a>> EntityTrait<'a> for T {
4040
if let Some(object) = self.object() {
4141
object.get_property(analyzer, dep, key)
4242
} else {
43-
analyzer.builtins.prototypes.function.get_property(analyzer, self, key, dep)
43+
analyzer.builtins.prototypes.function.get_property(analyzer, self.into(), key, dep)
4444
}
4545
}
4646

@@ -109,7 +109,7 @@ impl<'a, T: BuiltinFnEntity<'a>> EntityTrait<'a> for T {
109109
}
110110

111111
fn r#await(&'a self, _analyzer: &mut Analyzer<'a>, _dep: Consumable<'a>) -> Entity<'a> {
112-
self
112+
self.into()
113113
}
114114

115115
fn iterate(&'a self, analyzer: &mut Analyzer<'a>, dep: Consumable<'a>) -> IteratedElements<'a> {
@@ -221,12 +221,15 @@ impl<'a> Analyzer<'a> {
221221
_name: &'static str,
222222
implementation: F,
223223
) -> Entity<'a> {
224-
self.factory.alloc(ImplementedBuiltinFnEntity {
225-
#[cfg(feature = "flame")]
226-
name: _name,
227-
implementation,
228-
object: Some(self.new_function_object(None).0),
229-
})
224+
self
225+
.factory
226+
.alloc(ImplementedBuiltinFnEntity {
227+
#[cfg(feature = "flame")]
228+
name: _name,
229+
implementation,
230+
object: Some(self.new_function_object(None).0),
231+
})
232+
.into()
230233
}
231234
}
232235

crates/tree_shaker/src/entity/computed.rs

-180
This file was deleted.

0 commit comments

Comments
 (0)