pzuraq / macro-decorators

Decorators for getter/setter macros!
https://pzuraq.github.io/macro-decorators/
MIT License
62 stars 10 forks source link

Basic support for expansion syntax #14

Open andreyfel opened 4 years ago

andreyfel commented 4 years ago

This PR partially addresses the 2nd concern from #11. This is how expansion syntax is implemented in Ember: https://github.com/emberjs/ember.js/blob/master/packages/%40ember/-internals/metal/lib/expand_properties.ts It doesn't support nested syntax but supports some other edge cases like:

'a.{b,c,d}.e' => ['a.b.e', 'a.c.e', 'a.d.e']
'{a,b,c}.d.{e,f}.g' => ['a.d.e.g', 'a.d.f.g', 'b.d.e.g', 'b.d.f.g', 'c.d.e.g', 'c.d.f.g']

See tests https://github.com/emberjs/ember.js/blob/master/packages/%40ember/-internals/metal/tests/expand_properties_test.js

These cases seems like it is too much for macro-decorators but the very basic expansion syntax can be helpful as it might be used in many Ember apps willing to migrate to @tracked properties.

'a.{b,c,d}' => ['a.b', 'a.c', 'a.d']
andreyfel commented 4 years ago

Note that we don't make any checks if the syntax is supported like Ember does using assert.

I believe the error message would be helpful, to prevent confusion during migration if those edge cases were used in Ember apps. But I'm not sure what is the best way to do those checks. Just throw an error if users are trying to use unsupported syntax?