tildeio / htmlbars

A variant of Handlebars that emits DOM and allows you to write helpers that manipulate live DOM nodes
MIT License
1.61k stars 193 forks source link

Pruning of nodes through plugins / Walker #373

Open zackthehuman opened 9 years ago

zackthehuman commented 9 years ago

Hi. I have a use case where I need to remove nodes from the AST as part of a custom precompilation step. I want to walk the AST and remove certain helpers nodes, but there doesn't seem to be a way to do it (at least not through a plugin through ember-cli). Is this possible or does this need to be built out?

mmun commented 9 years ago

@zackthehuman The current walker is pretty crappy and I have plans to write a new one in the style of babel plugins / estraverse. Basically the "visitor with replacement" pattern. Are you interested in working on that? Happy to chat about it in #dev-glimmer on the Ember community slack.

mmun commented 9 years ago

Also the AST is not public yet so you might experience some breakage in the future. I'd like to have a similar API as ast-types, e.g. t.isHTMLComment(node).

zackthehuman commented 9 years ago

Understood. This is something I would be interested in helping with for sure. At first I thought I could just use the AST Visitor from Handlebars but it turns out that wasn't the case :(. The nice thing about that visitor is it follows the "visitor with replacement" pattern you describe.