unsplash / intlc

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

Prettified codegen #5

Open samhh opened 2 years ago

samhh commented 2 years ago

It's all on a single line at the moment. We'll probably run Prettier against it in web, but ideally the output would be more legible out of the box.

samhh commented 2 years ago

This'd also make golden test output diffs more legible.

samhh commented 2 years ago

I guess one way to implement this would be to convert the JS Compiler from Reader Cfg to RWS Cfg () State where State tracks indent level. Then wherever there's an indentable block, like opening a function body in a switch statement, we call a helper indent :: Compiler a -> Compiler a which increments the state, compiles the contents with indentation, and then decrements on the way back out - similar to withPluralCtx in Intlc.Parser.

Edit: Can use Reader local for this, see #173.