ES6兼容的JavaScript迷你型程序

esprimajs的Python项目详细描述


esprima编译器是一个由python编写的与es6兼容的javascript小型化器。 esprima编译器使用esprima-python 作为javascript解析器库

功能

  • ES6支持
  • 损坏函数和变量名
  • 识别输出
  • 模糊字符串

安装

pip install esprima-compiler

示例

示例javascript文件

constAconst=Math.PI,Bconst="Bconst";constCconst="Cconst";functionadd(a,b){functionfoo(){returna+b;}returnfoo();}constDconst="Dconst";functionmul(a,b){returna*b;}constEconst="Econst";letAlet="Alet";constFconst="Fconst",Gconst="Gconst";

重新排列和更改变量:

python -m esprima_compiler -r --mangle-variable test.js
constAconst=Math.PI,Bconst="Bconst",Cconst="Cconst";functionadd($a,$b){functionfoo(){return$a+$b;}returnfoo();}constDconst="Dconst";functionmul($a,$b){return$a*$b;}constEconst="Econst",Fconst="Fconst",Gconst="Gconst";letAlet="Alet";

重新排列变量和损坏变量(包括顶层)以及函数名(顶层除外):

python -m esprima_compiler -r --mangle-variable-top --mangle-function test.js
const$a=Math.PI,$b="Bconst",$c="Cconst";functionadd($d,$e){function$f(){return$d+$e;}return$f();}const$d="Dconst";functionmul($e,$f){return$e*$f;}const$e="Econst",$f="Fconst",$g="Gconst";let$h="Alet";

重新排列变量、更改变量和函数名(包括顶层),但不标识:

python -m esprima_compiler -i 0 -r --mangle-variable-top --mangle-function-top --mangle-function test.js
const$a=Math.PI,$b="Bconst",$c="Cconst";function$d($e,$f){function$g(){return$e+$f;}return$g();}const$e="Dconst";function$f($g,$h){return$g*$h;}const$g="Econst",$h="Fconst",$i="Gconst";let$j="Alet";

API

编译javascript字符串:

>>>fromesprima_compiler.compilerimportCompiler>>>c=Compiler(rearrange=True,mangle_variable=True,mangle_variable_top=True)>>>js="""
... const A=1;
... const B=2;
... let C=3;
...
... class TestClass extends Object{
...   constructor(a, b){
...     this._a=a;
...     this.b=b;
...   }
...   static get a(){
...     return this._a;
...   }
...   set b(b){
...     this.b=b;
...   }
...
...   static async sum(){
...     return this.a+this.b
...   }
... }
... """>>>buf=c.compile(js)>>>print(buf.read())const$a=1,$b=2;let$c=3;classTestClassextendsObject{constructor($d,$e){this._a=$d;this.b=$e;}staticgeta(){returnthis._a;}setb($d){this.b=$d;}staticasyncsum(){returnthis.a+this.b;}}>>>

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何忽略缓冲读取器中在“”之后的行的其余部分,或行上的特定字符?   java在db中创建空对象或稍后保存   java如何实现UI无关的后台工作任务   java未能在Android中从BaseAdapter扩展的类中启动Tactivity?   java斐波那契迭代移动数组[]   安卓从文件读取提供了java。木卫一。StreamCorruptedException:无效的流标头:73720027   java计算矩形中的六边形数?   仅使用Java 1.5(或更早版本)读写XML   java如果所有元素都以相同的bucked结尾,为什么要进行大小调整?   java Apache POI Excel在xx中发现无法读取的内容。xlsx   swing我可以在普通java应用程序中使用GWTGUI吗?   来自自定义Java客户端的http删除请求的行为与邮递员不同   运行批处理文件时,java当前目录无效   使用TypeReference将java字符串转换为ArrayList<STRING>   documentlistener突出显示所有匹配词Java