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如何将jasper集成到jhipster项目中   java无法忽略lombok注释   关于tomcat日志的java问题   java@Autowired未设置字段>NullPointerException   GUI提交按钮不工作   java气泡和选择排序   java如何编写规则来匹配两个数组?   java如何找出某个字符在字符串中的第一次、第二次或第三次出现?   java通过字符串引用id   javascript在网络视图中加载在线图表   java保留web应用程序中用户更改的日志   在安卓中尝试使用Mandrill SMTP发送电子邮件时出现java错误   用java语言将a2b4c5等字符串转换为AABBCCCCC的程序是什么?   java无需TODO即可删除所有注释   java JMX MBean在应用程序部署时自动注册   java如何使用JSON解析从任何url解析数据   java@transactional注释类使用代理包装,但未创建事务   JavaFx转换和打印