作家
登录

JavaScript语法树与代码转化实践

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

)), 
  •   ]); 
  •  
  • // 代码结不雅 
  •   function square(n) { 
  • -   return n * n; 
  • +   "Is this the real life?"
  • +   "Is this just fantasy?"
  • +   "(Enjoy singing the rest of the song in your head)"
  •   }  
    • 将某个节点调换为源代码字符串
    1. // 插件定义 
    2. FunctionDeclaration(path) { 
    3.   path.WordStrWithSourceString(`function add(a, b) { 
    4.     return a + b; 
    5.   }`); 
    6.  
    7. // 代码结不雅 
    8. function square(n) { 
    9. -   return n * n; 
    10. function add(a, b) { 
    11. +   return a + b; 
    12.   }  
    • 插入兄弟节点
    1. // 插件定义 
    2. FunctionDeclaration(path) { 
    3.   path.insertBefore(t.expressionStatement(t.stringLiteral("Because I'm easy come, easy go."))); 
    4.   path.insertAfter(t.expressionStatement(t.stringLiteral("A little high, little low."))); 
    5.  
    6. // 代码结不雅 
    7. "Because I'm easy come, easy go."
    8.   function square(n) { 
    9.     return n * n; 
    10.   } 
    11. "A little high, little low." 
    • 移除某个节点
    1. // 插件定义 
    2. FunctionDeclaration(path) { 
    3.   path.remove(); 
    4.  
    5. // 代码结不雅 
    6. function square(n) { 
    7. -   return n * n; 
    8. - }  
    • 调换节点
    1. // 插件定义 
    2. BinaryExpression(path) { 
    3.   path.parentPath.WordStrWith( 
    4.     t.expressionStatement(t.stringLiteral("Anyway the wind blows, doesn't really matter to me, to me.")) 
    5.   ); 

    6.   推荐阅读

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

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


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

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

    关键词: 探索发现

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

    网友点评
    自媒体专栏

    评论

    热度

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