hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
902 stars 57 forks source link

Use Recast for AST modification in custom.js #4

Closed benjamn closed 10 years ago

benjamn commented 10 years ago

The https://github.com/benjamn/recast package is similar in spirit to falafel, but it has more convenient tools for checking AST node types and creating new AST nodes, which helps simplify the big if-statement in custom.js and also makes it easier to create the replacement Literal nodes.

If that's not something you particularly care about, then feel free to close this pull request. Just thought I'd make the suggestion!

andreypopp commented 10 years ago

+1 on this.

From recast README:

The magic of Recast is that it reprints only those parts of the syntax tree that you modify.

So this means that in a lot of cases envify won't change formatting and line numbers!

hughsk commented 10 years ago

Ah, fantastic - a few of my transforms have been using escodegen and the reformatting can be pretty frustrating. I'll have a proper look at the changes after work and then it should be good to merge :) It'll probably warrant bumping envify up to 1.0.0 too. Thanks @benjamn!

benjamn commented 10 years ago

Glad you like it! Whatever you decide here, I'm curious to know how recast works for you (for this or anything else).

hughsk commented 10 years ago

Looks great, merging and publishing to 1.0.0. Thanks again :) recast seems like a nice alternative to falafel, especially with source map support. I'm gonna have a closer look at using it for my other transforms soon, will let you know if I run into anything!