com.shapesecurity.shift.es2017.minifier.README.md Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of es2017 Show documentation
Show all versions of es2017 Show documentation
Shift format ECMAScript 2017 AST tooling
Shift AST Minifier
==================
## Description
The `Minifier` class takes a `Script` object and transforms the AST so that it may be represented using the smallest
source length.
## Usage
```java
import com.shapesecurity.shift.minifier.Minifier;
import com.shapesecurity.shift.parser.Parser;
import com.shapesecurity.shift.codegen.CodeGen;
// parse a javascript program
String js = "a; b;";
Script p = Parser.parse(js);
// specifying reduction/expansion rules for minification
List reductionRules = List.list<>(FlattenBlocks.INSTANCE, ReduceNestedIfStatements.INSTANCE, ...);
List expansionRules = List.list<>();
Script pPrime = Minifier.minify(p, reductionRules, expansionRules);
String minified1 = CodeGen.codeGen(pPrime);
// using the default sets of reduction/expansion rules
Script pPrimePrime = Minifier.minify(p);
String minified2 = CodeGen.codeGen(pPrimePrime);
```