Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmony v2.8.2 #1521

Merged
merged 6 commits into from
Mar 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -624,7 +624,7 @@ function uglify(ast, options, mangle) {

// Compression
uAST.figure_out_scope();
uAST = uAST.transform(UglifyJS.Compressor(options));
uAST = UglifyJS.Compressor(options).compress(uAST);

// Mangling (optional)
if (mangle) {
@@ -868,7 +868,7 @@ toplevel.figure_out_scope()
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
27 changes: 16 additions & 11 deletions lib/compress.js
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ function Compressor(options, false_by_default) {
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,
@@ -188,8 +188,8 @@ merge(Compressor.prototype, {
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) {
@@ -206,7 +206,7 @@ merge(Compressor.prototype, {
this.walk(tw);

function reset_def(def) {
def.modified = false;
def.fixed = true;
def.references = [];
def.should_replace = undefined;
if (unsafe && def.init) {
@@ -1168,11 +1168,14 @@ merge(Compressor.prototype, {
def(AST_Statement, function(){
throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
});
// XXX: AST_Accessor and AST_Function both inherit from AST_Scope,
// which itself inherits from AST_Statement; however, they aren't
// really statements. This could bite in other places too. :-(
// Wish JS had multiple inheritance.
def(AST_Accessor, function(){
throw def;
});
def(AST_Function, function(){
// XXX: AST_Function inherits from AST_Scope, which itself
// inherits from AST_Statement; however, an AST_Function
// isn't really a statement. This could byte in other
// places too. :-( Wish JS had multiple inheritance.
throw def;
});
def(AST_Arrow, function() {
@@ -1210,7 +1213,9 @@ merge(Compressor.prototype, {
for (var i = 0, len = this.properties.length; i < len; i++) {
var prop = this.properties[i];
var key = prop.key;
if (key instanceof AST_Node) {
if (key instanceof AST_Symbol) {
key = key.name;
} else if (key instanceof AST_Node) {
key = ev(key, compressor);
}
if (typeof Object.prototype[key] === 'function') {
@@ -1290,7 +1295,7 @@ merge(Compressor.prototype, {
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);
@@ -3174,7 +3179,7 @@ merge(Compressor.prototype, {
}
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) {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"homepage": "http://lisperator.net/uglifyjs",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause",
"version": "2.8.0",
"version": "2.8.2",
"engines": {
"node": ">=0.8.0"
},
26 changes: 26 additions & 0 deletions test/compress/evaluate.js
Original file line number Diff line number Diff line change
@@ -431,6 +431,32 @@ unsafe_object_repeated: {
}
}

unsafe_object_accessor: {
options = {
evaluate: true,
reduce_vars: true,
unsafe: true,
}
input: {
function f() {
var a = {
get b() {},
set b() {}
};
return {a:a};
}
}
expect: {
function f() {
var a = {
get b() {},
set b() {}
};
return {a:a};
}
}
}

unsafe_function: {
options = {
evaluate : true,
9 changes: 9 additions & 0 deletions test/mocha/minify.js
Original file line number Diff line number Diff line change
@@ -182,4 +182,13 @@ describe("minify", function() {
});
});

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)}");
});
})

});