Compare commits

..

4 Commits

Author SHA1 Message Date
Richard van Velzen
1a78bbcd23 v2.7.3 2016-08-17 20:34:27 +02:00
Richard van Velzen
8430123e9d Fix negate_iife transform to return a correct tree for nested IIFEs
Fix for #1256, partially reverts d854523783
2016-08-17 11:55:59 +02:00
Richard van Velzen
614db97cca v2.7.2 2016-08-17 08:51:23 +02:00
kzc
d854523783 Fix negate_iife regression #1254 2016-08-17 01:29:34 -04:00
4 changed files with 58 additions and 2 deletions

View File

@@ -831,6 +831,13 @@ merge(Compressor.prototype, {
}; };
function negate_iifes(statements, compressor) { function negate_iifes(statements, compressor) {
function is_iife_call(node) {
if (node instanceof AST_Call) {
return node.expression instanceof AST_Function || is_iife_call(node.expression);
}
return false;
}
statements.forEach(function(stat){ statements.forEach(function(stat){
if (stat instanceof AST_SimpleStatement) { if (stat instanceof AST_SimpleStatement) {
stat.body = (function transform(thing) { stat.body = (function transform(thing) {
@@ -838,7 +845,7 @@ merge(Compressor.prototype, {
if (node instanceof AST_New) { if (node instanceof AST_New) {
return node; return node;
} }
if (node instanceof AST_Call && node.expression instanceof AST_Function) { if (is_iife_call(node)) {
return make_node(AST_UnaryPrefix, node, { return make_node(AST_UnaryPrefix, node, {
operator: "!", operator: "!",
expression: node expression: node

View File

@@ -4,7 +4,7 @@
"homepage": "http://lisperator.net/uglifyjs", "homepage": "http://lisperator.net/uglifyjs",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)", "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"version": "2.7.1", "version": "2.7.3",
"engines": { "engines": {
"node": ">=0.8.0" "node": ">=0.8.0"
}, },

View File

@@ -130,3 +130,45 @@ negate_iife_issue_1073: {
}(7))(); }(7))();
} }
} }
issue_1254_negate_iife_false: {
options = {
negate_iife: false,
}
input: {
(function() {
return function() {
console.log('test')
};
})()();
}
expect_exact: '(function(){return function(){console.log("test")}})()();'
}
issue_1254_negate_iife_true: {
options = {
negate_iife: true,
}
input: {
(function() {
return function() {
console.log('test')
};
})()();
}
expect_exact: '!function(){return function(){console.log("test")}}()();'
}
issue_1254_negate_iife_nested: {
options = {
negate_iife: true,
}
input: {
(function() {
return function() {
console.log('test')
};
})()()()()();
}
expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
}

View File

@@ -75,3 +75,10 @@ call_with_unary_arguments: {
} }
expect_exact: "x();x(-1);x(-1,-2);x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);(-1)();(-1)(-2);" expect_exact: "x();x(-1);x(-1,-2);x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);(-1)();(-1)(-2);"
} }
new_with_unary_prefix: {
input: {
var bar = (+new Date()).toString(32);
}
expect_exact: 'var bar=(+new Date).toString(32);';
}