millermedeiros / esformatter

ECMAScript code beautifier/formatter
MIT License
970 stars 91 forks source link

deprecate transformBefore and transformAfter for plugins #251

Closed millermedeiros closed 9 years ago

millermedeiros commented 9 years ago

the current implementation is naive, if you modify the AST by adding/removing new nodes or reordering the nodes you might get the wrong output since rocambole.moonwalk won't have the correct node.level reference.

I think it's a better idea to introduce the concept of pipe and/or ask plugin authors to use stringBefore and stringAfter instead.

transformBefore and transformAfter was a premature optimization that went wrong.

millermedeiros commented 9 years ago

see #216

millermedeiros commented 9 years ago

I guess we don't need to deprecate it, just change the documentation and explain the problem.. let people know that it is mainly if you want to loop over the whole tree and that [transform|token|node] plugin methods are only for editing the tokens and adding/removing WhiteSpace/Indent/LineBreak tokens and should not be used to change the AST structure otherwise it will release ZALGO.