Skip to content

Commit

Permalink
Merge pull request #1582 from alexlamsl/harmony-v2.8.10
Browse files Browse the repository at this point in the history
Merging from master for 2.8.10
  • Loading branch information
alexlamsl authored Mar 9, 2017
2 parents 952e265 + 8f4b45f commit 5d5c793
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 74 deletions.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Bug report or feature request?
- `uglify-js` version (`uglifyjs -V`)
- JavaScript input - ideally as small as possible.
- The `uglifyjs` CLI command executed or `minify()` options used.
- An example of JavaScript output produced and/or the error or warning.

Note: the release version of `uglify-js` only supports ES5. Those wishing to minify ES6 should use the experimental [`harmony`](https://github.com/mishoo/UglifyJS2#harmony) branch.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
language: node_js
before_install: "npm install -g npm"
node_js:
- "0.12"
- "0.10"
- "0.12"
- "4"
- "6"
- "7"
env:
- UGLIFYJS_TEST_ALL=1
matrix:
fast_finish: true
sudo: false
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ to set `true`; it's effectively a shortcut for `foo=true`).
- `cascade` -- small optimization for sequences, transform `x, x` into `x`
and `x = something(), x` into `x = something()`

- `collapse_vars` -- default `false`. Collapse single-use `var` and `const`
definitions when possible.
- `collapse_vars` -- Collapse single-use `var` and `const` definitions
when possible.

- `reduce_vars` -- default `false`. Improve optimization on variables assigned
with and used as constant values.
- `reduce_vars` -- Improve optimization on variables assigned with and
used as constant values.

- `warnings` -- display warnings when dropping unreachable code or unused
declarations etc.
Expand Down
27 changes: 12 additions & 15 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,7 @@ merge(Compressor.prototype, {
}
if (node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn)) {
var def = node.definitions.filter(function(def){
if (def.value) def.value = def.value.transform(tt);
if (def.is_destructuring()) return true;
if (def.name.definition().id in in_use_ids) return true;
if (!drop_vars && def.name.definition().global) return true;
Expand Down Expand Up @@ -2006,18 +2007,16 @@ merge(Compressor.prototype, {
}
return node;
}
if (assign_as_unused) {
var n = node;
while (n instanceof AST_Assign
&& n.operator == "="
&& n.left instanceof AST_SymbolRef) {
var def = n.left.definition();
if (def.id in in_use_ids
|| !drop_vars && def.global
|| self.variables.get(def.name) !== def) break;
n = n.right;
if (assign_as_unused
&& node instanceof AST_Assign
&& node.operator == "="
&& node.left instanceof AST_SymbolRef) {
var def = node.left.definition();
if (!(def.id in in_use_ids)
&& (drop_vars || !def.global)
&& self.variables.get(def.name) === def) {
return maintain_this_binding(tt.parent(), node, node.right.transform(tt));
}
if (n !== node) return n;
}
if (node instanceof AST_For) {
descend(node, this);
Expand Down Expand Up @@ -2218,7 +2217,8 @@ merge(Compressor.prototype, {
def(AST_This, return_null);
def(AST_Call, function(compressor, first_in_statement){
if (!this.has_pure_annotation(compressor) && compressor.pure_funcs(this)) {
if (this.expression instanceof AST_Function) {
if (this.expression instanceof AST_Function
&& (!this.expression.name || !this.expression.name.definition().references.length)) {
var node = this.clone();
node.expression = node.expression.process_expression(false);
return node;
Expand Down Expand Up @@ -2742,9 +2742,6 @@ merge(Compressor.prototype, {
if (compressor.option("unused")
&& def.references.length == 1
&& compressor.find_parent(AST_Scope) === def.scope) {
if (!compressor.option("keep_fnames")) {
exp.name = null;
}
self.expression = exp;
}
}
Expand Down
36 changes: 12 additions & 24 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,16 +882,14 @@ function OutputStream(options) {
DEFPRINT(AST_Do, function(self, output){
output.print("do");
output.space();
self._do_print_body(output);
make_block(self.body, output);
output.space();
output.print("while");
output.space();
output.with_parens(function(){
self.condition.print(output);
});
if (output.option("beautify") && output.option("screw_ie8")) {
output.semicolon();
}
output.semicolon();
});
DEFPRINT(AST_While, function(self, output){
output.print("while");
Expand Down Expand Up @@ -1085,20 +1083,18 @@ function OutputStream(options) {

/* -----[ if ]----- */
function make_then(self, output) {
if (output.option("bracketize")) {
make_block(self.body, output);
return;
}
var b = self.body;
if (output.option("bracketize")
|| !output.option("screw_ie8") && b instanceof AST_Do)
return make_block(b, output);
// The squeezer replaces "block"-s that contain only a single
// statement with the statement itself; technically, the AST
// is correct, but this can create problems when we output an
// IF having an ELSE clause where the THEN clause ends in an
// IF *without* an ELSE block (then the outer ELSE would refer
// to the inner IF). This function checks for this case and
// adds the block brackets if needed.
if (!self.body)
return output.force_semicolon();
var b = self.body;
if (!b) return output.force_semicolon();
while (true) {
if (b instanceof AST_If) {
if (!b.alternative) {
Expand Down Expand Up @@ -1668,15 +1664,7 @@ function OutputStream(options) {

function force_statement(stat, output) {
if (output.option("bracketize")) {
if (!stat || stat instanceof AST_EmptyStatement)
output.print("{}");
else if (stat instanceof AST_BlockStatement)
stat.print(output);
else output.with_block(function(){
output.indent();
stat.print(output);
output.newline();
});
make_block(stat, output);
} else {
if (!stat || stat instanceof AST_EmptyStatement)
output.force_semicolon();
Expand Down Expand Up @@ -1725,11 +1713,11 @@ function OutputStream(options) {
};

function make_block(stmt, output) {
if (stmt instanceof AST_BlockStatement) {
if (!stmt || stmt instanceof AST_EmptyStatement)
output.print("{}");
else if (stmt instanceof AST_BlockStatement)
stmt.print(output);
return;
}
output.with_block(function(){
else output.with_block(function(){
output.indent();
stmt.print(output);
output.newline();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": "http://lisperator.net/uglifyjs",
"author": "Mihai Bazon <[email protected]> (http://lisperator.net/)",
"license": "BSD-2-Clause",
"version": "2.8.8",
"version": "2.8.10",
"engines": {
"node": ">=0.8.0"
},
Expand Down
61 changes: 61 additions & 0 deletions test/compress/drop-unused.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,3 +781,64 @@ issue_1539: {
}
}
}

vardef_value: {
options = {
keep_fnames: false,
reduce_vars: true,
unused: true,
}
input: {
function f() {
function g(){
return x();
}
var a = g();
return a(42);
}
}
expect: {
function f() {
var a = function(){
return x();
}();
return a(42);
}
}
}

assign_binding: {
options = {
cascade: true,
side_effects: true,
unused: true,
}
input: {
function f() {
var a;
a = f.g, a();
}
}
expect: {
function f() {
(0, f.g)();
}
}
}

assign_chain: {
options = {
unused: true,
}
input: {
function f() {
var a, b;
x = a = y = b = 42;
}
}
expect: {
function f() {
x = y = 42;
}
}
}
19 changes: 19 additions & 0 deletions test/compress/issue-1569.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
inner_reference: {
options = {
side_effects: true,
}
input: {
!function f(a) {
return a && f(a - 1) + a;
}(42);
!function g(a) {
return a;
}(42);
}
expect: {
!function f(a) {
return a && f(a - 1) + a;
}(42);
!void 0;
}
}
10 changes: 5 additions & 5 deletions test/compress/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ issue_186: {
else
bar();
}
expect_exact: 'var x=3;if(foo())do do alert(x);while(--x)while(x)else bar();'
expect_exact: 'var x=3;if(foo())do{do{alert(x)}while(--x)}while(x);else bar();'
}

issue_186_ie8: {
Expand All @@ -276,7 +276,7 @@ issue_186_ie8: {
else
bar();
}
expect_exact: 'var x=3;if(foo())do do alert(x);while(--x)while(x)else bar();'
expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else bar();'
}

issue_186_beautify: {
Expand All @@ -295,7 +295,7 @@ issue_186_beautify: {
else
bar();
}
expect_exact: 'var x = 3;\n\nif (foo()) do do alert(x); while (--x); while (x); else bar();'
expect_exact: 'var x = 3;\n\nif (foo()) do {\n do {\n alert(x);\n } while (--x);\n} while (x); else bar();'
}

issue_186_beautify_ie8: {
Expand All @@ -314,7 +314,7 @@ issue_186_beautify_ie8: {
else
bar();
}
expect_exact: 'var x = 3;\n\nif (foo()) do do alert(x); while (--x) while (x) else bar();'
expect_exact: 'var x = 3;\n\nif (foo()) {\n do {\n do {\n alert(x);\n } while (--x);\n } while (x);\n} else bar();'
}

issue_186_bracketize: {
Expand Down Expand Up @@ -394,5 +394,5 @@ issue_186_beautify_bracketize_ie8: {
else
bar();
}
expect_exact: 'var x = 3;\n\nif (foo()) {\n do {\n do {\n alert(x);\n } while (--x)\n } while (x)\n} else {\n bar();\n}'
expect_exact: 'var x = 3;\n\nif (foo()) {\n do {\n do {\n alert(x);\n } while (--x);\n } while (x);\n} else {\n bar();\n}'
}
22 changes: 22 additions & 0 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -1122,3 +1122,25 @@ defun_label: {
}();
}
}

double_reference: {
options = {
reduce_vars: true,
unused: true,
}
input: {
function f() {
var g = function g() {
g();
};
g();
}
}
expect: {
function f() {
(function g() {
g();
})();
}
}
}
24 changes: 0 additions & 24 deletions test/mocha/benchmark.js

This file was deleted.

Loading

0 comments on commit 5d5c793

Please sign in to comment.