[Javascirpt AST] Babel Plugin -- create new CallExpression
The code we want to trasform:
2 ** 3;
a ** b;
a **b * c;
a ** b ** c;
(a+1) ** (b+1);
transform to:
Math.pow(2, 3);
Math.pow(a, b);
Math.pow(a, b) * c;
Math.pow(a, Math.pow(b, c));
Math.pow(a+1, b+1);
Code:
export default function (babel) {
const { types: t } = babel; return {
name: "ast-transform", // not required
visitor: {
BinaryExpression (path) {
console.log(t )
const isPowOpreator = path.node.operator === '**';
if(!isPowOpreator) {
return;
} const {left, right} = path.node; path.replaceWith(t.callExpression( // create Math.pow() node
t.memberExpression(
t.identifier('Math'),
t.identifier('pow')
),
[left, right] // pass in Math.pow(left, right)
))
}
}
};
}
[Javascirpt AST] Babel Plugin -- create new CallExpression的更多相关文章
- [AST Babel Plugin] Transform code, add line:column number for console log
For example we have current code: function add(a, b) { console.log(a, b) return a + b } function sub ...
- [AST Babel Plugin] Hanlde ArrowFunction && FunctionExpression
Continue with previous post: https://www.cnblogs.com/Answer1215/p/12342540.html Now we need to think ...
- [Javascript AST] 1. Continue: Write a simple Babel plugin
We want to write a Babel Plugin, which move 'const versionRegex = /(/d+)\.(/d+)\.(/d+)/gi' out of fu ...
- 简单 babel plugin 开发-使用lerna 工具
babel在现在的web 应用开发上具有很重要的作用,帮助我们做了好多事情,同时又有 比较多的babel plugin 可以解决我们实际开发上的问题. 以下只是学习下如果编写一个简单的babel pl ...
- babel plugin和presets是什么,怎么用?
https://www.fullstackreact.com/articles/what-are-babel-plugins-and-presets/ 当开发react或者vuejs app时,开发者 ...
- [AST Babel] Add function name into the console log 'path.findParent(t.isFunctionDeclaration)'
Continue with the previous post: https://www.cnblogs.com/Answer1215/p/12337243.html What we want to ...
- babel plugin
a = () => {}, // Support for the experimental syntax 'classProperties' isn't currently enabled ya ...
- [Javascript AST] 0. Introduction: Write a simple BabelJS plugin
To write a simple Babel plugin, we can use http://astexplorer.net/ to help us. The plugin we want to ...
- 前端工程师需要掌握的 Babel 知识
在前端圈子里,对于 Babel,大家肯定都比较熟悉了.如果哪天少了它,对于前端工程师来说肯定是个噩梦.Babel 的工作原理是怎样的可能了解的人就不太多了.本文将主要介绍 Babel 的工作原理以及怎 ...
随机推荐
- MVP模式入门(结合Rxjava,Retrofit)
本文MVP的sample实现效果: github地址:https://github.com/xurui1995/MvpSample 老规矩,在说对MVP模式的理解之前还是要再谈谈MVC模式,了解了MV ...
- JWT Authentication Tutorial: An example using Spring Boot--转
原文地址:http://www.svlada.com/jwt-token-authentication-with-spring-boot/ Table of contents: Introductio ...
- 使用iframe在手机中嵌套页面
使用iframe嵌套网页 <iframe id="show-iframes" frameborder="0" name="showHere&qu ...
- 联想 Thinkserver TS250服务器RAID1 重建测试
1.RAID1状态下,拨掉其中一块硬盘后,RAID1即失效. 2.重新插入后,在进行系统后会自动重建 *RAID1 提示Rebuild *进入桌面后软件,显示重建进度 软件下载地址:https://p ...
- python jieba分词工具
源码地址:https://github.com/fxsjy/jieba 演示地址:http://jiebademo.ap01.aws.af.cm/ 特点 1,支持三种分词模式: a,精确模式,试图将句 ...
- DEDE 修改后台图集上传单个图片的大小限制
默认情况下,DEDE图集中单个图片大小限制在2M以内,而有时我们需要上传一个2M以上的文件,这是只要修改几个文件就可以实现了. 一.需要修改php.ini这个文件,我们必须保证PHP的配置中允许上传一 ...
- debian8平滑升级到debian9
本文在Creative Commons许可证下发布. 首先,在升级时可以查看一下自己的版本号: uname -a ##查看内核信息 cat /etc/issue ##查看发行版本号 方法1:利用网 ...
- Windows Server 2016 主域控制器搭建
基本上微软产品都需要依附于域控制器做身份认证,接下来我们一起来对Windows Server 2016 进行AD活动目录功能添加.1.更改服务器IP地址2.修改计算机名称(重新启动计算机)3.打开服务 ...
- python编程练习
python练习之冒泡排序: python代码: #coding=utf-8 if __name__=="__main__": arr=[3,2,1,7,11,4,5,8] pri ...
- 构建基于Javascript的移动CMS——加入滑动
在和几个有兴趣做移动CMS的小伙伴讨论了一番之后,我们认为当前比較重要的便是统一一下RESTful API.然而近期持续断网中,又遭遇了一次停电,暂停了对API的思考.在周末无聊的时光了看了<人 ...