coderaiser / putout

🐊 Pluggable and configurable JavaScript Linter, code transformer and formatter, drop-in ESLint superpower replacement πŸ’ͺ with built-in support for js, jsx, typescript, flow, markdown, yaml and json. Write declarative codemods in a simplest possible way 😏
https://putout.cloudcmd.io/
MIT License
698 stars 40 forks source link

Question: Reverse mode #195

Closed enzonotario closed 8 months ago

enzonotario commented 8 months ago

Hi there!

Is there any way to run transformations in "reverse mode"? so that I can get the original code back from the transformed code.

Thanks!

coderaiser commented 8 months ago

There is no such a feature, anyways there is a couple ways you can achieve this:

What option do you think would be the best?

enzonotario commented 8 months ago

Well, maybe I'm wrong but let me explain what I want to do:

I have a little project EsJS that wants to "extend" JavaScript with Spanish keywords. Of course, I saw your Goldstein project, but I want to try Putout without extending Acorn.

For now, my little project does a basic transpilation, by tokenizing the code and just looking for a translation. I want to improve a bit more this, and was trying to use Putout. It works fine for EsJS -> JS, but I also want to have a bi-directional transpilation.

As Putout works for me in a way, I wonder if I can transform the code in the other way to replace my "basic transpilation" with Putout (and then look up for more improvements).

So, the options you mentioned don't resolve my needs... I think I could write my "reverse rules" to do this. But, also maybe I'm doing this wrong, and will have to do this in others ways. What do you think? Thanks in advance!

coderaiser commented 8 months ago

Yes, 🀫Goldstein can help you do to what you want with help of:

But the most important thing is @putout/printer, you can override it in any way you want using Babel AST, here is example.

enzonotario commented 8 months ago

Nice, thank you so much!

I've checked Goldstein but I was looking at the Acorn Extension (here for example). I'll check the Printer more in depth! Thanks!