unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
MIT License
56 stars 2 forks source link

Combine transformations #187

Closed samhh closed 1 year ago

samhh commented 1 year ago

In Web we currently do:

intlc flatten "$in" | intlc-internal expand-plurals > "$out"

This means we're parsing the input twice and compiling the output twice. It also means that our recursion schemes can't potentially fuse for better performance.

Some sort of command that combines these efficiently could make a large impact.

samhh commented 1 year ago

To allow merging commands across external and internal, the internal stuff could be moved into external but hidden from -h with the hidden modifier. I suppose our internal lints would need to be hidden behind a flag as well.

samhh commented 1 year ago

Here are all the commands we currently support:

The first four all happen to provide different outputs. Namely, respectively:

Internal lints could be behind a hidden --internal flag on intlc lint. Plural expansion outputs ICU JSON like flattening.

I'm not sure how to design a safe, extensible, comprehendible CLI in which you can mix and match compatible commands. I can however imagine the following, which would be functionally as flexible as what we have today. It'd theoretically allow for performance optimisations as everything you'd need for a given output would be packed into a single call to intlc:

I think any other combinations of commands should be redundant, such as flattening or plural expansion before compiling. It's not ideal hiding plural expansion behind flattening, but then it's an internal flag that we always use in that context, so it's okay for now.

The only concern with this is how extensible it is, for example if plural expansion became something that should be external. We could wind up with countless commands and flags that all need to be available on one-another. But maybe we'll never cross that bridge.

samhh commented 1 year ago

Combining the two entrypoints would also implicitly close #191.