kaleidawave / ezno

A JavaScript compiler and TypeScript checker written in Rust with a focus on static analysis and runtime performance
https://kaleidawave.github.io/posts/introducing-ezno/
MIT License
2.44k stars 45 forks source link

Fix and figure out how multiple properties should be represented #99

Open kaleidawave opened 9 months ago

kaleidawave commented 9 months ago

Currently there is no difference in the representation of properties that are dependent once OR multiple times.

aka { [a: number]: "value" } has under a context properties as [(PropertyKey::Type(*number type*), Property::Value(TypeId -> Type::Constant(Constant::String("value")))]. There is no difference between this being a project with many keys that are number like OR a single key, which is of the type of number.

I think this can be solved by a separate variant Property on the RHS called Property::Multiple(Box<Property>) which denotes that the RHS property is dependent. This only makes sense if the LHS is PropertyKey::Type though 🤔. Also the RHS needs depend of types from the LHS for type mappings in TypeScript 🤔🤔

kaleidawave commented 3 months ago

Quite happy with how PropertyValue is now. Probably 90% done

/// TODO getter, setting need a closure id
#[derive(Clone, Debug, binary_serialize_derive::BinarySerializable)]
pub enum PropertyValue {
    Value(TypeId),
    Getter(Box<FunctionType>),
    Setter(Box<FunctionType>),
    /// TODO doesn't exist Deleted | Optional
    Deleted,
    ConditionallyExists {
        on: TypeId,
        truthy: Box<Self>,
    },
}