ezno_checker/types/
classes.rs1use source_map::SpanWithSource;
2
3use crate::{
4 events::Event, features::functions::ClassPropertiesToRegister, types::properties::Publicity,
5 CheckingData, Environment, PropertyValue, TypeId,
6};
7
8use super::properties::PropertyKey;
9
10pub enum PropertyFunctionProperty {
12 Get,
13 Set,
14 Standard { is_async: bool, is_generator: bool },
15}
16
17pub struct ClassValue<'a, A: crate::ASTImplementation> {
18 pub publicity: Publicity,
19 pub key: PropertyKey<'static>,
21 pub value: Option<&'a A::Expression<'a>>,
22}
23
24pub struct SynthesisedClassValue {
25 pub publicity: Publicity,
26 pub key: PropertyKey<'static>,
28 pub effects: Vec<Event>,
29 pub value: TypeId,
30}
31
32pub struct RegisterClassPropertiesEvent {
44 pub properties: Vec<SynthesisedClassValue>,
45 pub class_prototype: TypeId,
46}
47
48fn _register_class_properties_for_later_application<
49 T: crate::ReadFromFS,
50 A: crate::ASTImplementation,
51>(
52 environment: &mut Environment,
53 class_prototype: TypeId,
54 properties: ClassPropertiesToRegister<A>,
55 checking_data: &mut CheckingData<T, A>,
56 position: SpanWithSource,
57) {
58 let scope = crate::Scope::Function(crate::context::environment::FunctionScope::Constructor {
59 extends: false,
60 type_of_super: Some(TypeId::UNIMPLEMENTED_ERROR_TYPE),
61 this_object_type: TypeId::UNIMPLEMENTED_ERROR_TYPE,
63 });
64
65 let ((), result, _) = environment.new_lexical_environment_fold_into_parent(
66 scope,
67 checking_data,
68 |environment, checking_data| {
69 register_properties_into_environment(
70 environment,
71 class_prototype,
72 checking_data,
73 properties,
74 position,
75 );
76 },
77 );
78 let (_events, _free_variables) = result.unwrap();
79
80 todo!()
82}
83
84pub(crate) fn register_properties_into_environment<
85 T: crate::ReadFromFS,
86 A: crate::ASTImplementation,
87>(
88 environment: &mut Environment,
89 on: TypeId,
90 checking_data: &mut CheckingData<T, A>,
91 ClassPropertiesToRegister { properties }: ClassPropertiesToRegister<A>,
92 position: SpanWithSource,
93) {
94 for ClassValue { publicity, key, value } in properties {
95 let value = if let Some(expression) = value {
96 PropertyValue::Value(A::synthesise_expression(
97 expression,
98 TypeId::ANY_TYPE,
99 environment,
100 checking_data,
101 ))
102 } else {
103 PropertyValue::Value(TypeId::UNDEFINED_TYPE)
104 };
105 environment.info.register_property(on, publicity, key, value, position);
106 }
107}