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.3k stars 42 forks source link

Implement destructuring assignment (declaration works already) #106

Closed kaleidawave closed 2 months ago

kaleidawave commented 6 months ago

While declaration destructuring is implemented (aka you can declare some variables where the LHS destructors the RHS value), the assignment part is not implemented

https://github.com/kaleidawave/ezno/blob/7eb3a31b02f7fd9a2e6055951948c250fd4e8719/checker/src/context/environment.rs#L412-L413

For

let array1 = [1, 2, 3];
let a = 0, b = 0;
[a, b] = array1;

a satisfies 1;
b satisfies "hello world";

to work. It should be very similar (but different as it is acting on intermediate level rather than AST) to the assign_fields function used for the declaration kind

https://github.com/kaleidawave/ezno/blob/7eb3a31b02f7fd9a2e6055951948c250fd4e8719/checker/src/synthesis/variables.rs#L198

The implementation should be very similar to the current behaviour for assigning to a variable, however it needs to do the recursive assignment and get_property things from destructuring.