DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.33k stars 28 forks source link

Fix handling of empty arrays and objects in patterns #1202

Closed edemaine closed 2 months ago

edemaine commented 2 months ago

Fix the issue mentioned here: https://github.com/DanielXMoore/Civet/pull/1200#discussion_r1583864309

This turned out to be tricky to figure out, as it had to do with the generator! ArrayBindingPattern nodes have a length field which was zero in this case. We could instead remove length fields from AST node objects, but it seems like a useful field name (I'd rather have it defined for ObjectBindingPattern too so that code could be more symmetric), and maybe used a fair amount around array patterns, so changing the generator seemed better. Note that empty arrays are still also removed, using the code down below.