htmlbars icon indicating copy to clipboard operation
htmlbars copied to clipboard

Pruning of nodes through plugins / Walker

Open zackthehuman opened this issue 9 years ago • 3 comments

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?

zackthehuman avatar Jul 02 '15 21:07 zackthehuman

@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 avatar Jul 02 '15 21:07 mmun

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).

mmun avatar Jul 02 '15 21:07 mmun

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.

zackthehuman avatar Jul 02 '15 23:07 zackthehuman