作家
登录

JavaScript语法树与代码转化实践

作者: 来源: 2017-07-27 09:55:49 阅读 我要评论

 
  • // 代码结不雅 
  •   function square(n) { 
  • -   return n * n; 
  • +   "Anyway the wind blows, doesn't really matter to me, to me."
  •   }  
    • 移除某个父节点
    1. // 插件定义 
    2. BinaryExpression(path) { 
    3.   path.parentPath.remove(); 
    4.  
    5. // 代码结不雅 
    6.   function square(n) { 
    7. -   return n * n; 
    8.   }  
    1. FunctionDeclaration(path) { 
    2.   if (path.scope.hasBinding("n")) { 
    3.     // ... 
    4.   } 
    5.  
    6. FunctionDeclaration(path) { 
    7.   if (path.scope.hasOwnBinding("n")) { 
    8.     // ... 
    9.   } 
    10.  
    • 创建 UID
    1. // 插件定义 
    2. FunctionDeclaration(path) { 
    3.   const id = path.scope.generateUidIdentifierBasedOnNode(path.node.id); 
    4.   path.remove(); 
    5.   path.scope.parent.push({ id, init: path.node }); 
    6.  
    7. // 代码结不雅 
    8. function square(n) { 
    9. + var _square = function square(n) { 
    10.     return n * n; 
    11. - } 
    12. + };  

    【编辑推荐】

    1. 前端模板的道理与实现
    2. 给Python小白看的10个应用案例,入门Python就在这里了
    3. 深刻懂得游戏中寻路算法
    4. 前端机能优化
    5. 换个思路懂得Javascript中的this
    【义务编辑:枯木 TEL:(010)68476606】

      推荐阅读

      海南常见罪名量刑细则实施 人工智能助力司法改革

    2009年6月,我省开端量刑规范化改革,是全国第二批试点省份。据介绍,海南最新版的量刑细则涵盖了23个常见着绫躯和罚金刑、缓刑实用,所涉的刑事犯法案件占到我省刑事案件的95%以上。此次>>>详细阅读


    本文标题:JavaScript语法树与代码转化实践

    地址:http://www.17bianji.com/lsqh/36429.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)