PHP port of UglifyJS. Since PHP supports closures, it's like some kind of "transliteration".
It supports PHP >= 5.4, but using PHP >= 7.0 is recommended.
It runs 1.5x - 4x slower than the original Node version, depending on the PHP environment. With PHP7, the performance would be acceptable.
- Purely written in PHP, does not need Node.js installed
- Does not require non-default extensions
- Evaluates simple constant expressions correctly
- PHP has no native support of Unicode, and the
mb_*
functions are unbearably slow, so your code cannot contain non-ASCII characters (except in comments). However, Unicode escape sequences are supported. - No support for
ast_lift_variables
andast_consolidate
The APIs should be almost identical to the original ones.
require 'parse-js.php';
require 'process.php';
$orig_code = '... JS code here';
$ast = $parse($orig_code); // parse code and get the initial AST
$ast = $ast_mangle($ast); // get a new AST with mangled names
$ast = $ast_squeeze($ast); // get an AST with compression optimizations
$final_code = $strip_lines($gen_code($ast)); // compressed code here