We want to write a Babel Plugin, which move 'const versionRegex = /(/d+)\.(/d+)\.(/d+)/gi' out of function scope and put it into global scope. Code: function getVersion(versionString) { const versionRegex = /(\d+)\.(\d+)\.(\d+)/gi var x = /foo/.text(…
To write a simple Babel plugin, we can use http://astexplorer.net/ to help us. The plugin we want to write is: var foo = 'o' var bar = 'o' foo === bar function foo(foo, bar) { foo === bar; } We want to trasnform the code which highlighted in foo() fu…
const disallowedMethods = ["log", "info", "warn", "error", "dir"]; module.exports = { meta: { docs: { description: "Disallow use of console", category: "Best Practices", recommended: tr…
The rule we want to write is show warning if user using console method: // valid foo.console() console() info() console.baz() // invalid console.log() console.info() console.warn() Rule: const disallowedMethods = ["log", "info", "…
What we want to do is checking if user write nested if statements which actually can combine to one: // BAD if (a) { console.log("a"); } else { if (b) { console.log("b"); } } // GOOD if (a) { console.log("a"); } else if (b) {…
1.错误描述 An internal error occurred during: "Requesting JavaScript AST from selection".      GC overhead limit exceeded 单击"OK"后,提示如下图所示: 2.错误原因 由于用Eclipse编写JavaScript时,出现了return,位置不对,导致错误 3.解决办法 Windows--->Preference--->JavaScript…
之前一直在掘金上看到一些关于面试写babel插件的文章,最近也在学,以下就是学习后的总结. 关键词:AST编译解析, babel AST编译解析 AST[维基百科]:在计算机科学中,抽象语法树(Abstract Syntax Tree,AST),或简称语法树(Syntax tree),是源代码语法结构的一种抽象表示.它以树状的形式表现编程语言的语法结构,树上的每个节点都表示源代码中的一种结构.之所以说语法是"抽象"的,是因为这里的语法并不会表示出真实语法中出现的每个细节.比如,嵌套括号…
For example we have current code: function add(a, b) { console.log(a, b) return a + b } function subtract(a, b) { console.log(a, b) return a - b } add(, ) subtract(, ) console.log('sup dawg') We want to transform the code to: function add(a, b) { con…
babel在现在的web 应用开发上具有很重要的作用,帮助我们做了好多事情,同时又有 比较多的babel plugin 可以解决我们实际开发上的问题. 以下只是学习下如果编写一个简单的babel plugin,项目使用lerna 进行代码包管理 插件开发模型 项目准备 lerna 项目初始化 lerna init 创建plugin package lerna create MyFirstBabelPlugin 创建使用plugin 的package lerna create PluginUsag…
https://www.fullstackreact.com/articles/what-are-babel-plugins-and-presets/ 当开发react或者vuejs app时,开发者可能经常需要在不同的babel configuration(.bablerc)中切换.你应该在package.json文件中见到过以下代码: // package.json { "babel": { "presets": [ "es2015", &q…