[英]`esprima` AST Tree: How to easily detect and add function parens?
TL;DR: i want to do same thing as there https://github.com/nolanlawson/optimize-js but with esprima
when i traverse through AST tree with estraverse
. TL; DR:我想做与https://github.com/nolanlawson/optimize-js相同的事情,但是当我使用esprima
遍历 AST 树时使用estraverse
。
ESPrima gives same output nodes for following code: ESPrima 为以下代码提供相同的输出节点:
!function (){}()
and和
!(function (){})()
http://esprima.org/demo/parse.html?code=!function%20()%7B%7D()%0A%0A!(function%20()%7B%7D)() http://esprima.org/demo/parse.html?code=!function%20()%7B%7D()%0A%0A!(function%20()%7B%7D)()
For example - i will traverse through AST tree.例如 - 我将遍历 AST 树。 On Function Expression ExpressionStatement node i want to check - if that node doesn't have parens around function - i want to add it.在 Function Expression ExpressionStatement 节点上,我想检查 - 如果该节点在函数周围没有括号 - 我想添加它。
So, how i can detect function parens, how i can add them?那么,我如何检测函数括号,如何添加它们? I look at tokens, but i have no idea how i can associate flat tokens object with object with specified AST node.我查看令牌,但我不知道如何将平面令牌对象与具有指定 AST 节点的对象相关联。
似乎它的任务不是针对 esprima,而是针对 escodegen https://github.com/estools/escodegen/issues/315
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.