// Compression
uAST.figure_out_scope();
- uAST = uAST.transform(UglifyJS.Compressor(options));
+ uAST = UglifyJS.Compressor(options).compress(uAST);
// Mangling (optional)
if (mangle) {
Like this:
```javascript
var compressor = UglifyJS.Compressor(options);
-var compressed_ast = toplevel.transform(compressor);
+var compressed_ast = compressor.compress(toplevel);
```
The `options` can be missing. Available options are discussed above in
booleans : !false_by_default,
loops : !false_by_default,
unused : !false_by_default,
- toplevel : !!options["top_retain"],
+ toplevel : !!(options && options["top_retain"]),
top_retain : null,
hoist_funs : !false_by_default,
keep_fargs : true,
if_return : !false_by_default,
join_vars : !false_by_default,
collapse_vars : !false_by_default,
- reduce_vars : false,
+ reduce_vars : !false_by_default,
cascade : !false_by_default,
side_effects : !false_by_default,
pure_getters : false,
if (node instanceof AST_SymbolRef) {
var d = node.definition();
d.references.push(node);
- if (!d.modified && (d.orig.length > 1 || isModified(node, 0))) {
- d.modified = true;
+ if (d.fixed && (d.orig.length > 1 || isModified(node, 0))) {
+ d.fixed = false;
}
}
if (node instanceof AST_Call && node.expression instanceof AST_Function) {
this.walk(tw);
function reset_def(def) {
- def.modified = false;
+ def.fixed = true;
def.references = [];
def.should_replace = undefined;
if (unsafe && def.init) {
this._evaluating = true;
try {
var d = this.definition();
- if (compressor.option("reduce_vars") && !d.modified && d.init) {
+ if (compressor.option("reduce_vars") && d.fixed && d.init) {
if (compressor.option("unsafe")) {
if (d.init._evaluated === undefined) {
d.init._evaluated = ev(d.init, compressor);
}
if (compressor.option("evaluate") && compressor.option("reduce_vars")) {
var d = self.definition();
- if (!d.modified && d.init) {
+ if (d.fixed && d.init) {
if (d.should_replace === undefined) {
var init = d.init.evaluate(compressor);
if (init.length > 1) {
});
});
+ describe("Compressor", function() {
+ it("should be backward compatible with ast.transform(compressor)", function() {
+ var ast = Uglify.parse("function f(a){for(var i=0;i<a;i++)console.log(i)}");
+ ast.figure_out_scope();
+ ast = ast.transform(Uglify.Compressor());
+ assert.strictEqual(ast.print_to_string(), "function f(a){for(var i=0;i<a;i++)console.log(i)}");
+ });
+ })
+
});