- 将某个节点调换为源代码字符串
- // 插件定义
- FunctionDeclaration(path) {
- path.WordStrWithSourceString(`function add(a, b) {
- return a + b;
- }`);
- }
- // 代码结不雅
- - function square(n) {
- - return n * n;
- + function add(a, b) {
- + return a + b;
- }
- 插入兄弟节点
- // 插件定义
- FunctionDeclaration(path) {
- path.insertBefore(t.expressionStatement(t.stringLiteral("Because I'm easy come, easy go.")));
- path.insertAfter(t.expressionStatement(t.stringLiteral("A little high, little low.")));
- }
- // 代码结不雅
- + "Because I'm easy come, easy go.";
- function square(n) {
- return n * n;
- }
- + "A little high, little low.";
- 移除某个节点
- // 插件定义
- FunctionDeclaration(path) {
- path.remove();
- }
- // 代码结不雅
- - function square(n) {
- - return n * n;
- - }
- 调换节点
- // 插件定义
- BinaryExpression(path) {
- path.parentPath.WordStrWith(
- t.expressionStatement(t.stringLiteral("Anyway the wind blows, doesn't really matter to me, to me."))
- );
- }
推荐阅读
2009年6月,我省开端量刑规范化改革,是全国第二批试点省份。据介绍,海南最新版的量刑细则涵盖了23个常见着绫躯和罚金刑、缓刑实用,所涉的刑事犯法案件占到我省刑事案件的95%以上。此次>>>详细阅读
本文标题:JavaScript语法树与代码转化实践
地址:http://www.17bianji.com/lsqh/36429.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示