beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.52k stars 1.36k forks source link

Add option to extend the beautifier with custom tokenizers/formatters #250

Open bitwiseman opened 11 years ago

bitwiseman commented 11 years ago

Several recent issues filed would require siginifcant changes to the core tokenizing, parsing, and/or formatting code. For example, #234, and #223. The user implemented #234 and we accepted it because it was basically self-contained, but #223 would require quite a bit more work and doesn't seem to be part of any javascript spec.

Still, there are many flavors of javascript and these javascript-ish dialects are proliferating. If we added a few well-defined extension/plugin points we could better focus on our core goals. Over time we could even add some plugins to the distribution, providing a greater value to users.

Same principles would apply, extensions would need to not break the core features (and possibly other plugins), and would need to have tests.

evocateur commented 11 years ago

I definitely agree with the spirit of this proposal. Keep the core focused, allow powerful plugins.

The implementation, however, seems to beg for an AST (#200) that could be sent to plugins at well-defined steps (before/after default transforms, before "printing", etc). The various options we have now, like brace-style, could even be implemented as built-in plugins (similar to Express middleware, in my mind (perhaps addled by all the middleware-related work I've been doing recently)).

bitwiseman commented 11 years ago

Yeah, that's about where I was going, though I was hoping we could avoid a full AST.

prettydiff commented 7 years ago

If you would like you could use the Pretty Diff parsers and maintain independent beautification. I would have some work to do on my end to make this possible. Currently the parser, beautifier, analyzer, and other features are in the very same file for a respective language category. I would need to break these apart so that the parser is in a separate file for easier consumption. I would also need to write additional documentation to explain the API and some qualities that right now are purely internal or for things that I have not explicitly thought about explaining.

If you are interested just let me know I will open an issue to make this happen.

Some details about the parsers: