Skip to content

Commit 39ac0de

Browse files
committed
2 parents a1c9860 + 3e1cc9a commit 39ac0de

16 files changed

+221
-137
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
builtins::{constants::OBJECT_CONSTRUCTOR_OBJECT_ID, Builtins},
3-
entity::{Entity, LiteralEntity, ObjectPropertyValue, TypeofResult},
3+
entity::{Entity, LiteralEntity, ObjectPropertyValue, ObjectPrototype, TypeofResult},
44
init_namespace,
55
};
66
use std::borrow::BorrowMut;
@@ -9,8 +9,11 @@ impl<'a> Builtins<'a> {
99
pub fn init_object_constructor(&mut self) {
1010
let factory = self.factory;
1111

12-
let object =
13-
factory.builtin_object(OBJECT_CONSTRUCTOR_OBJECT_ID, &self.prototypes.function, false);
12+
let object = factory.builtin_object(
13+
OBJECT_CONSTRUCTOR_OBJECT_ID,
14+
ObjectPrototype::Builtin(&self.prototypes.function),
15+
false,
16+
);
1417
object.init_rest(ObjectPropertyValue::Field(factory.immutable_unknown, true));
1518

1619
init_namespace!(object, {

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
builtins::{constants::SYMBOL_CONSTRUCTOR_OBJECT_ID, Builtins},
3-
entity::ObjectPropertyValue,
3+
entity::{ObjectPropertyValue, ObjectPrototype},
44
init_namespace,
55
};
66
use std::borrow::BorrowMut;
@@ -9,8 +9,11 @@ impl<'a> Builtins<'a> {
99
pub fn init_symbol_constructor(&mut self) {
1010
let factory = self.factory;
1111

12-
let object =
13-
factory.builtin_object(SYMBOL_CONSTRUCTOR_OBJECT_ID, &self.prototypes.function, false);
12+
let object = factory.builtin_object(
13+
SYMBOL_CONSTRUCTOR_OBJECT_ID,
14+
ObjectPrototype::Builtin(&self.prototypes.function),
15+
false,
16+
);
1417
object.init_rest(ObjectPropertyValue::Field(factory.immutable_unknown, true));
1518

1619
init_namespace!(object, {

crates/tree_shaker/src/builtins/import_meta.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use super::{constants::IMPORT_META_OBJECT_ID, prototypes::BuiltinPrototypes, Builtins};
2-
use crate::entity::{Entity, EntityFactory, ObjectProperty, ObjectPropertyValue};
2+
use crate::entity::{Entity, EntityFactory, ObjectProperty, ObjectPropertyValue, ObjectPrototype};
33

44
impl<'a> Builtins<'a> {
55
pub fn create_import_meta(
66
factory: &'a EntityFactory<'a>,
7-
prototypes: &'a BuiltinPrototypes<'a>,
7+
_prototypes: &'a BuiltinPrototypes<'a>,
88
) -> Entity<'a> {
9-
let object = factory.builtin_object(IMPORT_META_OBJECT_ID, &prototypes.null, true);
9+
let object =
10+
factory.builtin_object(IMPORT_META_OBJECT_ID, ObjectPrototype::ImplicitOrNull, true);
1011
object.init_rest(ObjectPropertyValue::Property(
1112
Some(factory.immutable_unknown),
1213
Some(factory.immutable_unknown),

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
analyzer::Analyzer,
33
consumable::{Consumable, ConsumableTrait},
4-
entity::{Entity, EntityFactory},
4+
entity::{Entity, EntityFactory, ObjectPrototype},
55
init_object,
66
};
77
use oxc::semantic::SymbolId;
@@ -42,7 +42,8 @@ pub fn create_react_create_context_impl<'a>(factory: &'a EntityFactory<'a>) -> E
4242
let default_value =
4343
args.destruct_as_array(analyzer, analyzer.factory.empty_consumable, 1, false).0[0];
4444

45-
let context = analyzer.new_empty_object(&analyzer.builtins.prototypes.object, None);
45+
let context = analyzer
46+
.new_empty_object(ObjectPrototype::Builtin(&analyzer.builtins.prototypes.object), None);
4647

4748
let context_id = analyzer.builtins.react_data.contexts.push(ReactContextData {
4849
object_id: context.object_id,

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
use crate::entity::{Entity, EntityFactory};
1+
use crate::entity::{Entity, EntityFactory, ObjectPrototype};
22

33
pub fn create_react_create_element_impl<'a>(factory: &'a EntityFactory<'a>) -> Entity<'a> {
44
factory.implemented_builtin_fn("React::createElement", |analyzer, dep, _this, args| {
55
let (args, children, _) = args.destruct_as_array(analyzer, dep, 2, true);
66
let [tag, props] = args[..] else { unreachable!() };
77
let props = match props.test_nullish() {
8-
Some(true) => analyzer.new_empty_object(&analyzer.builtins.prototypes.object, None),
8+
Some(true) => analyzer
9+
.new_empty_object(ObjectPrototype::Builtin(&analyzer.builtins.prototypes.object), None),
910
Some(false) => props,
1011
None => analyzer.factory.union((
1112
props,
12-
analyzer.new_empty_object(&analyzer.builtins.prototypes.object, None) as Entity<'a>,
13+
analyzer
14+
.new_empty_object(ObjectPrototype::Builtin(&analyzer.builtins.prototypes.object), None)
15+
as Entity<'a>,
1316
)),
1417
};
1518

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::{
1313
prototypes::BuiltinPrototypes,
1414
};
1515
use crate::{
16-
entity::{Entity, EntityFactory, ObjectPropertyValue},
16+
entity::{Entity, EntityFactory, ObjectPropertyValue, ObjectPrototype},
1717
init_namespace,
1818
};
1919
pub use class_names::create_class_names_namespace;
@@ -36,9 +36,10 @@ pub struct AnalyzerDataForReact<'a> {
3636

3737
pub fn create_react_namespace<'a>(
3838
factory: &'a EntityFactory<'a>,
39-
prototypes: &'a BuiltinPrototypes<'a>,
39+
_prototypes: &'a BuiltinPrototypes<'a>,
4040
) -> Entity<'a> {
41-
let namespace = factory.builtin_object(REACT_NAMESPACE_OBJECT_ID, &prototypes.null, false);
41+
let namespace =
42+
factory.builtin_object(REACT_NAMESPACE_OBJECT_ID, ObjectPrototype::ImplicitOrNull, false);
4243
namespace.init_rest(ObjectPropertyValue::Field(factory.immutable_unknown, true));
4344

4445
init_namespace!(namespace, {
@@ -55,10 +56,13 @@ pub fn create_react_namespace<'a>(
5556

5657
pub fn create_react_jsx_runtime_namespace<'a>(
5758
factory: &'a EntityFactory<'a>,
58-
prototypes: &'a BuiltinPrototypes<'a>,
59+
_prototypes: &'a BuiltinPrototypes<'a>,
5960
) -> Entity<'a> {
60-
let object =
61-
factory.builtin_object(REACT_JSX_RUNTIME_NAMESPACE_OBJECT_ID, &prototypes.null, false);
61+
let object = factory.builtin_object(
62+
REACT_JSX_RUNTIME_NAMESPACE_OBJECT_ID,
63+
ObjectPrototype::ImplicitOrNull,
64+
false,
65+
);
6266
object.init_rest(ObjectPropertyValue::Field(factory.immutable_unknown, true));
6367

6468
init_namespace!(object, {

crates/tree_shaker/src/entity/factory.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{
2-
builtins::Prototype,
32
consumable::{Consumable, ConsumableTrait, LazyConsumable, OnceConsumable},
43
mangling::{AlwaysMangableDep, MangleAtom, MangleConstraint, ManglingDep},
54
module::ModuleId,
@@ -18,8 +17,8 @@ use super::{
1817
react_element::ReactElementEntity,
1918
union::UnionEntity,
2019
utils::UnionLike,
21-
ClassEntity, Entity, LiteralEntity, ObjectEntity, PrimitiveEntity, PureBuiltinFnEntity,
22-
UnknownEntity,
20+
ClassEntity, Entity, LiteralEntity, ObjectEntity, ObjectPrototype, PrimitiveEntity,
21+
PureBuiltinFnEntity, UnknownEntity,
2322
};
2423
use oxc::semantic::SymbolId;
2524
use oxc::{allocator::Allocator, ast::ast::Class};
@@ -150,7 +149,7 @@ impl<'a> EntityFactory<'a> {
150149
pub fn builtin_object(
151150
&self,
152151
object_id: SymbolId,
153-
prototype: &'a Prototype<'a>,
152+
prototype: ObjectPrototype<'a>,
154153
consumable: bool,
155154
) -> &'a mut ObjectEntity<'a> {
156155
self.alloc(ObjectEntity {

crates/tree_shaker/src/entity/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use builtin_fn::PureBuiltinFnEntity;
2525
pub use class::ClassEntity;
2626
pub use factory::EntityFactory;
2727
pub use literal::LiteralEntity;
28-
pub use object::{ObjectEntity, ObjectProperty, ObjectPropertyValue};
28+
pub use object::{ObjectEntity, ObjectProperty, ObjectPropertyValue, ObjectPrototype};
2929
pub use primitive::PrimitiveEntity;
3030
use rustc_hash::FxHashSet;
3131
use std::{cmp::Ordering, fmt::Debug};

crates/tree_shaker/src/entity/never.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a> EntityTrait<'a> for NeverEntity {
9696
&'a self,
9797
_analyzer: &Analyzer<'a>,
9898
) -> Option<rustc_hash::FxHashSet<super::LiteralEntity<'a>>> {
99-
None
99+
Some(rustc_hash::FxHashSet::default())
100100
}
101101
fn get_literal(&'a self, _analyzer: &Analyzer<'a>) -> Option<super::LiteralEntity<'a>> {
102102
None

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

+25-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::ObjectEntity;
1+
use super::{get::GetPropertyContext, ObjectEntity};
22
use crate::{
33
analyzer::Analyzer,
44
consumable::Consumable,
@@ -21,25 +21,31 @@ impl<'a> ObjectEntity<'a> {
2121
analyzer.push_cf_scope_with_deps(CfScopeKind::Dependent, vec![dep], None);
2222

2323
let mut result = vec![];
24-
let mut non_existent = vec![];
24+
let mut context = GetPropertyContext {
25+
key: analyzer.factory.never,
26+
values: vec![],
27+
getters: vec![],
28+
extra_deps: vec![],
29+
};
2530

2631
{
27-
let mut values = vec![];
28-
let mut getters = vec![];
29-
3032
{
3133
let mut unknown_keyed = self.unknown_keyed.borrow_mut();
32-
unknown_keyed.get(analyzer, &mut values, &mut getters, &mut non_existent);
34+
unknown_keyed.get(analyzer, &mut context, None);
3335
if let Some(rest) = &mut *self.rest.borrow_mut() {
34-
rest.get(analyzer, &mut values, &mut getters, &mut non_existent);
36+
rest.get(analyzer, &mut context, None);
3537
}
3638
}
3739

38-
for getter in getters {
39-
values.push(getter.call_as_getter(analyzer, analyzer.factory.empty_consumable, self));
40+
for getter in context.getters.drain(..) {
41+
context.values.push(getter.call_as_getter(
42+
analyzer,
43+
analyzer.factory.empty_consumable,
44+
self,
45+
));
4046
}
4147

42-
if let Some(value) = analyzer.factory.try_union(values) {
48+
if let Some(value) = analyzer.factory.try_union(mem::take(&mut context.values)) {
4349
result.push((false, analyzer.factory.unknown_primitive, value));
4450
}
4551
}
@@ -64,22 +70,24 @@ impl<'a> ObjectEntity<'a> {
6470
analyzer.factory.string(key)
6571
};
6672

67-
let mut values = vec![];
68-
let mut getters = vec![];
69-
property.get(analyzer, &mut values, &mut getters, &mut non_existent);
73+
property.get(analyzer, &mut context, None);
7074
mem::drop(string_keyed);
71-
for getter in getters {
72-
values.push(getter.call_as_getter(analyzer, analyzer.factory.empty_consumable, self));
75+
for getter in context.getters.drain(..) {
76+
context.values.push(getter.call_as_getter(
77+
analyzer,
78+
analyzer.factory.empty_consumable,
79+
self,
80+
));
7381
}
7482

75-
if let Some(value) = analyzer.factory.try_union(values) {
83+
if let Some(value) = analyzer.factory.try_union(mem::take(&mut context.values)) {
7684
result.push((definite, key_entity, value));
7785
}
7886
}
7987
}
8088

8189
analyzer.pop_cf_scope();
8290

83-
(result, analyzer.consumable((dep, non_existent)))
91+
(result, analyzer.consumable((dep, context.extra_deps)))
8492
}
8593
}

0 commit comments

Comments
 (0)