Skip to main content

es6-compatible javascript minifier

Project description

esprima-compiler is a es6-compatible javascript minifier written by python. esprima-compiler uses esprima-python as javascript parser library

Features

  • ES6 support

  • Mangling function and variable names

  • Ident output

  • Obfuscate strings

Installation

pip install esprima-compiler

Examples

Example javascript file

const Aconst = Math.PI, Bconst = "Bconst";
const Cconst = "Cconst";

function add(a, b){
        function foo(){
                return a+b;
        }
        return foo();
}

const Dconst="Dconst";

function mul(a, b){
        return a*b;
}


const Econst="Econst";
let Alet="Alet";
const Fconst="Fconst", Gconst="Gconst";

Rearrange and mangle variables:

python -m esprima_compiler -r --mangle-variable test.js
const Aconst=Math.PI,Bconst="Bconst",Cconst="Cconst";
function add($a,$b){
  function foo(){
    return $a+$b;
  }
  return foo();
}
const Dconst="Dconst";
function mul($a,$b){
  return $a*$b;
}
const Econst="Econst",Fconst="Fconst",Gconst="Gconst";
let Alet="Alet";

Rearrange variables and mangle variables (include top level) and function names (except top-level):

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

Rearrange variables and mangle variables and function names (include top level) without identing:

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

Compile javascript string:

>>> from esprima_compiler.compiler import Compiler
>>> 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;
class TestClass extends Object{
  constructor($d,$e){
    this._a=$d;
    this.b=$e;
  }
  static get a(){
    return this._a;
  }
  set b($d){
    this.b=$d;
  }
  static async sum(){
    return this.a+this.b;
  }
}
>>>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

esprimajs-0.1.0.tar.gz (13.3 kB view details)

Uploaded Source

File details

Details for the file esprimajs-0.1.0.tar.gz.

File metadata

  • Download URL: esprimajs-0.1.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for esprimajs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 590511d479eba35f389a9caa64d274c2a6aa4243ac2a910b0e27dbe7927a298f
MD5 8859e09cac45155eb26aacd78bd94362
BLAKE2b-256 6c29941f3a74cf776ddad73832596516e68aef6ab87d5512754347ac96478233

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page